lib/LaTeX/TikZ/Scope.pm
lib/LaTeX/TikZ/Set.pm
lib/LaTeX/TikZ/Set/Arc.pm
+lib/LaTeX/TikZ/Set/Arrow.pm
lib/LaTeX/TikZ/Set/Circle.pm
lib/LaTeX/TikZ/Set/Line.pm
lib/LaTeX/TikZ/Set/Mutable.pm
require LaTeX::TikZ::Set::Rectangle; # rectangle
require LaTeX::TikZ::Set::Circle; # circle
require LaTeX::TikZ::Set::Arc; # arc
+ require LaTeX::TikZ::Set::Arrow; # arrow
require LaTeX::TikZ::Mod::Raw; # raw_mod
--- /dev/null
+package LaTeX::TikZ::Set::Arrow;
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+LaTeX::TikZ::Set::Arrow - A combined set object representing an arrow.
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '0.01';
+
+use Carp;
+
+use LaTeX::TikZ::Point;
+
+use LaTeX::TikZ::Set::Line;
+
+use Any::Moose 'Util::TypeConstraints' => [ 'find_type_constraint' ];
+
+my $ltp_tc = find_type_constraint('LaTeX::TikZ::Point::Autocoerce');
+
+use LaTeX::TikZ::Interface arrow => sub {
+ shift;
+
+ Carp::confess('Not enough arguments') unless @_ >= 2;
+
+ my $from = $ltp_tc->coerce(shift);
+
+ my $to;
+ if ($_[0] eq 'dir') {
+ my $dir = $ltp_tc->coerce($_[1]);
+ $to = LaTeX::TikZ::Point->new(
+ x => $from->x + $dir->x,
+ y => $from->y + $dir->y,
+ );
+ } else {
+ $to = $_[0];
+ }
+
+ LaTeX::TikZ::Set::Line->new(
+ from => $from,
+ to => $to,
+ )->mod('->');
+};
+
+=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::Arrow
use strict;
use warnings;
-use Test::More tests => 31;
+use Test::More tests => 32;
BEGIN {
use_ok( 'LaTeX::TikZ' );
use_ok( 'LaTeX::TikZ::Scope' );
use_ok( 'LaTeX::TikZ::Set' );
use_ok( 'LaTeX::TikZ::Set::Arc' );
+ use_ok( 'LaTeX::TikZ::Set::Arrow' );
use_ok( 'LaTeX::TikZ::Set::Circle' );
use_ok( 'LaTeX::TikZ::Set::Line' );
use_ok( 'LaTeX::TikZ::Set::Mutable' );
use strict;
use warnings;
-use Test::More tests => 5 + 16 + 12;
+use Test::More tests => 5 + 17 + 12;
use LaTeX::TikZ;
my @methods = qw/
raw
path seq
- point line polyline closed_polyline rectangle circle arc
+ point line polyline closed_polyline rectangle circle arc arrow
raw_mod
clip layer
width color fill
use strict;
use warnings;
-use Test::More tests => (14 + 2 * 5) + 2 * (11 + 2 * 3);
+use Test::More tests => (16 + 2 * 5) + 2 * (13 + 2 * 3);
use Math::Complex;
\draw (-1cm,2cm) -- (3cm,-4cm) ;
RES
+# Arrow
+
+my $ar = eval {
+ Tikz->arrow($o, 1);
+};
+is $@, '', 'creating an arrow from two points doesn\'t croak';
+
+check $ar, 'an arrow from two points', <<'RES';
+\draw [->] (0cm,0cm) -- (1cm,0cm) ;
+RES
+
+$ar = eval {
+ Tikz->arrow(2, dir => -i());
+};
+is $@, '', 'creating an arrow from a point and a direction doesn\'t croak';
+
+check $ar, 'an arrow from a point and a direction', <<'RES';
+\draw [->] (2cm,0cm) -- (2cm,-1cm) ;
+RES
+
# Polyline
my $w = Tikz->point(3, -4);