From: Vincent Pit Date: Thu, 22 Jul 2010 19:39:14 +0000 (+0200) Subject: Complete origin support in the formatter object X-Git-Tag: v0.01~12 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=4a815ba07fc07f94629ca6364fae6204988e3dab;p=perl%2Fmodules%2FLaTeX-TikZ.git Complete origin support in the formatter object --- diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index 6f3d56e..899b4b0 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -56,17 +56,24 @@ has 'height' => ( has 'origin' => ( is => 'rw', - isa => 'Maybe[LaTeX::TikZ::Point::Autocoerce]', + isa => 'LaTeX::TikZ::Point::Autocoerce', coerce => 1, ); sub id { my $tikz = shift; + my $origin = $tikz->origin; + if (defined $origin) { + my ($x, $y) = map $origin->$_, qw/x y/; + $origin = "($x;$y)"; + } else { + $origin = "(0;0)"; + } + join $;, map { - my $val = $tikz->$_; - defined($val) ? "$val" : '(undef)'; - } qw/unit format scale width height origin/; + defined() ? "$_" : '(undef)'; + } map($tikz->$_, qw/unit format scale width height/), $origin; } my $find_mods = do { @@ -107,6 +114,8 @@ my $find_mods = do { }); }; +my $translate; + sub render { my $tikz = shift; @@ -114,6 +123,29 @@ sub render { kids => \@_, ); + unless ($translate) { + require LaTeX::TikZ::Functor; + $translate = LaTeX::TikZ::Functor->new( + rules => [ + 'LaTeX::TikZ::Set::Point' => sub { + my ($functor, $set, $v) = @_; + + $set->new( + point => [ + $set->x + $v->x, + $set->y + $v->y, + ], + label => $set->label, + pos => $set->pos, + ); + }, + ], + ); + } + + my $origin = $tikz->origin; + $seq = $seq->$translate($origin) if defined $origin; + my (@layers, @other_mods); $find_mods->($seq, \@layers, \@other_mods);