6 use Test::More tests => 8 + 2 * 16;
10 my $tikz = Tikz->formatter(
15 my ($set, $desc, $exp) = @_;
17 local $Test::Builder::Level = $Test::Builder::Level + 1;
19 my ($head, $decl, $body) = eval {
20 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
22 is $@, '', "$desc: no error";
24 unless (ref $exp eq 'ARRAY') {
25 $exp = [ split /\n/, $exp ];
27 unshift @$exp, '\begin{tikzpicture}';
28 push @$exp, '\end{tikzpicture}';
30 is_deeply $body, $exp, $desc;
33 my $clip1 = Tikz->raw('clip1');
34 my $clip2 = Tikz->raw('clip2');
40 is $@, '', 'creating a clipping a raw path with ->clip doesn\'t croak';
42 check $foo, 'one clipped raw set', <<'RES';
51 ->mod(Tikz->clip(Tikz->raw('clip1')));
53 is $@, '', 'creating a clipping a raw path with ->mod doesn\'t croak';
55 check $bar, 'another clipped raw set', <<'RES';
62 my $seq = Tikz->seq($foo, $bar);
64 check $seq, 'mods folding with clips 1', <<'RES';
72 my $baz = Tikz->raw('baz')
75 check Tikz->seq($seq, $baz), 'mods folding with clips 2', <<'RES';
87 check Tikz->seq($baz, $seq), 'mods folding with clips 3', <<'RES';
99 my $seq2 = Tikz->seq($seq, $baz)
102 check $seq2, 'mods folding with clips 4', <<'RES';
114 $seq2 = Tikz->seq($seq, $baz)
117 check $seq2, 'mods folding with clips 5', <<'RES';
131 check $seq2, 'mods folding with clips 6', <<'RES';
143 $seq2->mod(Tikz->color('red'));
145 check $seq2, 'mods folding with clips 7', <<'RES';
146 \begin{scope} [color=red]
158 $seq->layer('bottom');
160 check $seq2, 'mods folding with clips and layers', <<'RES';
161 \begin{pgfonlayer}{top}
162 \begin{scope} [color=red]
166 \begin{pgfonlayer}{bottom}
167 \begin{scope} [color=red]
183 my $b = Tikz->point(4, 2);
184 my $c = Tikz->point(1, 3);
185 my $d = Tikz->point(2, 1);
187 my $r1 = Tikz->rectangle($a, $b);
188 my $r2 = Tikz->rectangle($c, $d);
196 is $@, '', 'two intersecting rectangle clips doesn\'t croak';
198 check $seq, 'two intersecting rectangle clips', <<'RES';
200 \clip (1cm,3cm) rectangle (2cm,1cm) ;
202 \clip (0cm,0cm) rectangle (4cm,2cm) ;
208 $r2 = Tikz->rectangle($a, $d); # $r2 is a subset of $r1
216 is $@, '', 'two overlapping rectangle clips 1 doesn\'t croak';
218 check $seq, 'two overlapping rectangle clips 1', <<'RES';
220 \clip (0cm,0cm) rectangle (2cm,1cm) ;
231 is $@, '', 'two overlapping rectangle clips 2 doesn\'t croak';
233 check $seq, 'two overlapping rectangle clips 2', <<'RES';
235 \clip (0cm,0cm) rectangle (4cm,2cm) ;
237 \clip (0cm,0cm) rectangle (2cm,1cm) ;
243 my $c1 = Tikz->circle($a, 2);
244 my $c2 = Tikz->circle($d, 3);
252 is $@, '', 'two intersecting circle clips doesn\'t croak';
254 check $seq, 'two intersecting circle clips', <<'RES';
256 \clip (2cm,1cm) circle (3cm) ;
258 \clip (0cm,0cm) circle (2cm) ;
264 $c2 = Tikz->circle($a, 1); # $c2 is a subset of $c1
272 is $@, '', 'two overlapping circle clips 1 doesn\'t croak';
274 check $seq, 'two overlapping circle clips 1', <<'RES';
276 \clip (0cm,0cm) circle (1cm) ;
287 is $@, '', 'two overlapping circle clips 2 doesn\'t croak';
289 check $seq, 'two overlapping circle clips 2', <<'RES';
291 \clip (0cm,0cm) circle (2cm) ;
293 \clip (0cm,0cm) circle (1cm) ;