Object3D/Point/Cast.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 75.0% 3 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 96.5% 56 / 58 CC 4 SCAR 5.2
CC
4
Cov
96%
cast
3.0
_cast_perspective
2.0
BEGIN
1.0
CRAP 1.7
« Object3D/Examples.pm ↑ Summary Object3D/Line.pm »
1 package Vector::Object3D::Point::Cast;
2  
3 =head1 NAME
4  
5 Vector::Object3D::Point::Cast - Three-dimensional point object casting into two-dimensional surface areas
6  
7 =head2 SYNOPSIS
8  
9 package Vector::Object3D::Point;
10  
11 use Moose;
12 with 'Vector::Object3D::Point::Cast';
13  
14 # Calling any method from this role requires providing an object of a base class
15 # and results in creation of a new instance of the same class:
16 my $point = Vector::Object3D::Point->new(coord => [-2, 3, 1]);
17  
18 # Project point onto a two-dimensional plane using an orthographic projection:
19 my $point2D = $point->cast(type => 'parallel');
20  
21 # Project point onto a two-dimensional plane using a perspective projection:
22 my $distance = 5;
23 my $point2D = $point->cast(type => 'perspective', distance => $distance);
24  
25 =head1 DESCRIPTION
26  
27 C<Vector::Object3D::Point::Cast> is a Moose role that is meant to be applied to C<Vector::Object3D::Point> class in order to provide it with additional methods of mapping three-dimensional points to a two-dimensional plane.
28  
29 =head1 METHODS
30  
31 =cut
32  
33 7 our $VERSION = '0.01';
34  
35 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 7 ▶use Vector::Object3D::Matrix;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 =head2 cast
45  
46 Project point onto a two-dimensional plane using an orthographic projection:
47  
48 my $point2D = $point->cast(type => 'parallel');
49  
50 Project point onto a two-dimensional plane using a perspective projection:
51  
52 my $distance = 5;
53 my $point2D = $point->cast(type => 'perspective', distance => $distance);
54  
55 =cut
56  
57 84 ▶sub cast {
Subroutine cast: called CC=3 SCAR=11.1
Pod documented
58 84 my ($self, %args) = @_;
59  
60 84 my $type = $args{type};
61  
62 84 ▶ if ($type eq 'parallel') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'parallel') { } 42 42 84
elsif ($type eq 'perspective') { } 42 0 42
63 42 my $point2D = $self->_cast_parallel(%args);
64 42 return $point2D;
65 }
66 elsif ($type eq 'perspective') {
67 42 my $point2D = $self->_cast_perspective(%args);
68 42 return $point2D;
69 }
70 else {
71 0 croak qq{Invalid projection type: "${type}"};
72 }
73 }
74  
75 42 ▶sub _cast_parallel {
Subroutine _cast_parallel: called CC=1 SCAR=0.0
76 42 my ($self, %args) = @_;
77  
78 42 my @xy = $self->get_xy;
79  
80 42 my $point2D = $self->new(coord => \@xy);
81 42 return $point2D;
82 }
83  
84 42 ▶sub _cast_perspective {
Subroutine _cast_perspective: called CC=2 SCAR=6.9
85 42 my ($self, %args) = @_;
86  
87 42 my $distance = $args{distance};
88  
89 42 my $x = $self->get_x;
90 42 my $y = $self->get_y;
91 42 ▶ my $z = $self->get_z || 0.00001; # avoid division by zero exception
Condition100%2/2
$self->get_z || 1e-05
l!l
1824
MC/DC100%1/1
$self->get_z || 1e-05
$self->get_z
Truth table100%2/2
A
A= $self->get_z
Aresult
11
00
92  
93 42 my $x_casted = $distance * $x / $z;
94 42 my $y_casted = $distance * $y / $z;
95  
96 42 my $point2D = $self->new(x => $x_casted, y => $y_casted);
97 42 return $point2D;
98 }
99  
100 =head1 BUGS
101  
102 There are no known bugs at the moment. Please report any bugs or feature requests.
103  
104 =head1 EXPORT
105  
106 C<Vector::Object3D::Point::Cast> exports nothing neither by default nor explicitly.
107  
108 =head1 SEE ALSO
109  
110 L<Vector::Object3D::Point>.
111  
112 =head1 AUTHOR
113  
114 Pawel Krol, E<lt>pawelkrol@cpan.orgE<gt>.
115  
116 =head1 VERSION
117  
118 Version 0.01 (2012-12-24)
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 Copyright (C) 2012 by Pawel Krol.
123  
124 This library is free open source software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
125  
126 PLEASE NOTE THAT IT COMES WITHOUT A WARRANTY OF ANY KIND!
127  
128 =cut
129  
130 7 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 7 1;
« Object3D/Examples.pm ↑ Summary Object3D/Line.pm »