| 1 | package SVG::Estimate::Ellipse; | ||||||||||||
| 2 | 3 | $SVG::Estimate::Ellipse::VERSION = '1.0116'; | |||||||||||
| 3 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use Math::Trig qw/pi/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 3 | extends 'SVG::Estimate::Shape'; | |||||||||||
| 7 | 3 | with 'SVG::Estimate::Role::MakePolygon'; | |||||||||||
| 8 | 3 | with 'SVG::Estimate::Role::ArgsWithUnits'; | |||||||||||
| 9 | |||||||||||||
| 10 | =head1 NAME | ||||||||||||
| 11 | |||||||||||||
| 12 | SVG::Estimate::Ellipse - Handles estimating ellipses. | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 VERSION | ||||||||||||
| 15 | |||||||||||||
| 16 | version 1.0116 | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||
| 19 | |||||||||||||
| 20 | my $ellipse = SVG::Estimate::Ellipse->new( | ||||||||||||
| 21 | transformer => $transform, | ||||||||||||
| 22 | start_point => [45,13], | ||||||||||||
| 23 | cx => 1, | ||||||||||||
| 24 | cy => 3, | ||||||||||||
| 25 | rx => 1, | ||||||||||||
| 26 | ry => 1.5, | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | |||||||||||||
| 29 | my $length = $ellipse->length; | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 INHERITANCE | ||||||||||||
| 32 | |||||||||||||
| 33 | This class extends L<SVG::Estimate::Shape>. | ||||||||||||
| 34 | |||||||||||||
| 35 | =head1 METHODS | ||||||||||||
| 36 | |||||||||||||
| 37 | =head2 new() | ||||||||||||
| 38 | |||||||||||||
| 39 | Constructor. | ||||||||||||
| 40 | |||||||||||||
| 41 | =over | ||||||||||||
| 42 | |||||||||||||
| 43 | =item cx | ||||||||||||
| 44 | |||||||||||||
| 45 | Float representing center x. | ||||||||||||
| 46 | |||||||||||||
| 47 | =item cy | ||||||||||||
| 48 | |||||||||||||
| 49 | Float representing center y. | ||||||||||||
| 50 | |||||||||||||
| 51 | =item rx | ||||||||||||
| 52 | |||||||||||||
| 53 | Float representing the x radius. | ||||||||||||
| 54 | |||||||||||||
| 55 | =item ry | ||||||||||||
| 56 | |||||||||||||
| 57 | Float representing the y radius. | ||||||||||||
| 58 | |||||||||||||
| 59 | =back | ||||||||||||
| 60 | |||||||||||||
| 61 | =cut | ||||||||||||
| 62 | |||||||||||||
| 63 | has cx => ( | ||||||||||||
| 64 | is => 'ro', | ||||||||||||
| 65 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 66 | 3 | ); | |||||||||||
| 67 | |||||||||||||
| 68 | has cy => ( | ||||||||||||
| 69 | is => 'ro', | ||||||||||||
| 70 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 71 | 3 | ); | |||||||||||
| 72 | |||||||||||||
| 73 | 3 | has rx => ( | |||||||||||
| 74 | is => 'ro', | ||||||||||||
| 75 | required => 1, | ||||||||||||
| 76 | ); | ||||||||||||
| 77 | |||||||||||||
| 78 | 3 | has ry => ( | |||||||||||
| 79 | is => 'ro', | ||||||||||||
| 80 | required => 1, | ||||||||||||
| 81 | ); | ||||||||||||
| 82 | |||||||||||||
| 83 | sub BUILDARGS { | ||||||||||||
| 84 | 2 | ▶ | my ($class, @args) = @_; | ||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 85 | ##Upgrade to hashref | ||||||||||||
| 86 | 2 | ▶ | my $args = @args % 2 ? $args[0] : { @args }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 2 | ▶ | $args->{cx} //= 0; | ||||||||||
|
Condition50%1/2
$args->{"cx"} //= 0
MC/DC0%0/1
$args->{"cx"} //= 0
$args->{"cx"}
Truth table50%1/2
A
A= $args->{"cx"}
| |||||||||||||
| 88 | 2 | ▶ | $args->{cy} //= 0; | ||||||||||
|
Condition50%1/2
$args->{"cy"} //= 0
MC/DC0%0/1
$args->{"cy"} //= 0
$args->{"cy"}
Truth table50%1/2
A
A= $args->{"cy"}
| |||||||||||||
| 89 | 2 | my $center = [ $args->{cx}, $args->{cy} ]; | |||||||||||
| 90 | 2 | ▶ | if ($args->{transformer}->has_transforms) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | ##Approximate the circle with a polygon | ||||||||||||
| 92 | 1 | my $poly = $class->make_polygon($args); | |||||||||||
| 93 | 1 | $args->{draw_start} = $poly->draw_start; | |||||||||||
| 94 | 1 | $args->{draw_end} = $poly->draw_end; | |||||||||||
| 95 | 1 | $args->{shape_length} = $poly->shape_length; | |||||||||||
| 96 | 1 | $args->{min_x} = $poly->min_x; | |||||||||||
| 97 | 1 | $args->{min_y} = $poly->min_y; | |||||||||||
| 98 | 1 | $args->{max_x} = $poly->max_x; | |||||||||||
| 99 | 1 | $args->{max_y} = $poly->max_y; | |||||||||||
| 100 | 1 | return $args; | |||||||||||
| 101 | } | ||||||||||||
| 102 | 1 | $args->{draw_start} = [$args->{cx}+$args->{rx}, $args->{cy}]; | |||||||||||
| 103 | 1 | $args->{draw_end} = $args->{draw_start}; | |||||||||||
| 104 | |||||||||||||
| 105 | ##https://www.mathsisfun.com/geometry/ellipse-perimeter.html, Series #2 | ||||||||||||
| 106 | 1 | my $h = ($args->{rx} - $args->{ry})**2 / ($args->{rx} + $args->{ry}) **2; | |||||||||||
| 107 | 1 | my $len = pi * ( $args->{rx} + $args->{ry} ) * ( 1 + $h/4 + ($h**2)/64 + ($h**3)/256 + ($h**4 * (25/16384))); | |||||||||||
| 108 | 1 | $args->{shape_length} = $len; | |||||||||||
| 109 | |||||||||||||
| 110 | 1 | $args->{min_x} = $args->{cx} - $args->{rx}; | |||||||||||
| 111 | 1 | $args->{min_y} = $args->{cy} - $args->{ry}; | |||||||||||
| 112 | 1 | $args->{max_x} = $args->{cx} + $args->{rx}; | |||||||||||
| 113 | 1 | $args->{max_y} = $args->{cy} + $args->{ry}; | |||||||||||
| 114 | 1 | return $args; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | sub args_with_units { | ||||||||||||
| 118 | 4 | ▶ | return qw/rx ry/; | ||||||||||
|
Subroutine
args_with_units: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | sub this_point { | ||||||||||||
| 122 | 13 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
this_point: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 123 | 13 | my $args = shift; | |||||||||||
| 124 | 13 | my $t = shift; | |||||||||||
| 125 | 13 | my $angle = $t * 2 * pi; | |||||||||||
| 126 | 13 | my $cosr = cos $angle; | |||||||||||
| 127 | 13 | my $sinr = sin $angle; | |||||||||||
| 128 | 13 | my $x = $cosr * $args->{rx} + $args->{cx}; | |||||||||||
| 129 | 13 | my $y = $sinr * $args->{ry} + $args->{cy}; | |||||||||||
| 130 | 13 | return [$x, $y]; | |||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | 3 | 1; | |||||||||||