| 1 | package Shape::RegularPolygon; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Math::Trig; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT = qw(); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 19 | 4 | my %params = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | my $self = {CenterX => 0, | |||||||||||||||||||||||||||
| 22 | CenterY => 0, | ||||||||||||||||||||||||||||
| 23 | Sides => 3, | ||||||||||||||||||||||||||||
| 24 | Radius => 50, | ||||||||||||||||||||||||||||
| 25 | Angle => 0.0, | ||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | foreach my $name (keys %params) { | |||||||||||||||||||||||||||
| 29 | 10 | ▶ | $self->{$name} = $params{$name} if exists $self->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | ($self->{Sides} >= 3) or die "Sides is too small."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 4 | bless($self, $class); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub center { | ||||||||||||||||||||||||||
|
Subroutine
center: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 5 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||
| 39 | return ($self->{CenterX}, $self->{CenterY}) | ||||||||||||||||||||||||||||
| 40 | 5 | ▶ | if !defined $x || !defined $y; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $x and defined $y
MC/DC50%1/2
defined $x and defined $y
defined $x
defined $y
Truth table66%2/3
A and B
A= defined $xB= defined $y
| |||||||||||||||||||||||||||||
| 41 | 2 | $self->{CenterX} = $x; | |||||||||||||||||||||||||||
| 42 | 2 | $self->{CenterY} = $y; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 5 | ▶ | sub sides { | ||||||||||||||||||||||||||
|
Subroutine
sides: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 5 | my ($self, $sides) = @_; | |||||||||||||||||||||||||||
| 46 | 5 | ▶ | return $self->{Sides} if not defined $sides; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | ($sides >= 3) or die "Sides is too smaill."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | $self->{Sides} = $sides; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 5 | ▶ | sub radius { | ||||||||||||||||||||||||||
|
Subroutine
radius: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 5 | my ($self, $radius) = @_; | |||||||||||||||||||||||||||
| 53 | 5 | ▶ | return $self->{Radius} if not defined $radius; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 2 | $self->{Radius} = $radius; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 5 | ▶ | sub angle { | ||||||||||||||||||||||||||
|
Subroutine
angle: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 5 | my ($self, $angle) = @_; | |||||||||||||||||||||||||||
| 58 | 5 | ▶ | return $self->{Angle} if not defined $angle; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 2 | $self->{Angle} = $angle; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub points { | ||||||||||||||||||||||||||
|
Subroutine
points: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | my @points; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | my $rad = - pi / 2 + $self->{Angle}; # -90 degree | |||||||||||||||||||||||||||
| 68 | 2 | ▶ | for (my $i = 0 ; $i < $self->{Sides} ; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | push @points, {x => cos($rad) * $self->{Radius} + $self->{CenterX}, | ||||||||||||||||||||||||||||
| 70 | 10 | y => sin($rad) * $self->{Radius} + $self->{CenterY}}; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 10 | $rad += pi * 2 / $self->{Sides}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | return @points; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||