Vector::Object3D::Parameters - additional vector object parameters
package Vector::Object3D::Matrix; use Moose; with 'Vector::Object3D::Parameters'; # Define list of allowed parameter names with their default values and wrap it by an appropriate method call: sub build_default_parameter_values { return { precision => undef }; } # Get currently used parameter value: my $param = 'precision'; my $value = $object->get(parameter => $param); # Set new parameter value: my $param = 'precision'; my $value = 2; $object->set(parameter => $param, value => $value); # Get complete list of allowed parameter names: my @names = $object->get_parameter_names; # Get complete list of currently used parameter values: my %values = $object->get_parameter_values;
Vector::Object3D::Parameters is a Moose role that is meant to be applied to the family of Vector::Object3D:: classes in order to provide them with additional methods supporting maintenance of additional object properties. That might for example be a parameter named precision, as used by i.a. Vector::Object3D::Matrix and Vector::Object3D::Point classes. Understanding the importance of this parameter is illustrated in the following example:
Vector::Object3D::Parameters
Vector::Object3D::
precision
Vector::Object3D::Matrix
Vector::Object3D::Point
use Vector::Object3D::Matrix; # Create two almost identical matrix objects: my $matrix1 = Vector::Object3D::Matrix->new(rows => [[-2, 2], [2.018, 1]]); my $matrix2 = Vector::Object3D::Matrix->new(rows => [[-2, 2], [2.021, 1]]); # Set new precision values for both objects that will not be sufficient to consider them equal: $matrix1->set(parameter => 'precision', value => 3); $matrix2->set(parameter => 'precision', value => 3); # Comparing two almost identical matrix objects with too high precision yields false: my $are_the_same = $matrix1 == $matrix2; # false # Set new precision values for both objects that will be good enough to have a match: $matrix1->set(parameter => 'precision', value => 2); $matrix2->set(parameter => 'precision', value => 2); # Comparing two almost identical matrix objects with accurate precision yields true: my $are_the_same = $matrix1 == $matrix2; # true
This becomes especially important when comparing different transformation matrices, which might not appear to be equal due to divisions that produce results with theoretically infinite number of decimal places, just like in this example:
$ perl -e 'print 2/3' 0.666666666666667
Since calculations of input values that feed transformation matrix data during their construction involve producing such numbers, you should always consider setting up an accurate precision value if you plan to compare them later with each other.
The exactly same reasoning could be applied to Vector::Object3D::Point objects as well.
Set new parameter value:
my $param = 'precision'; my $value = 2; $object->set(parameter => $param, value => $value);
Get currently used parameter value:
my $param = 'precision'; my $value = $object->get(parameter => $param);
Get complete list of allowed parameter names:
my @names = $object->get_parameter_names;
Get complete list of currently used parameter values:
my %values = $object->get_parameter_values;
There are no known bugs at the moment. Please report any bugs or feature requests.
Vector::Object3D::Parameters exports nothing neither by default nor explicitly.
Vector::Object3D::Matrix, Vector::Object3D::Point.
Pawel Krol, <pawelkrol@cpan.org>.
Version 0.01 (2012-12-24)
Copyright (C) 2012 by Pawel Krol.
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.
PLEASE NOTE THAT IT COMES WITHOUT A WARRANTY OF ANY KIND!
To install Vector::Object3D, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Vector::Object3D
CPAN shell
perl -MCPAN -e shell install Vector::Object3D
For more information on module installation, please visit the detailed CPAN module installation guide.