NAME

Vector::Object3D::Line - Three-dimensional line object definitions

SYNOPSIS

use Vector::Object3D::Line;

# Create two endpoints of a line:
my $vertex1 = Vector::Object3D::Point->new(x => 3, y => -2, z => 1);
my $vertex2 = Vector::Object3D::Point->new(x => -1, y => 2, z => 3);

# Create an instance of a class:
my $line = Vector::Object3D::Line->new(vertex1 => $vertex1, vertex2 => $vertex2);
my $line = Vector::Object3D::Line->new(vertices => [$vertex1, $vertex2]);

# Create a new object as a copy of an existing object:
my $copy = $line->copy;

# Get first vertex point:
my $vertex1 = $line->get_vertex1;
# Get last vertex point:
my $vertex2 = $line->get_vertex2;

# Get both vertex points:
my @vertices = $line->get_vertices;

# Print out formatted line data:
$line->print(fh => $fh, precision => $precision);

# Compare two line objects:
my $are_the_same = $line1 == $line2;

DESCRIPTION

Vector::Object3D::Line provides an abstraction layer for describing line object in a three-dimensional space by composing it from two Vector::Object3D::Point objects (referred onwards as vertices).

METHODS

new

Create an instance of a Vector::Object3D::Line class:

my $vertex1 = Vector::Object3D::Point->new(x => 3, y => -2, z => 1);
my $vertex2 = Vector::Object3D::Point->new(x => -1, y => 2, z => 3);

my $line = Vector::Object3D::Line->new(vertex1 => $vertex1, vertex2 => $vertex2);
my $line = Vector::Object3D::Line->new(vertices => [$vertex1, $vertex2]);

There are two individual means of Vector::Object3D::Line object construction, provided a hash of two vertex components or a list of two point objects. When present, vertices constructor parameter takes precedence over vertex1 and vertex2 points in case both values are provided at the same time.

Vector::Object3D::Line requires provision of two endpoints in order to successfully construct an object instance, there is no exception from this rule.

copy

Create a new Vector::Object3D::Line object as a copy of an existing object:

my $copy = $line->copy;

get_vertex1

Get first vertex point:

my $vertex1 = $line->get_vertex1;

get_vertex2

Get last vertex point:

my $vertex2 = $line->get_vertex2;

get_vertices

Get both vertex points:

my @vertices = $line->get_vertices;

print

Print out text-formatted line data (which might be, for instance, useful for debugging purposes):

$line->print(fh => $fh, precision => $precision);

fh defaults to the standard output. precision is intended for internal use by string format specifier that outputs individual point coordinates as decimal floating points, and defaults to 2 (unless adjusted individually for each vertex).

compare (==)

Compare two line objects:

my $are_the_same = $line1 == $line2;

Overloaded comparison operator evaluates to true whenever two line objects are identical (both their endpoints are located at exactly same positions, note that vertex order matters as well).

negative compare (!=)

Compare two line objects:

my $are_not_the_same = $line1 != $line2;

Overloaded negative comparison operator evaluates to true whenever two line objects differ (any of their coordinates do not match).

BUGS

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

EXPORT

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

SEE ALSO

Vector::Object3D, 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!