From: Vincent Pit Date: Wed, 21 Jul 2010 16:04:10 +0000 (+0200) Subject: Introduce LaTeX::TikZ::Set::Arrow X-Git-Tag: v0.01~22 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=92f8566cc72a8bfded5c55589030ddab5f215bd6;p=perl%2Fmodules%2FLaTeX-TikZ.git Introduce LaTeX::TikZ::Set::Arrow --- diff --git a/MANIFEST b/MANIFEST index 9d59a92..f5a6088 100644 --- a/MANIFEST +++ b/MANIFEST @@ -23,6 +23,7 @@ lib/LaTeX/TikZ/Point/Math/Complex.pm 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 diff --git a/lib/LaTeX/TikZ/Interface.pm b/lib/LaTeX/TikZ/Interface.pm index 0e902f5..20e26fd 100644 --- a/lib/LaTeX/TikZ/Interface.pm +++ b/lib/LaTeX/TikZ/Interface.pm @@ -67,6 +67,7 @@ sub load { 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 diff --git a/lib/LaTeX/TikZ/Set/Arrow.pm b/lib/LaTeX/TikZ/Set/Arrow.pm new file mode 100644 index 0000000..cc10eab --- /dev/null +++ b/lib/LaTeX/TikZ/Set/Arrow.pm @@ -0,0 +1,77 @@ +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<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +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 diff --git a/t/00-load.t b/t/00-load.t index 11f9eef..f5e995c 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 31; +use Test::More tests => 32; BEGIN { use_ok( 'LaTeX::TikZ' ); @@ -26,6 +26,7 @@ BEGIN { 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' ); diff --git a/t/01-api.t b/t/01-api.t index 106ebbe..4ccbc96 100644 --- a/t/01-api.t +++ b/t/01-api.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 5 + 16 + 12; +use Test::More tests => 5 + 17 + 12; use LaTeX::TikZ; @@ -31,7 +31,7 @@ is(prototype('Tikz'), '', 'main::Tikz is actually a constant'); 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 diff --git a/t/12-geo.t b/t/12-geo.t index afbc1e7..7ce5d64 100644 --- a/t/12-geo.t +++ b/t/12-geo.t @@ -3,7 +3,7 @@ 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; @@ -60,6 +60,26 @@ check $l, 'a line from two Tikz points', <<'RES'; \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);