]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Arc.pm
Remove magic LaTeX::TikZ::Interface->import
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Arc.pm
index 3bbe83d83074b8d3fc8d7009b1f9da7a8b624927..9039cf02232b72144468a8352af48c7b619d12d0 100644 (file)
@@ -24,55 +24,59 @@ use LaTeX::TikZ::Point;
 use LaTeX::TikZ::Set::Circle;
 use LaTeX::TikZ::Set::Polyline;
 
+use LaTeX::TikZ::Interface;
+
 use LaTeX::TikZ::Tools;
 
 use Any::Moose 'Util::TypeConstraints' => [ 'find_type_constraint' ];
 
 my $ltp_tc = find_type_constraint('LaTeX::TikZ::Point::Autocoerce');
 
-use LaTeX::TikZ::Interface arc => sub {
- shift;
- Carp::confess('Tikz->arc($first_point, $second_point, $center)') if @_ < 3;
- my ($a, $b, $c) = @_;
+LaTeX::TikZ::Interface->register(
+ arc => sub {
+  shift;
+  Carp::confess('Tikz->arc($first_point, $second_point, $center)') if @_ < 3;
+  my ($a, $b, $c) = @_;
 
- for ($a, $b, $c) {
-  my $p = $ltp_tc->coerce($_);
-  $ltp_tc->assert_valid($p);
-  $_ = Math::Complex->make($p->x, $p->y);
- }
 for ($a, $b, $c) {
+   my $p = $ltp_tc->coerce($_);
+   $ltp_tc->assert_valid($p);
+   $_ = Math::Complex->make($p->x, $p->y);
 }
 
- my $r = abs($a - $c);
- Carp::confess("The two first points aren't on a circle of center the last")
 my $r = abs($a - $c);
 Carp::confess("The two first points aren't on a circle of center the last")
                              unless LaTeX::TikZ::Tools::numeq(abs($b - $c), $r);
 
- my $set = LaTeX::TikZ::Set::Circle->new(
-  center => $c,
-  radius => $r,
- );
-
- my $factor = 1/32;
-
- my $theta  = (($b - $c) / ($a - $c))->arg;
- my $points = int(abs($theta) / abs(Math::Trig::acos(0.95)));
- $theta    /= $points + 1;
- my $rho    = (1 / cos($theta)) / (1 - $factor);
-
- my $ua = ($a - $c) * (1 - $factor) + $c;
- my $ub = ($b - $c) * (1 - $factor) + $c;
-
- my @outside = map { $_ * $rho + $c } (
-  $a - $c,
-  (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points),
-  $b - $c,
- );
-
- $set->clip(
-  LaTeX::TikZ::Set::Polyline->new(
-   points => [ $ua, @outside, $ub ],
-   closed => 1,
-  ),
- );
-};
+  my $set = LaTeX::TikZ::Set::Circle->new(
+   center => $c,
+   radius => $r,
+  );
+
+  my $factor = 1/32;
+
+  my $theta  = (($b - $c) / ($a - $c))->arg;
+  my $points = int(abs($theta) / abs(Math::Trig::acos(0.95)));
+  $theta    /= $points + 1;
+  my $rho    = (1 / cos($theta)) / (1 - $factor);
+
+  my $ua = ($a - $c) * (1 - $factor) + $c;
+  my $ub = ($b - $c) * (1 - $factor) + $c;
+
+  my @outside = map { $_ * $rho + $c } (
+   $a - $c,
+   (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points),
+   $b - $c,
+  );
+
+  $set->clip(
+   LaTeX::TikZ::Set::Polyline->new(
+    points => [ $ua, @outside, $ub ],
+    closed => 1,
+   ),
+  );
+ },
+);
 
 =head1 AUTHOR