X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet%2FArc.pm;h=ed32cfdb4c81b481be11e08dc929a42bb3a76cce;hb=4f696c03a66ef6b52ee7b9b3c74a71d5abc64f7e;hp=3ac58e01d6536ee27449076ea18f05de6422ac81;hpb=1918fdf5100058cd6a4281bc8b04ec8977841e5e;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Set/Arc.pm b/lib/LaTeX/TikZ/Set/Arc.pm index 3ac58e0..ed32cfd 100644 --- a/lib/LaTeX/TikZ/Set/Arc.pm +++ b/lib/LaTeX/TikZ/Set/Arc.pm @@ -9,11 +9,11 @@ LaTeX::TikZ::Set::Arc - A combined set object representing an arc. =head1 VERSION -Version 0.01 +Version 0.03 =cut -our $VERSION = '0.01'; +our $VERSION = '0.03'; use Carp (); use Math::Complex (); @@ -24,54 +24,63 @@ 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' ]; +use Mouse::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($_); - $_ = 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 $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 $factor = 1/32; + my $ua = ($a - $c) * (1 - $factor) + $c; + my $ub = ($b - $c) * (1 - $factor) + $c; - 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 @outside = map { $_ * $rho + $c } ( + $a - $c, + (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points), + $b - $c, + ); - my $ua = ($a - $c) * (1 - $factor) + $c; - my $ub = ($b - $c) * (1 - $factor) + $c; + $set->clip( + LaTeX::TikZ::Set::Polyline->new( + points => [ $ua, @outside, $ub ], + closed => 1, + ), + ); + }, +); - my @outside = map { $_ * $rho + $c } ( - $a - $c, - (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points), - $b - $c, - ); +=head1 SEE ALSO - $set->clip( - LaTeX::TikZ::Set::Polyline->new( - points => [ $ua, @outside, $ub ], - closed => 1, - ), - ); -}; +L, L. =head1 AUTHOR @@ -92,7 +101,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2010 Vincent Pit, all rights reserved. +Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.