lib/LaTeX/TikZ/Set/Circle.pm
lib/LaTeX/TikZ/Set/Line.pm
lib/LaTeX/TikZ/Set/Mutable.pm
-lib/LaTeX/TikZ/Set/Op.pm
lib/LaTeX/TikZ/Set/Path.pm
lib/LaTeX/TikZ/Set/Point.pm
lib/LaTeX/TikZ/Set/Polyline.pm
lib/LaTeX/TikZ/Set/Raw.pm
lib/LaTeX/TikZ/Set/Rectangle.pm
lib/LaTeX/TikZ/Set/Sequence.pm
+lib/LaTeX/TikZ/Set/Union.pm
lib/LaTeX/TikZ/Tools.pm
samples/synopsis.pl
t/00-load.t
=head1 CONCEPTS
-Traditionally, in TikZ, there are two ways of grouping elements, or I<ops>, together :
+Traditionally, in TikZ, there are two ways of grouping paths together :
=over 4
=item *
-either as a I<sequence>, where each element is drawn in its own line :
+either as a I<sequence>, where each path is drawn in its own line :
\draw (0cm,0cm) -- (0cm,1cm) ;
\draw (0cm,0cm) -- (1cm,0cm) ;
=item *
-or as a I<path>, where elements are all drawn as one line :
+or as an I<union>, where paths are all drawn as one line :
\draw (0cm,0cm) -- (0cm,1cm) (0cm,0cm) -- (1cm,0cm) ;
This distinction is important because there are some primitives that only apply to paths but not to sequences, and vice versa.
-Figures are made of ops, path or sequence I<sets> assembled together in a tree.
+Figures are made of path or sequence I<sets> assembled together in a tree.
I<Modifiers> can be applied onto any set to alter the way in which it is generated.
The two TikZ concepts of I<clips> and I<layers> have been unified with the modifiers.
=head2 Containers
-=head3 C<< Tikz->path(@ops) >>
+=head3 C<< Tikz->union(@seq) >>
-Creates a L<LaTeX::TikZ::Set::Path> object out of the ops C<@ops>.
+Creates a L<LaTeX::TikZ::Set::Union> object out of the paths C<@kids>.
# A path made of two circles
Tikz->path(
=head3 C<< Tikz->seq(@kids) >>
-Creates a L<LaTeX::TikZ::Set::Sequence> object out of the sequences, paths or ops C<@kids>.
+Creates a L<LaTeX::TikZ::Set::Sequence> object out of the sequences or paths C<@kids>.
my $bag = Tikz->seq($sequence, $path, $circle, $raw, $point);
}
}
- my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence')
- ? $set->kids
- : $set->isa('LaTeX::TikZ::Set::Path')
- ? $set->ops
+ my @subsets = ($set->isa('LaTeX::TikZ::Set::Sequence')
+ || $set->isa('LaTeX::TikZ::Set::Union'))
+ ? $set->kids
: ();
$find_mods_rec->($_, $layers, $others) for @subsets;
require LaTeX::TikZ::Set::Raw; # raw
- require LaTeX::TikZ::Set::Path; # path
+ require LaTeX::TikZ::Set::Union; # union
require LaTeX::TikZ::Set::Sequence; # seq
require LaTeX::TikZ::Set::Point; # point
has clip => (
is => 'ro',
- does => 'LaTeX::TikZ::Set::Op',
+ does => 'LaTeX::TikZ::Set::Path',
required => 1,
);
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
=head1 ATTRIBUTES
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
=head1 ATTRIBUTES
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
+++ /dev/null
-package LaTeX::TikZ::Set::Op;
-
-use strict;
-use warnings;
-
-=head1 NAME
-
-LaTeX::TikZ::Set::Op - A role for set objects that can be part of a path.
-
-=head1 VERSION
-
-Version 0.02
-
-=cut
-
-our $VERSION = '0.02';
-
-=head1 DESCRIPTION
-
-Ops are the components of a path.
-They can be built together to form a path.
-Thus, they are all the elements against which we can call the C<path> method.
-
-=cut
-
-use Any::Moose 'Role';
-
-=head1 RELATIONSHIPS
-
-This role consumes the L<LaTeX::TikZ::Set> role, and as such implements the L</draw> method.
-
-=cut
-
-with 'LaTeX::TikZ::Set';
-
-=head1 METHODS
-
-This method is required by the interface :
-
-=over 4
-
-=item *
-
-C<path $formatter>
-
-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>.
-
-=back
-
-=cut
-
-requires qw<
- path
->;
-
-=head2 C<draw>
-
-=cut
-
-sub draw {
- my $set = shift;
-
- [ "\\draw " . $set->path(@_) . ' ;' ];
-}
-
-=head1 SEE ALSO
-
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>.
-
-=head1 AUTHOR
-
-Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
-
-You can contact me by mail or on C<irc.perl.org> (vincent).
-
-=head1 BUGS
-
-Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
-I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
-
-=head1 SUPPORT
-
-You can find documentation for this module with the perldoc command.
-
- perldoc LaTeX::TikZ
-
-=head1 COPYRIGHT & LICENSE
-
-Copyright 2010 Vincent Pit, all rights reserved.
-
-This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
-
-=cut
-
-1; # End of LaTeX::TikZ::Set::Op;
=head1 NAME
-LaTeX::TikZ::Set::Path - A set object representing a path.
+LaTeX::TikZ::Set::Path - A role for set objects that can be part of a path.
=head1 VERSION
our $VERSION = '0.02';
-use LaTeX::TikZ::Interface;
-use LaTeX::TikZ::Functor;
+=head1 DESCRIPTION
-use LaTeX::TikZ::Tools;
-
-use Any::Moose;
-
-=head1 RELATIONSHIPS
-
-This class consumes the L<LaTeX::TikZ::Set::Op> and L<LaTeX::TikZ::Set::Mutable> roles, and as such implements the L</path> and L</add> methods.
+Paths are all the elements against which we can call the C<path> method.
=cut
-with qw<
- LaTeX::TikZ::Set::Op
- LaTeX::TikZ::Set::Mutable
->;
+use Any::Moose 'Role';
-=head1 ATTRIBUTES
-
-=head2 C<ops>
+=head1 RELATIONSHIPS
-The L<LaTeX::TikZ::Set::Op> objects that from the path.
+This role consumes the L<LaTeX::TikZ::Set> role, and as such implements the L</draw> method.
=cut
-has '_ops' => (
- is => 'ro',
- isa => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Op]]',
- init_arg => 'ops',
- default => sub { [ ] },
-);
-
-sub ops { @{$_[0]->_ops} }
+with 'LaTeX::TikZ::Set';
=head1 METHODS
-=head2 C<add>
+This method is required by the interface :
-=cut
+=over 4
-my $ltso_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Set::Op');
+=item *
-sub add {
- my $set = shift;
+C<path $formatter>
- $ltso_tc->assert_valid($_) for @_;
+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>.
- push @{$set->_ops}, @_;
+=back
- $set;
-}
+=cut
+
+requires qw<
+ path
+>;
-=head2 C<path>
+=head2 C<draw>
=cut
-sub path {
+sub draw {
my $set = shift;
- join ' ', map $_->path(@_), $set->ops;
+ [ "\\draw " . $set->path(@_) . ' ;' ];
}
-LaTeX::TikZ::Interface->register(
- path => sub {
- shift;
-
- __PACKAGE__->new(ops => \@_);
- },
-);
-
-LaTeX::TikZ::Functor->default_rule(
- (__PACKAGE__) => sub {
- my ($functor, $set, @args) = @_;
- $set->new(ops => [ map $_->$functor(@args), $set->ops ])
- }
-);
-
-__PACKAGE__->meta->make_immutable;
-
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>, L<LaTeX::TikZ::Set::Mutable>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>.
=head1 AUTHOR
=cut
-1; # End of LaTeX::TikZ::Set::Path
+1; # End of LaTeX::TikZ::Set::Path;
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
=head1 ATTRIBUTES
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
subtype 'LaTeX::TikZ::Set::Polyline::Vertices'
=> as 'ArrayRef[LaTeX::TikZ::Set::Point]'
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
=head1 ATTRIBUTES
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
=head1 RELATIONSHIPS
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
=cut
-with 'LaTeX::TikZ::Set::Op';
+with 'LaTeX::TikZ::Set::Path';
=head1 ATTRIBUTES
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
=head1 AUTHOR
subtype 'LaTeX::TikZ::Set::Sequence::Elements'
=> as 'Object'
=> where {
- $_->does('LaTeX::TikZ::Set::Op')
+ $_->does('LaTeX::TikZ::Set::Path')
or $_->isa('LaTeX::TikZ::Set::Sequence')
};
=head2 C<kids>
-The L<LaTeX::TikZ::Set::Op> or L<LaTeX::TikZ::Set::Sequence> objects that from the sequence.
+The L<LaTeX::TikZ::Set::Path> or L<LaTeX::TikZ::Set::Sequence> objects that from the sequence.
=cut
=head1 SEE ALSO
-L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>, L<LaTeX::TikZ::Set::Mutable>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>, L<LaTeX::TikZ::Set::Mutable>.
=head1 AUTHOR
--- /dev/null
+package LaTeX::TikZ::Set::Union;
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+LaTeX::TikZ::Set::Union - A set object representing a path formed by the reunion of several subpaths.
+
+=head1 VERSION
+
+Version 0.02
+
+=cut
+
+our $VERSION = '0.02';
+
+use LaTeX::TikZ::Interface;
+use LaTeX::TikZ::Functor;
+
+use LaTeX::TikZ::Tools;
+
+use Any::Moose;
+
+=head1 RELATIONSHIPS
+
+This class consumes the L<LaTeX::TikZ::Set::Path> and L<LaTeX::TikZ::Set::Mutable> roles, and as such implements the L</path> and L</add> methods.
+
+=cut
+
+with qw<
+ LaTeX::TikZ::Set::Path
+ LaTeX::TikZ::Set::Mutable
+>;
+
+=head1 ATTRIBUTES
+
+=head2 C<kids>
+
+The L<LaTeX::TikZ::Set::Path> objects that form the path.
+
+=cut
+
+has '_kids' => (
+ is => 'ro',
+ isa => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]',
+ init_arg => 'kids',
+ default => sub { [ ] },
+);
+
+sub kids { @{$_[0]->_kids} }
+
+=head1 METHODS
+
+=head2 C<add>
+
+=cut
+
+my $ltsp_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Set::Path');
+
+sub add {
+ my $set = shift;
+
+ $ltsp_tc->assert_valid($_) for @_;
+
+ push @{$set->_kids}, @_;
+
+ $set;
+}
+
+=head2 C<path>
+
+=cut
+
+sub path {
+ my $set = shift;
+
+ join ' ', map $_->path(@_), $set->kids;
+}
+
+LaTeX::TikZ::Interface->register(
+ union => sub {
+ shift;
+
+ __PACKAGE__->new(kids => \@_);
+ },
+);
+
+LaTeX::TikZ::Functor->default_rule(
+ (__PACKAGE__) => sub {
+ my ($functor, $set, @args) = @_;
+ $set->new(kids => [ map $_->$functor(@args), $set->kids ])
+ }
+);
+
+__PACKAGE__->meta->make_immutable;
+
+=head1 SEE ALSO
+
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>, L<LaTeX::TikZ::Set::Mutable>.
+
+=head1 AUTHOR
+
+Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
+
+You can contact me by mail or on C<irc.perl.org> (vincent).
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
+I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc LaTeX::TikZ
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2010 Vincent Pit, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1; # End of LaTeX::TikZ::Set::Union
use_ok( 'LaTeX::TikZ::Set::Circle' );
use_ok( 'LaTeX::TikZ::Set::Line' );
use_ok( 'LaTeX::TikZ::Set::Mutable' );
- use_ok( 'LaTeX::TikZ::Set::Op' );
use_ok( 'LaTeX::TikZ::Set::Path' );
use_ok( 'LaTeX::TikZ::Set::Point' );
use_ok( 'LaTeX::TikZ::Set::Polyline' );
use_ok( 'LaTeX::TikZ::Set::Raw' );
use_ok( 'LaTeX::TikZ::Set::Rectangle' );
use_ok( 'LaTeX::TikZ::Set::Sequence' );
+ use_ok( 'LaTeX::TikZ::Set::Union' );
use_ok( 'LaTeX::TikZ::Tools' );
}
my @methods = qw<
formatter functor
raw
- path seq
+ union seq
point line polyline closed_polyline rectangle circle arc arrow
raw_mod
clip layer
}
eval {
- Tikz->path($foo, $seq2);
+ Tikz->union($foo, $seq2);
};
-like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Op]]'),
- 'creating a path that contains a sequence croaks';
+like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]'),
+ 'creating an union that contains a sequence croaks';
my $path = eval {
- Tikz->path($foo, $bar, $baz);
+ Tikz->union($foo, $bar, $baz);
};
-is $@, '', 'creating a path set doesn\'t croak';
+is $@, '', 'creating an union set doesn\'t croak';
check $path, 'one path set', <<'RES';
\draw foo bar baz ;
eval {
$path->add($seq2);
};
-like $@, failed_valid('LaTeX::TikZ::Set::Op'),
+like $@, failed_valid('LaTeX::TikZ::Set::Path'),
'adding a sequence to a path croaks';
'+LaTeX::TikZ::Mod' => sub { die "mod\n" },
'+LaTeX::TikZ::Set' => sub { die "set\n" },
'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) },
- 'LaTeX::TikZ::Set::Op' => sub { Tikz->raw('moo') },
+ 'LaTeX::TikZ::Set::Path' => sub { Tikz->raw('moo') },
);
};
is $@, '', 'creating a special functor with + and normal rules doesn\'t croak';
pod_coverage_ok( 'LaTeX::TikZ::Set::Circle' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Line' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Mutable' );
-pod_coverage_ok( 'LaTeX::TikZ::Set::Op' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Path' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Point' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Polyline' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Raw' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Rectangle' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Sequence' );
+pod_coverage_ok( 'LaTeX::TikZ::Set::Union' );
pod_coverage_ok( 'LaTeX::TikZ::Tools' );