]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Point.pm
First cut at the documentation
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Point.pm
index 85c35cf843f03fcdc05f48b94a13907499b9258b..b226fd41ec6b0efed1ce2bfdf54277fae09d7198 100644 (file)
@@ -15,29 +15,132 @@ Version 0.01
 
 our $VERSION = '0.01';
 
+use LaTeX::TikZ::Point;
+
+use LaTeX::TikZ::Interface;
+use LaTeX::TikZ::Functor;
+
 use Any::Moose;
+use Any::Moose 'Util::TypeConstraints';
+
+=head1 RELATIONSHIPS
+
+This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+
+=cut
 
 with 'LaTeX::TikZ::Set::Op';
 
+=head1 ATTRIBUTES
+
+=head2 C<point>
+
+The L<LaTeX::TikZ::Point> object representing the underlying geometrical point.
+
+=cut
+
 has 'point' => (
  is       => 'ro',
does     => 'LaTeX::TikZ::Point',
isa      => 'LaTeX::TikZ::Point::Autocoerce',
  required => 1,
+ coerce   => 1,
+ handles  => [ qw/x y/ ],
+);
+
+=head2 C<label>
+
+An optional label for the point.
+
+=cut
+
+has 'label' => (
+ is      => 'rw',
+ isa     => 'Maybe[Str]',
+ default => undef,
+);
+
+=head2 C<pos>
+
+The position of the label around the point.
+
+=cut
+
+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 => $_) };
+
+coerce 'LaTeX::TikZ::Point::Autocoerce'
+    => from 'LaTeX::TikZ::Set::Point'
+    => via { $_->point };
+
+=head1 METHODS
+
+=head2 C<path>
+
+=cut
+
 sub path {
  my ($set, $tikz) = @_;
 
  my $p = $set->point;
 
- '(' . $tikz->len($p->Re) . ',' . $tikz->len($p->Im) . ')';
+ 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;
 }
 
-use LaTeX::TikZ::API point => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ point => sub {
+  shift;
+
+  my $point;
+  if (@_ == 0) {
+   $point = 0;
+  } elsif (@_ % 2) {
+   $point = shift;
+  } else { # @_ even, @_ >= 2
+   $point = [ shift, shift ];
+  }
+
+  __PACKAGE__->new(point => $point, @_);
+ },
+);
 
- __PACKAGE__->new(point => $_[0]);
-};
+LaTeX::TikZ::Functor->default_rule(
+ (__PACKAGE__) => sub {
+  my ($functor, $set, @args) = @_;
+  $set->new(
+   point => $set->point,
+   label => $set->label,
+   pos   => $set->pos,
+  );
+ }
+);
 
 __PACKAGE__->meta->make_immutable;