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 => $_) };
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,
+ );
}
);