« Construction/Derivate/PointOnCircle.pm
↑ Summary
Construction/Derivate/IntersectionCircleLine.pm »
| 1 | package Math::Geometry::Construction::Role::PositionSelection; | ||||||||||||||||||||||||||||
| 2 | 14 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Math::Geometry::Construction::Vector; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use Math::Geometry::Construction::Types qw(Vector); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use MooseX::Params::Validate 0.13; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Math::Vector::Real; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | C<Math::Geometry::Construction::Role::PositionSelection> - select position from list | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 VERSION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Version 0.024 | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 14 | our $VERSION = '0.024'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ########################################################################### | ||||||||||||||||||||||||||||
| 26 | # # | ||||||||||||||||||||||||||||
| 27 | # Accessors # | ||||||||||||||||||||||||||||
| 28 | # # | ||||||||||||||||||||||||||||
| 29 | ########################################################################### | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 14 | requires 'id'; | |||||||||||||||||||||||||||
| 32 | 14 | requires 'positions'; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | ########################################################################### | ||||||||||||||||||||||||||||
| 35 | # # | ||||||||||||||||||||||||||||
| 36 | # Retrieve Data # | ||||||||||||||||||||||||||||
| 37 | # # | ||||||||||||||||||||||||||||
| 38 | ########################################################################### | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 109 | ▶ | sub indexed_position { | ||||||||||||||||||||||||||
|
Subroutine
indexed_position: called CC=5 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 109 | my ($self, $index) = @_; | |||||||||||||||||||||||||||
| 42 | 109 | my @positions = grep { defined($_) } $self->positions; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 109 | ▶ | croak "Undefined index in 'indexed_position' selector" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if(!defined($index)); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 109 | ▶ | if(!@positions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | warn sprintf("No positions to select from in %s.\n", $self->id); | |||||||||||||||||||||||||||
| 49 | 0 | return undef; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 109 | ▶ | if($index < 0 or $index >= @positions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index < 0 or $index >= @positions
MC/DC0%0/2
$index < 0 or $index >= @positions
$index < 0
$index >= @positions
Truth table33%1/3
A or B
A= $index < 0B= $index >= @positions
| |||||||||||||||||||||||||||||
| 52 | 0 | warn sprintf("Position index out of range in %s.\n", $self->id); | |||||||||||||||||||||||||||
| 53 | 0 | return undef; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 109 | return($positions[$index]); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 13 | ▶ | sub extreme_position { | ||||||||||||||||||||||||||
|
Subroutine
extreme_position: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 13 | my ($direction) = map { $_->value } pos_validated_list | |||||||||||||||||||||||||||
| 62 | (\@_, {isa => Vector, coerce => 1}); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 13 | my $d = abs($direction); | |||||||||||||||||||||||||||
| 65 | 13 | ▶ | return undef if($d == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 13 | my $norm = $direction / $d; | |||||||||||||||||||||||||||
| 68 | 13 | my @positions = grep { defined($_) } $self->positions; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 13 | ▶ | if(!@positions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | warn sprintf("No positions to select from in %s.\n", $self->id); | |||||||||||||||||||||||||||
| 72 | 0 | return undef; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 26 | return((map { $_->[0] } | |||||||||||||||||||||||||||
| 76 | 13 | sort { $b->[1] <=> $a->[1] } | |||||||||||||||||||||||||||
| 77 | 13 | map { [$_, $_ * $norm] } | |||||||||||||||||||||||||||
| 78 | @positions)[0]); | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | sub close_position { | ||||||||||||||||||||||||||
|
Subroutine
close_position: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 4 | my ($reference) = map { $_->value } pos_validated_list | |||||||||||||||||||||||||||
| 84 | (\@_, {isa => Vector, coerce => 1}); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | my @positions = grep { defined($_) } $self->positions; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | if(!@positions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | warn sprintf("No positions to select from in %s.\n", $self->id); | |||||||||||||||||||||||||||
| 90 | 0 | return undef; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 8 | return((map { $_->[0] } | |||||||||||||||||||||||||||
| 94 | 4 | sort { $a->[1] <=> $b->[1] } | |||||||||||||||||||||||||||
| 95 | 4 | map { [$_, abs($_ - $reference)] } | |||||||||||||||||||||||||||
| 96 | @positions)[0]); | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | ▶ | sub distant_position { | ||||||||||||||||||||||||||
|
Subroutine
distant_position: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 2 | my ($reference) = map { $_->value } pos_validated_list | |||||||||||||||||||||||||||
| 102 | (\@_, {isa => Vector, coerce => 1}); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | my @positions = grep { defined($_) } $self->positions; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2 | ▶ | if(!@positions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | warn sprintf("No positions to select from in %s.\n", $self->id); | |||||||||||||||||||||||||||
| 108 | 0 | return undef; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 4 | return((map { $_->[0] } | |||||||||||||||||||||||||||
| 112 | 2 | sort { $b->[1] <=> $a->[1] } | |||||||||||||||||||||||||||
| 113 | 2 | map { [$_, abs($_ - $reference)] } | |||||||||||||||||||||||||||
| 114 | @positions)[0]); | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | ########################################################################### | ||||||||||||||||||||||||||||
| 118 | # # | ||||||||||||||||||||||||||||
| 119 | # Change Data # | ||||||||||||||||||||||||||||
| 120 | # # | ||||||||||||||||||||||||||||
| 121 | ########################################################################### | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 14 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||