return $path;
}
+=head2 C<begin>
+
+=cut
+
+sub begin {
+ my $set = shift;
+
+ my @kids = $set->kids;
+ return undef unless @kids;
+
+ $kids[0]->begin;
+}
+
+=head2 C<end>
+
+=cut
+
+sub end {
+ my $set = shift;
+
+ my @kids = $set->kids;
+ return undef unless @kids;
+
+ $kids[-1]->end;
+}
+
LaTeX::TikZ::Interface->register(
join => sub {
shift;
$set->center->path(@_) . ' circle (' . $tikz->len($set->radius) . ')';
}
+=head2 C<begin>
+
+=cut
+
+sub begin { $_[0]->center->begin }
+
+=head2 C<end>
+
+=cut
+
+sub end { $_[0]->center->end }
+
LaTeX::TikZ::Interface->register(
circle => sub {
shift;
$set->from->path(@_) . ' -- ' . $set->to->path(@_);
}
+=head2 C<begin>
+
+=cut
+
+sub begin { $_[0]->from->begin }
+
+=head2 C<end>
+
+=cut
+
+sub end { $_[0]->to->end }
+
LaTeX::TikZ::Interface->register(
line => sub {
shift;
=head1 METHODS
-This method is required by the interface :
+These methods are required by the interface :
=over 4
Returns the TikZ code that builds a path out of the current set object as a string formatted by the L<LaTeX::TikZ::Formatter> object C<$formatter>.
+=item *
+
+C<begin>
+
+Returns a L<LaTeX::TikZ::Point> object pointing to the beginning of the path, or C<undef> if this path has no beginning.
+
+=item *
+
+C<end>
+
+A L<LaTeX::TikZ::Point> object pointing to the end of the path, or C<undef> if this path has no end.
+
=back
=cut
requires qw<
path
+ begin
+ end
>;
=head2 C<draw>
$path;
}
+=head2 C<begin>
+
+=cut
+
+sub begin { $_[0]->point }
+
+=head2 C<end>
+
+=cut
+
+sub end { $_[0]->point }
+
LaTeX::TikZ::Interface->register(
point => sub {
shift;
($set->closed ? 'cycle' : ());
}
+=head2 C<begin>
+
+=cut
+
+sub begin {
+ my $set = shift;
+
+ my @points = $set->points;
+ return undef unless @points;
+
+ $points[0]->begin;
+}
+
+=head2 C<end>
+
+=cut
+
+sub end {
+ my $set = shift;
+
+ my @points = $set->points;
+ return undef unless @points;
+
+ $points[-1]->end;
+}
+
LaTeX::TikZ::Interface->register(
polyline => sub {
shift;
sub path { $_[0]->content }
+=head2 C<begin>
+
+=cut
+
+sub begin { undef }
+
+=head2 C<end>
+
+=cut
+
+sub end { undef }
+
LaTeX::TikZ::Interface->register(
raw => sub {
shift;
$set->from->path(@_) . ' rectangle ' . $set->to->path(@_);
}
+=head2 C<begin>
+
+=cut
+
+sub begin { $_[0]->from->begin }
+
+=head2 C<end>
+
+=cut
+
+sub end { $_[0]->to->end }
+
my $meta = __PACKAGE__->meta;
my $tc1 = $meta->find_attribute_by_name('from')->type_constraint;
my $tc2 = $meta->find_attribute_by_name('to')->type_constraint;
join ' ', map $_->path(@_), $set->kids;
}
+=head2 C<begin>
+
+=cut
+
+sub begin {
+ my $set = shift;
+
+ my @kids = $set->kids;
+ return undef unless @kids;
+
+ $kids[0]->begin;
+}
+
+=head2 C<end>
+
+=cut
+
+sub end {
+ my $set = shift;
+
+ my @kids = $set->kids;
+ return undef unless @kids;
+
+ $kids[-1]->end;
+}
+
LaTeX::TikZ::Interface->register(
union => sub {
shift;
use strict;
use warnings;
-use Test::More tests => 8 + 2 * 8;
+use Test::More tests => 8 + 2 * 8 + 2 * (1 + 2 * 3);
use Math::Complex;
check $p, 'a labeled positioned point', <<'RES';
\draw (2cm,-2cm) [fill] circle (0.4pt) node[scale=0.20,below right] {bar} ;
RES
+
+my $union = eval {
+ Tikz->union(
+ Tikz->point([ 0, -1 ]),
+ Tikz->raw("foo"),
+ Tikz->point(9)
+ );
+};
+is $@, '', 'creating a simple union path doesn\'t croak';
+is_point_ok $union->begin, 0, -1, 'beginning of a simple union path';
+is_point_ok $union->end, 9, 0, 'end of a simple union path';
+
+my $path = eval {
+ Tikz->union(
+ Tikz->join('--' => 1, 2, 3),
+ $union,
+ Tikz->chain(5 => '--' => [ 6, 1 ]),
+ );
+};
+is $@, '', 'creating a complex union path doesn\'t croak';
+is_point_ok $path->begin, 1, 0, 'beginning of a complex union path';
+is_point_ok $path->end, 6, 1, 'end of a complex union path';
use Any::Moose 'Exporter';
any_moose('Exporter')->setup_import_methods(
- as_is => [ qw<using check> ],
+ as_is => [ qw<using check is_point_ok> ],
);
my $tikz;
return $head, $decl, $body;
}
+sub is_point_ok {
+ my ($p, $x, $y, $desc) = @_;
+
+ my $ok = Test::More::isa_ok($p, 'LaTeX::TikZ::Point', "$desc isa point");
+ if ($ok) {
+ Test::More::cmp_ok($p->x, '==', $x, "$desc x coordinate is right");
+ Test::More::cmp_ok($p->y, '==', $y, "$desc y coordinate is right");
+ } else {
+ Test::More::fail("$desc placeholder $_") for 1, 2;
+ }
+}
+
1;