our $VERSION = '0.02';
use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Set::Raw;
use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
coerce => 1,
);
+=head2 C<cycle>
+
+A boolean that indicates whether the path is a cycle or not.
+
+=cut
+
+has 'cycle' => (
+ is => 'ro',
+ isa => 'Bool',
+ default => 0,
+);
+
=head1 METHODS
=head2 C<add>
my $prev = $kids[0];
my $path = $prev->path($tikz);
+ if ($set->cycle) {
+ push @kids, LaTeX::TikZ::Set::Raw->new(
+ content => 'cycle',
+ );
+ }
+
for my $i (1 .. $#kids) {
my $next = $kids[$i];
my $link = $set->$conn($i - 1, $prev, $next, $tikz);
$set->new(
kids => [ map $_->$functor(@args), $set->kids ],
connector => $set->connector,
+ cycle => $set->cycle,
);
}
);
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
+This class is a subclass of L<LaTeX::TikZ::Set::Chain>, and as such inherits its C<path> method.
=cut
-with 'LaTeX::TikZ::Set::Path';
+extends 'LaTeX::TikZ::Set::Chain';
subtype 'LaTeX::TikZ::Set::Polyline::Vertices'
=> as 'ArrayRef[LaTeX::TikZ::Set::Point]'
=head2 C<points>
-The list of the successive vertices of the path.
+The list of L<LaTeX::TikZ::Set::Point> objects (or scalars that coerce into such objects) that make the successive vertices of the path.
=cut
-has '_points' => (
+has '+_kids' => (
is => 'ro',
isa => 'LaTeX::TikZ::Set::Polyline::Vertices',
init_arg => 'points',
coerce => 1,
);
-sub points { @{$_[0]->_points} }
+sub points { @{$_[0]->_kids} }
-=head2 C<closed>
+around 'BUILDARGS' => sub {
+ my ($orig, $class, %args) = @_;
-A boolean that indicates whether the path is closed or not.
-
-=cut
-
-has 'closed' => (
- is => 'ro',
- isa => 'Bool',
- default => 0,
-);
-
-=head1 METHODS
-
-=head2 C<path>
-
-=cut
-
-sub path {
- my $set = shift;
-
- join ' -- ', map($_->path(@_), $set->points),
- ($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;
-}
+ $class->$orig(
+ %args,
+ connector => '--',
+ );
+};
LaTeX::TikZ::Interface->register(
polyline => sub {
closed_polyline => sub {
shift;
- __PACKAGE__->new(points => \@_, closed => 1);
- },
-);
-
-LaTeX::TikZ::Functor->default_rule(
- (__PACKAGE__) => sub {
- my ($functor, $set, @args) = @_;
- $set->new(
- points => [ map $_->$functor(@args), $set->points ],
- closed => $set->closed,
+ __PACKAGE__->new(
+ points => \@_,
+ cycle => 1
);
- }
+ },
);
__PACKAGE__->meta->make_immutable;
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Chain>.
=head1 AUTHOR