From: Vincent Pit Date: Thu, 22 Jul 2010 19:08:04 +0000 (+0200) Subject: Add label and position support to Set::Point X-Git-Tag: v0.01~13 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c0c71aaf7da22da2c52cec635cb899a25599dad7;p=perl%2Fmodules%2FLaTeX-TikZ.git Add label and position support to Set::Point --- diff --git a/lib/LaTeX/TikZ/Set/Point.pm b/lib/LaTeX/TikZ/Set/Point.pm index 5bf292b..b45adaf 100644 --- a/lib/LaTeX/TikZ/Set/Point.pm +++ b/lib/LaTeX/TikZ/Set/Point.pm @@ -33,6 +33,28 @@ has 'point' => ( handles => [ qw/x y/ ], ); +has 'label' => ( + is => 'rw', + isa => 'Maybe[Str]', + default => undef, +); + +enum 'LaTeX::TikZ::Set::Point::Positions' => ( + 'below left', + 'below', + 'below right', + 'right', + 'above right', + 'above', + 'above left', + 'left', +); + +has 'pos' => ( + is => 'rw', + isa => 'Maybe[LaTeX::TikZ::Set::Point::Positions]', +); + coerce 'LaTeX::TikZ::Set::Point' => from 'Any' => via { __PACKAGE__->new(point => $_) }; @@ -46,24 +68,45 @@ sub path { my $p = $set->point; - '(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')'; + my $path = '(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')'; + + my $label = $set->label; + if (defined $label) { + my $pos = $set->pos; + $pos = 'above' unless defined $pos; + + my $size = sprintf '%0.1fpt', 2 * $tikz->scale / 5; + $path .= " [fill] circle ($size) " . $tikz->label($label, $pos); + } + + $path; } LaTeX::TikZ::Interface->register( point => sub { shift; - my $point = @_ == 0 ? 0 - : @_ == 1 ? $_[0] - : \@_; - __PACKAGE__->new(point => $point); + my $point; + if (@_ == 0) { + $point = 0; + } elsif (@_ % 2) { + $point = shift; + } else { # @_ even, @_ >= 2 + $point = [ shift, shift ]; + } + + __PACKAGE__->new(point => $point, @_); }, ); LaTeX::TikZ::Functor->default_rule( (__PACKAGE__) => sub { my ($functor, $set, @args) = @_; - $set->new(point => $set->point); + $set->new( + point => $set->point, + label => $set->label, + pos => $set->pos, + ); } );