| 1 | package SVG::Estimate::Circle; | ||||||||||||
| 2 | 3 | $SVG::Estimate::Circle::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::Circle - Handles estimating circles. | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 VERSION | ||||||||||||
| 15 | |||||||||||||
| 16 | version 1.0116 | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||
| 19 | |||||||||||||
| 20 | my $circle = SVG::Estimate::Circle->new( | ||||||||||||
| 21 | transformer => $transform, | ||||||||||||
| 22 | start_point => [45,13], | ||||||||||||
| 23 | cx => 1, | ||||||||||||
| 24 | cy => 3, | ||||||||||||
| 25 | r => 1, | ||||||||||||
| 26 | ); | ||||||||||||
| 27 | |||||||||||||
| 28 | my $length = $circle->length; | ||||||||||||
| 29 | |||||||||||||
| 30 | =head1 INHERITANCE | ||||||||||||
| 31 | |||||||||||||
| 32 | This class extends L<SVG::Estimate::Shape>. | ||||||||||||
| 33 | |||||||||||||
| 34 | =head1 METHODS | ||||||||||||
| 35 | |||||||||||||
| 36 | =head2 new() | ||||||||||||
| 37 | |||||||||||||
| 38 | Constructor. | ||||||||||||
| 39 | |||||||||||||
| 40 | =over | ||||||||||||
| 41 | |||||||||||||
| 42 | =item cx | ||||||||||||
| 43 | |||||||||||||
| 44 | Float representing center x. | ||||||||||||
| 45 | |||||||||||||
| 46 | =item cy | ||||||||||||
| 47 | |||||||||||||
| 48 | Float representing center y. | ||||||||||||
| 49 | |||||||||||||
| 50 | =item r | ||||||||||||
| 51 | |||||||||||||
| 52 | Float representing the radius. | ||||||||||||
| 53 | |||||||||||||
| 54 | =back | ||||||||||||
| 55 | |||||||||||||
| 56 | =cut | ||||||||||||
| 57 | |||||||||||||
| 58 | has cx => ( | ||||||||||||
| 59 | is => 'ro', | ||||||||||||
| 60 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 61 | 3 | ); | |||||||||||
| 62 | |||||||||||||
| 63 | has cy => ( | ||||||||||||
| 64 | is => 'ro', | ||||||||||||
| 65 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 66 | 3 | ); | |||||||||||
| 67 | |||||||||||||
| 68 | 3 | has r => ( | |||||||||||
| 69 | is => 'ro', | ||||||||||||
| 70 | required => 1, | ||||||||||||
| 71 | ); | ||||||||||||
| 72 | |||||||||||||
| 73 | sub args_with_units { | ||||||||||||
| 74 | 4 | ▶ | return qw/r/; | ||||||||||
|
Subroutine
args_with_units: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | sub BUILDARGS { | ||||||||||||
| 78 | 2 | ▶ | my ($class, @args) = @_; | ||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 79 | ##Upgrade to hashref | ||||||||||||
| 80 | 2 | ▶ | my $args = @args % 2 ? $args[0] : { @args }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 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"}
| |||||||||||||
| 82 | 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"}
| |||||||||||||
| 83 | 2 | my $center = [ $args->{cx}, $args->{cy} ]; | |||||||||||
| 84 | 2 | ▶ | if ($args->{transformer}->has_transforms) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | ##Approximate the circle with a polygon | ||||||||||||
| 86 | 1 | my $poly = $class->make_polygon($args); | |||||||||||
| 87 | 1 | $args->{draw_start} = $poly->draw_start; | |||||||||||
| 88 | 1 | $args->{draw_end} = $poly->draw_end; | |||||||||||
| 89 | 1 | $args->{shape_length} = $poly->shape_length; | |||||||||||
| 90 | 1 | $args->{min_x} = $poly->min_x; | |||||||||||
| 91 | 1 | $args->{min_y} = $poly->min_y; | |||||||||||
| 92 | 1 | $args->{max_x} = $poly->max_x; | |||||||||||
| 93 | 1 | $args->{max_y} = $poly->max_y; | |||||||||||
| 94 | 1 | return $args; | |||||||||||
| 95 | } | ||||||||||||
| 96 | 1 | $args->{draw_start} = [$args->{cx}+$args->{r}, $args->{cy}]; | |||||||||||
| 97 | 1 | $args->{draw_end} = $args->{draw_start}; | |||||||||||
| 98 | 1 | $args->{shape_length} = 2 * pi * $args->{r}; | |||||||||||
| 99 | 1 | $args->{min_x} = $args->{cx} - $args->{r}; | |||||||||||
| 100 | 1 | $args->{min_y} = $args->{cy} - $args->{r}; | |||||||||||
| 101 | 1 | $args->{max_x} = $args->{cx} + $args->{r}; | |||||||||||
| 102 | 1 | $args->{max_y} = $args->{cy} + $args->{r}; | |||||||||||
| 103 | 1 | return $args; | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | =head2 this_point ($args, $t) | ||||||||||||
| 107 | |||||||||||||
| 108 | This class method is used to calculate a point on a circle, given it's relative position (C<$t>, ranging | ||||||||||||
| 109 | from 0 to 1, inclusive), and the radius and center of the circle from a hashref of C<$args> (C<r> and C<cx> and <cy>). | ||||||||||||
| 110 | |||||||||||||
| 111 | =cut | ||||||||||||
| 112 | |||||||||||||
| 113 | sub this_point { | ||||||||||||
| 114 | 13 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
this_point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 115 | 13 | my $args = shift; | |||||||||||
| 116 | 13 | my $t = shift; | |||||||||||
| 117 | 13 | my $angle = $t * 2 * pi; | |||||||||||
| 118 | 13 | my $cosr = cos $angle; | |||||||||||
| 119 | 13 | my $sinr = sin $angle; | |||||||||||
| 120 | 13 | my $x = $cosr * $args->{r} + $args->{cx}; | |||||||||||
| 121 | 13 | my $y = $sinr * $args->{r} + $args->{cy}; | |||||||||||
| 122 | 13 | return [$x, $y]; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 3 | 1; | |||||||||||