line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Geometry::Construction::Vector; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4470
|
use 5.008008; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1708
|
use Math::Vector::Real; |
|
1
|
|
|
|
|
14364
|
|
|
1
|
|
|
|
|
85
|
|
6
|
0
|
|
|
|
|
|
use Math::Geometry::Construction::Types qw(MathVectorReal |
7
|
|
|
|
|
|
|
Point |
8
|
1
|
|
|
1
|
|
178
|
PointPoint); |
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Moose; |
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
C<Math::Geometry::Construction::Vector> - anything representing a vector |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.024 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.024'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
########################################################################### |
26
|
|
|
|
|
|
|
# # |
27
|
|
|
|
|
|
|
# Class Variables and Methods # |
28
|
|
|
|
|
|
|
# # |
29
|
|
|
|
|
|
|
########################################################################### |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
########################################################################### |
32
|
|
|
|
|
|
|
# # |
33
|
|
|
|
|
|
|
# Accessors # |
34
|
|
|
|
|
|
|
# # |
35
|
|
|
|
|
|
|
########################################################################### |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
with 'Math::Geometry::Construction::Role::AlternativeSources'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my %alternative_sources = |
40
|
|
|
|
|
|
|
(value_sources => {'vector' => {isa => MathVectorReal, |
41
|
|
|
|
|
|
|
coerce => 1}, |
42
|
|
|
|
|
|
|
'point' => {isa => Point}, |
43
|
|
|
|
|
|
|
'point_point' => {isa => PointPoint, |
44
|
|
|
|
|
|
|
coerce => 1}}); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
while(my ($name, $alternatives) = each %alternative_sources) { |
47
|
|
|
|
|
|
|
__PACKAGE__->alternatives |
48
|
|
|
|
|
|
|
(name => $name, |
49
|
|
|
|
|
|
|
alternatives => $alternatives, |
50
|
|
|
|
|
|
|
clear_buffer => 0); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub BUILD { |
54
|
|
|
|
|
|
|
my ($self, $args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->_check_value_sources; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
########################################################################### |
60
|
|
|
|
|
|
|
# # |
61
|
|
|
|
|
|
|
# Retrieve Data # |
62
|
|
|
|
|
|
|
# # |
63
|
|
|
|
|
|
|
########################################################################### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub value { |
66
|
|
|
|
|
|
|
my ($self) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $self->_vector if($self->_has_vector); |
69
|
|
|
|
|
|
|
return $self->_point->position if($self->_has_point); |
70
|
|
|
|
|
|
|
if($self->_has_point_point) { |
71
|
|
|
|
|
|
|
my $points = $self->_point_point; |
72
|
|
|
|
|
|
|
return $points->[1]->position - $points->[0]->position; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
croak('No way to determine value of Vector, '. |
75
|
|
|
|
|
|
|
'please send a bug report'); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
########################################################################### |
78
|
|
|
|
|
|
|
# # |
79
|
|
|
|
|
|
|
# Change Data # |
80
|
|
|
|
|
|
|
# # |
81
|
|
|
|
|
|
|
########################################################################### |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The typical user will not interact directly with this class. It |
93
|
|
|
|
|
|
|
unifies the access to different sources of a vector. This can be |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * a reference to an array of numbers |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
In this case, the L<value|/value> method will return a |
100
|
|
|
|
|
|
|
L<Math::Vector::Real|Math::Vector::Real> object consisting of the |
101
|
|
|
|
|
|
|
first two items of the array. It is only checked if the type is the |
102
|
|
|
|
|
|
|
C<Moose> type C<ArrayRef[Num]>. It is not checked if the array |
103
|
|
|
|
|
|
|
contains at least two items. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * a L<Math::Vector::Real> object |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The L<value|/value> method returns the object itself (not a clone). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * a L<Math::VectorReal> object |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The L<value|/value> method returns an |
112
|
|
|
|
|
|
|
L<Math::Vector::Real|Math::Vector::Real> object consisting of the |
113
|
|
|
|
|
|
|
C<x> and C<y> component of the vector. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * a |
116
|
|
|
|
|
|
|
L<Math::Geometry::Construction::Point|Math::Geometry::Construction::Point> |
117
|
|
|
|
|
|
|
object |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The L<value|/value> method returns the |
120
|
|
|
|
|
|
|
L<position|Math::Geometry::Construction::Point/position> attribute |
121
|
|
|
|
|
|
|
of the point. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * a |
124
|
|
|
|
|
|
|
L<Math::Geometry::Construction::Line|Math::Geometry::Construction::Line> |
125
|
|
|
|
|
|
|
object |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The L<value|/value> method returns the |
128
|
|
|
|
|
|
|
L<direction|Math::Geometry::Construction::Point/direction> of the |
129
|
|
|
|
|
|
|
line. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
C<Point> and C<Line> objects are evaluated at the time you call |
134
|
|
|
|
|
|
|
L<value|/value>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 INTERFACE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 Constructors |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 new |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$vector = Math::Geometry::Construction::Vector->new |
143
|
|
|
|
|
|
|
(provider => ...) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Creates a new C<Math::Geometry::Construction::Vector> object and |
146
|
|
|
|
|
|
|
initializes attributes. This is the default L<Moose|Moose> |
147
|
|
|
|
|
|
|
constructor. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 Public Attributes |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head3 provider |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This is the only attribute. It must be set at construction time and |
155
|
|
|
|
|
|
|
is readonly after that. The possible values are described in the |
156
|
|
|
|
|
|
|
L<DESCRIPTION section|/DESCRIPTION>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 Methods |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head3 value |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns a L<Math::Vector::Real|Math::Vector::Real> object as |
163
|
|
|
|
|
|
|
described in the L<DESCRIPTION section|/DESCRIPTION>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Lutz Gehlen, C<< <perl at lutzgehlen.de> >> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright 2013 Lutz Gehlen. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
176
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
177
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|