The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Vector::Object3D::Parameters - additional vector object parameters

SYNOPSIS

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;

DESCRIPTION

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:

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.

METHODS

set

Set new parameter value:

my $param = 'precision';
my $value = 2;
$object->set(parameter => $param, value => $value);

get

Get currently used parameter value:

my $param = 'precision';
my $value = $object->get(parameter => $param);

get_parameter_names

Get complete list of allowed parameter names:

my @names = $object->get_parameter_names;

get_parameter_values

Get complete list of currently used parameter values:

my %values = $object->get_parameter_values;

BUGS

There are no known bugs at the moment. Please report any bugs or feature requests.

EXPORT

Vector::Object3D::Parameters exports nothing neither by default nor explicitly.

SEE ALSO

Vector::Object3D::Matrix, Vector::Object3D::Point.

AUTHOR

Pawel Krol, <pawelkrol@cpan.org>.

VERSION

Version 0.01 (2012-12-24)

COPYRIGHT AND LICENSE

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!