]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/commitdiff
Introduce LaTeX::TikZ::Set::Arrow
authorVincent Pit <vince@profvince.com>
Wed, 21 Jul 2010 16:04:10 +0000 (18:04 +0200)
committerVincent Pit <vince@profvince.com>
Wed, 21 Jul 2010 16:04:10 +0000 (18:04 +0200)
MANIFEST
lib/LaTeX/TikZ/Interface.pm
lib/LaTeX/TikZ/Set/Arrow.pm [new file with mode: 0644]
t/00-load.t
t/01-api.t
t/12-geo.t

index 9d59a925084cac0510b890de1e2b73d876d5eff8..f5a6088da3fd60aeebb58632c363824ebc748ab7 100644 (file)
--- 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/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
 lib/LaTeX/TikZ/Set/Circle.pm
 lib/LaTeX/TikZ/Set/Line.pm
 lib/LaTeX/TikZ/Set/Mutable.pm
index 0e902f576e45efdb95cbda3bea1f312a249fda03..20e26fdc66fa627929bbb123fa42eb9e58b178c6 100644 (file)
@@ -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::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
 
 
  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 (file)
index 0000000..cc10eab
--- /dev/null
@@ -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<< <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
index 11f9eeffdca5cfe056c69ee58dcc93ff51df9b6e..f5e995c892b3d2355530e4035060650c8b1782a0 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Test::More tests => 31;
+use Test::More tests => 32;
 
 BEGIN {
  use_ok( 'LaTeX::TikZ' );
 
 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::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_ok( 'LaTeX::TikZ::Set::Circle' );
  use_ok( 'LaTeX::TikZ::Set::Line' );
  use_ok( 'LaTeX::TikZ::Set::Mutable' );
index 106ebbe649b573ea0ffe84c8e09bf5310e83b2c3..4ccbc96155b8da09b030e59708412d822da94521 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Test::More tests => 5 + 16 + 12;
+use Test::More tests => 5 + 17 + 12;
 
 use LaTeX::TikZ;
 
 
 use LaTeX::TikZ;
 
@@ -31,7 +31,7 @@ is(prototype('Tikz'), '', 'main::Tikz is actually a constant');
 my @methods = qw/
  raw
  path seq
 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
  raw_mod
  clip layer
  width color fill
index afbc1e703717d51dbf22f0d551f4889b97f638b9..7ce5d643a2414d94b3d43658c4c37614ea5c1c07 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
 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;
 
 
 use Math::Complex;
 
@@ -60,6 +60,26 @@ check $l, 'a line from two Tikz points', <<'RES';
 \draw (-1cm,2cm) -- (3cm,-4cm) ;
 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);
 # Polyline
 
 my $w = Tikz->point(3, -4);