# bless constructed objects in proper class
#
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
#
http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# If you have a decent Bourne-type shell:
# STEP 2: Run the shell with this file as input.
# If you don't have such a shell, you may need to manually create
# the files as shown below.
# STEP 3: Run the 'patch' program with this file as input.
#
# These are the commands needed to create/delete files/directories:
#
touch 't/subclass.t'
chmod 0664 't/subclass.t'
#
# This command terminates the shell and need not be executed manually.
exit
#
#### End of Preamble ####
#### Patch data follows ####
diff -c 'Math-Vector-Real-0.10.orig/MANIFEST' 'Math-Vector-Real-0.10/MANIFEST'
Index: ./MANIFEST
*** ./MANIFEST Tue Jul 17 07:50:36 2012
--- ./MANIFEST Sat Sep 7 19:01:54 2013
***************
*** 3,8 ****
--- 3,9 ----
MANIFEST
README
t/Math-Vector-Real.t
+ t/subclass.t
t/pods.t
lib/Math/Vector/Real.pm
examples/dist_to_line.pl
diff -c 'Math-Vector-Real-0.10.orig/lib/Math/Vector/Real.pm' 'Math-Vector-Real-0.10/lib/Math/Vector/Real.pm'
Index: ./lib/Math/Vector/Real.pm
*** ./lib/Math/Vector/Real.pm Wed Jul 4 09:17:09 2012
--- ./lib/Math/Vector/Real.pm Sat Sep 7 18:56:52 2013
***************
*** 98,104 ****
croak "vector dimensions do not match";
}
! sub clone { bless [@{$_[0]}] }
sub set {
&_check_dim;
--- 98,104 ----
croak "vector dimensions do not match";
}
! sub clone { bless [@{$_[0]}], ref $_[0] }
sub set {
&_check_dim;
***************
*** 109,115 ****
sub add {
&_check_dim;
my ($v0, $v1) = @_;
! bless [map $v0->[$_] + $v1->[$_], 0..$#$v0]
}
sub add_me {
--- 109,115 ----
sub add {
&_check_dim;
my ($v0, $v1) = @_;
! bless [map $v0->[$_] + $v1->[$_], 0..$#$v0], ref $_[ $_[2] ? 1 : 0];
}
sub add_me {
***************
*** 119,130 ****
$v0;
}
! sub neg { bless [map -$_, @{$_[0]}] }
sub sub {
&_check_dim;
! my ($v0, $v1) = ($_[2] ? @_[1, 0] : @_);
! bless [map $v0->[$_] - $v1->[$_], 0..$#$v0]
}
sub sub_me {
--- 119,130 ----
$v0;
}
! sub neg { bless [map -$_, @{$_[0]}], ref $_[0] }
sub sub {
&_check_dim;
! my ($v0, $v1 ) = ($_[2] ? @_[1, 0] : @_);
! bless [map $v0->[$_] - $v1->[$_], 0..$#$v0], ref $_[ $_[2] ? 1 : 0];
}
sub sub_me {
***************
*** 143,150 ****
$acu;
}
else {
! my ($v, $s) = @_;
! bless [map $s * $_, @$v];
}
}
--- 143,150 ----
$acu;
}
else {
! my ($v, $s ) = @_;
! bless [map $s * $_, @$v], ref $_[0];
}
}
***************
*** 158,167 ****
sub div {
croak "can't use vector as dividend"
if ($_[2] or ref $_[1]);
! my ($v, $div) = @_;
$div == 0 and croak "illegal division by zero";
my $i = 1 / $div;
! bless [map $i * $_, @$v]
}
sub div_me {
--- 158,167 ----
sub div {
croak "can't use vector as dividend"
if ($_[2] or ref $_[1]);
! my ($v, $div ) = @_;
$div == 0 and croak "illegal division by zero";
my $i = 1 / $div;
! bless [map $i * $_, @$v], ref $_[0];
}
sub div_me {
***************
*** 193,199 ****
if ($dim == 3) {
return bless [$v0->[1] * $v1->[2] - $v0->[2] * $v1->[1],
$v0->[2] * $v1->[0] - $v0->[0] * $v1->[2],
! $v0->[0] * $v1->[1] - $v0->[1] * $v1->[0]]
}
if ($dim == 7) {
croak "cross product for dimension 7 not implemented yet, patches welcome!";
--- 193,200 ----
if ($dim == 3) {
return bless [$v0->[1] * $v1->[2] - $v0->[2] * $v1->[1],
$v0->[2] * $v1->[0] - $v0->[0] * $v1->[2],
! $v0->[0] * $v1->[1] - $v0->[1] * $v1->[0]],
! ref $_[0];
}
if ($dim == 7) {
croak "cross product for dimension 7 not implemented yet, patches welcome!";
***************
*** 287,293 ****
$f += $_ * $_ for @$self;
$f == 0 and croak "Illegal division by zero";
$f = 1/sqrt $f;
! bless [map $f * $_, @$self]
}
sub wrap {
--- 288,294 ----
$f += $_ * $_ for @$self;
$f == 0 and croak "Illegal division by zero";
$f = 1/sqrt $f;
! bless [map $f * $_, @$self], ref $self;
}
sub wrap {
***************
*** 296,302 ****
bless [map { my $s = $self->[$_];
my $c = $v->[$_];
! $c - $s * POSIX::floor($c/$s) } (0..$#$self)];
}
sub max_component {
--- 297,304 ----
bless [map { my $s = $self->[$_];
my $c = $v->[$_];
! $c - $s * POSIX::floor($c/$s) } (0..$#$self)],
! ref $self;
}
sub max_component {
diff -c /dev/null 'Math-Vector-Real-0.10/t/subclass.t'
Index: ./t/subclass.t
*** ./t/subclass.t Wed Dec 31 19:00:00 1969
--- ./t/subclass.t Sat Sep 7 19:01:18 2013
***************
*** 0 ****
--- 1,34 ----
+ #!/usr/bin/perl
+
+ use Test::More;
+
+ use Math::Vector::Real;
+
+ {
+ package SC;
+ use base 'Math::Vector::Real';
+ }
+
+ is( ref SC->new->clone, 'SC', 'clone' );
+
+ is( ref ( SC->new + V() ), 'SC', 'add' );
+
+ is( ref ( - SC->new ), 'SC', 'neg' );
+
+ is( ref ( SC->new * 3 ), 'SC', '* 3' );
+
+ is( ref ( 3 * SC->new ), 'SC', '3 *' );
+
+ is( ref ( SC->new / 3), 'SC', '/ 3 ' );
+
+ is( ref ( SC->new(1,1,1) x V(1,1,1) ), 'SC', ' x V' );
+
+ is( ref ( SC->new(1,1,1) x [1,1,1] ), 'SC', 'x []' );
+
+ is( ref ( [1,1,1] x SC->new(1,1,1) ), 'SC', '[] x' );
+
+ is( ref( SC->new(1,1,1)->versor ), 'SC', 'versor' );
+
+ is( ref( SC->new(1,1,1)->wrap( V(1,1,1) ) ), 'SC', 'wrap' );
+
+ done_testing;
#### End of Patch data ####
#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Sat Sep 7 21:14:52 2013
# Generated by : makepatch 2.05
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# p 'MANIFEST' 194 1378594914 0100644
# p 'lib/Math/Vector/Real.pm' 16956 1378594612 0100644
# c 't/subclass.t' 0 1378594878 0100664
#### End of ApplyPatch data ####
#### End of Patch kit [created: Sat Sep 7 21:14:52 2013] ####
#### Patch checksum: 251 6220 60227 ####
#### Checksum: 281 7268 17977 ####