1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#!/usr/bin/perl
#
# Testing the Math::VectorReal module
#
# location of my libraries (I normally set this via PERL5LIB)
#use lib '/home/anthony/lib/perl5'; # location of my libraries
use FindBin;
use lib "$FindBin::Bin/blib/lib";
use Math::VectorReal qw( :all );
#$Math::VectorReal::TRACE = 1; # Tracing of overload operators on/off
print "Stringify output testing (MatrixReal default)\n";
print 'O->stringify => ', O->stringify;
print "\n";
print "Changing default vector to string format\n";
print '$Math::VectorReal::FORMAT = "[ %g %g %g ]";', "\n";
$Math::VectorReal::FORMAT = "[ %g %g %g ]";
print "\n";
print "Axis functions, assign to constants\n";
print ' $o = O => ', $o=O, "\n";
print ' $x = X => ', $x=X, "\n";
print ' $y = Y => ', $y=Y, "\n";
print ' $z = Z => ', $z=Z, "\n";
print "\n";
print "String conversion operation testing\n";
print "Note: this include some automatic stringify concat ('.') operations\n";
print ' "$o" => ', "$o", "\n";
print '""$x =>', " $x", "\n";
print ' $y"" => ', "$y\n";
print ' $z => ', $z, "\n";
print 'vector(1,2,3) => ', vector(1,2,3), "\n";
print "\n";
print "Addition\n";
$a = $x + Y;
print '$a = $x + Y => ', $a, "\n";
$a += $y ;
print '$a += $y => ', $a, "\n";
print "\n";
print "Clone and Addition Tests\n";
$b = $y;
print '$b = $y => ', $b, "\n";
$b += Z;
print '$b += Z => ', $b, "\n";
print ' $y => ', $y, "\n";
print "\n";
print "Subtraction\n";
$b -= $z ;
print '$b -= $z => ', $b, "\n";
$b = $b - Z ;
print '$b = $b - Z => ', $b, "\n";
print "\n";
print "Scalar Multiply\n";
$a = $z * 2;
print '$a = $z * 2 => ', $a, "\n";
$a = 2 * Z;
print '$a = 2 * Z => ', $a, "\n";
$a *= 2.5;
print '$a *= 2.5 => ', $a, "\n";
print "\n";
print "Scalar Divide\n";
$a = $b / 2;
print '$a = $b / 2 => ', $a, "\n";
$a /= 3e14;
print '$a /= 3e14 => ', $a, "\n";
print "\n";
print "Unary - and more subtraction\n";
$b = -$b;
print '$b = -$b => ', $b, "\n";
$b -= Z;
print '$b -= Z => ', $b, "\n";
$b -= $z - -$y;
print '$b -= $z - -$y => ', $b, "\n";
$b = $o - $b;
print '$b = $o - $b => ', $b, "\n";
print "\n";
print "Cross Product\n";
$a = $b x X;
print '$a = $b x X => ', $a, "\n";
$a = $b x $y;
print '$a = $b x $y => ', $a, "\n";
$a = $b x $z;
print '$a = $b x $z => ', $a, "\n";
print "\n";
print "Dot Product / String Concatenation\n";
$a = Z . $b;
print '$a = Z . $b => ', $a, "\n";
$a = $b . -$y;
print '$a = $b . -$y => ', $a, "\n";
$s = $b . "!";
print '$s = $b . "!" => ', $s, "\n";
$s = "!" . $b;
print '$s = "!" . $b => ', $s, "\n";
$a .= $b;
print '$a .= $b => ', $a, "\n";
print "\n";
print "Special Functions (length, norm, plane)\n";
print '$b->length => ', $b->length, "\n";
print '$b->norm => ', $b->norm, "\n";
@a = plane(X,Y,Z);
print '@a = plane(X,Y,Z) => ', "\n @a\n";
print "check output from plane() function\n";
$a = X+Y+Z;
print 'normal => ', $a->norm, "\n";
print 'distance => ', ($a/3)->length, "\n";
print "\n";
print "Are defined constants still OK\n";
print '$o => ', $o, "\n";
print '$x => ', $x, "\n";
print '$y => ', $y, "\n";
print '$z => ', $z, "\n";
print "\n";
|