Skip to content

Commit

Permalink
Muck around unsuccessfully with prefix +.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastOfTheCarelessMen committed Aug 30, 2009
1 parent ee9c26f commit 85bd658
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Vector.pm
Expand Up @@ -61,6 +61,11 @@ class Vector is also
}
}

# multi sub prefix:<+>(Vector $a)
# {
# $a;
# }

multi sub infix:<+>(Vector $a, Vector $b where { $a.Dim == $b.Dim })
{
Vector.new($a.coordinates »+« $b.coordinates);
Expand Down
6 changes: 6 additions & 0 deletions t/01-basics.t
Expand Up @@ -78,6 +78,7 @@ for @vectors -> $v
{
is_approx($v.Length ** 2, ⎡$v*$v ⎤, "v.Length squared equals ⎡v ⎤ squared");
is_approx($v.Length ** 2, $v$v, "v.Length squared equals v ⋅ v");
# is_approx(abs($v) ** 2, $v ⋅ $v, "abs(v) squared equals v ⋅ v");
}

for @vectors -> $v
Expand Down Expand Up @@ -175,6 +176,11 @@ dies_ok( { $v5 cross $v6 }, "You can't do 5D cross products");
dies_ok( { $a += $v2; }, "Catch if += violates the UnitVector constraint");
}

# test prefix plus
# isa_ok(+$v1, Vector, "Prefix + works on the Vector class");
dies_ok( { $v1.Num; }, "Make sure .Num does not work on 3D vector");

# test extensions
class VectorWithLength is Vector
{
has $.length;
Expand Down

0 comments on commit 85bd658

Please sign in to comment.