Line3D - composition and subclassing



examples/perloop/point/eg/line3d.pl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Point3D;
use Line3D;

my $point1 = Point3D->new(x => 10, y => 20, z => 30);
my $point2 = Point3D->new(x => 15, y => 25, z => 35);

my $line = Line3D->new($point1, $point2);
print $line->isa('Line3D') ? 'ok' : 'false';
print " - Line3D\n";
print $line->isa('Line') ? 'ok' : 'false';
print " - Line\n";

print $line->length, "\n";

examples/perloop/point/lib/Line3D.pm
package Line3D;
use strict;
use warnings;

use base 'Line';

sub length {
    my ($self) = @_;

    my $x = $self->p1->get_x - $self->p2->get_x;
    my $y = $self->p1->get_y - $self->p2->get_y;
    my $z = $self->p1->get_z - $self->p2->get_z;

    return sqrt($x**2 + $y**2 + $z**2);
}


1;