Permalink
Browse files

Change Nubs.Evaluate to Nubs.evaluate, make the default $direction Re…

…asonable, and have Reasonable mean Left on the first half of the Nubs's ParameterRange, and Right on the second half.
  • Loading branch information...
1 parent a25b0e7 commit 2ba7df8db1b902acaa6dba5a81b38268fa0166c0 SF committed Nov 1, 2009
Showing with 23 additions and 16 deletions.
  1. +11 −4 lib/Nurbs.pm
  2. +8 −8 t/03-nubs.t
  3. +4 −4 t/06-knots_poly.t
View
@@ -23,16 +23,23 @@ class Nubs
$.knot_vector.ParameterRange($.degree);
}
- multi method Evaluate($t, KnotBasisDirection $direction = Left)
+ # make this next one private?
+ multi method Direction($t, KnotBasisDirection $direction)
{
- my $n0 = $.knot_vector.N0_index($.degree, $t, $direction);
+ return $t < ([+] self.ParameterRange) / 2 ?? Left !! Right if ($direction == Reasonable);
+ return $direction;
+ }
+
+ multi method evaluate($t, KnotBasisDirection $direction = Reasonable)
+ {
+ my $n0 = $.knot_vector.N0_index($.degree, $t, self.Direction($t, $direction));
return [+] ($.knot_vector.N_local($n0, $.degree, $t)
>>*<< @.control_points[$n0 .. ($n0 + $.degree)]);
}
- multi method Evaluate($base_t, $actual_t, KnotBasisDirection $direction = Left)
+ multi method evaluate($base_t, $actual_t, KnotBasisDirection $direction = Reasonable)
{
- my $n0 = $.knot_vector.N0_index($.degree, $base_t, $direction);
+ my $n0 = $.knot_vector.N0_index($.degree, $base_t, self.Direction($base_t, $direction));
return [+] ($.knot_vector.N_local($n0, $.degree, $actual_t)
>>*<< @.control_points[$n0 .. ($n0 + $.degree)]);
}
View
@@ -21,11 +21,11 @@ isa_ok(eval($nubs1.perl), Nubs, ".perl works, tested with isa");
is_approx($nubs1.ParameterRange()[0], 0, "ParameterRange starts at 0");
is_approx($nubs1.ParameterRange()[1], 1, "ParameterRange ends at 1");
-is_approx_vector($nubs1.Evaluate(0.0), Vector.new(0, 0, 0, 0), "\$nubs1.Evaluate(0.0) is (0, 0, 0, 0)");
-is_approx_vector($nubs1.Evaluate(0.4), Vector.new(0.4, 4, 40, 400), "\$nubs1.Evaluate(0.4) is (0.4, 4, 40, 400)");
+is_approx_vector($nubs1.evaluate(0.0), Vector.new(0, 0, 0, 0), "\$nubs1.evaluate(0.0) is (0, 0, 0, 0)");
+is_approx_vector($nubs1.evaluate(0.4), Vector.new(0.4, 4, 40, 400), "\$nubs1.evaluate(0.4) is (0.4, 4, 40, 400)");
my $nubs2 = Nubs.new(1, $kv, (Vector.new(1, 10, 100, 1000), Vector.new(0, 0, 0, 0)));
-is_approx_vector($nubs2.Evaluate(0.0), Vector.new(1, 10, 100, 1000), "\$nubs2.Evaluate(0.0) is (1, 10, 100, 1000)");
+is_approx_vector($nubs2.evaluate(0.0), Vector.new(1, 10, 100, 1000), "\$nubs2.evaluate(0.0) is (1, 10, 100, 1000)");
# hardcore tests
@@ -41,18 +41,18 @@ my Nubs $nubs = Nubs.new(3, KnotVector.new(@knots), @control_points);
is_approx($nubs.ParameterRange()[0], -1, "ParameterRange starts at -1");
is_approx($nubs.ParameterRange()[1], 3, "ParameterRange ends at 3");
-is_approx_vector $nubs.Evaluate(-1), Vector.new(-1, -2, -3), "\$nubs.Evaluate(-1) is (-1, -2, -3)";
-is_approx_vector $nubs.Evaluate(3.0, Right), Vector.new(1, 2, -1), "\$nubs.Evaluate(3.0) is (1, 2, -1)";
+is_approx_vector $nubs.evaluate(-1), Vector.new(-1, -2, -3), "\$nubs.evaluate(-1) is (-1, -2, -3)";
+is_approx_vector $nubs.evaluate(3.0, Right), Vector.new(1, 2, -1), "\$nubs.evaluate(3.0) is (1, 2, -1)";
my $translation = Vector.new(3, 4.0, 5);
my Nubs $nubs3 = Nubs.new(3, KnotVector.new(@knots), @control_points >>+>> $translation);
for RangeOfSize(-1, 3, 10) -> $t
{
my $direction = $t < 3 ?? Left !! Right;
- is_approx_vector $nubs3.Evaluate($t, $direction),
- $nubs.Evaluate($t, $direction) + $translation,
- "\$nubs3.Evaluate($t) == \$nubs.Evaluate($t) + \$translation";
+ is_approx_vector $nubs3.evaluate($t, $direction),
+ $nubs.evaluate($t, $direction) + $translation,
+ "\$nubs3.evaluate($t) == \$nubs.evaluate($t) + \$translation";
}
done_testing;
View
@@ -35,18 +35,18 @@ my @control_points = (Vector.new(0, 0, 0),
my KnotVector $kv = KnotVector.new((-1, -1, -1, -1, 1, 2, 2, 3, 3, 3, 3));
my Nubs $nubs = Nubs.new(3, $kv, @control_points);
-my $poly = $nubs.Evaluate(1/2, Polynomial.new(0, 1));
+my $poly = $nubs.evaluate(1/2, Polynomial.new(0, 1));
for (-1, -1/2, 0, 1/2) -> $t
{
- is_approx($poly.evaluate($t), $nubs.Evaluate($t), "Polynomial sum and evaluation == Nubs evaluation");
+ is_approx($poly.evaluate($t), $nubs.evaluate($t), "Polynomial sum and evaluation == Nubs evaluation");
}
-$poly = $nubs.Evaluate(5/2, Polynomial.new(0, 1));
+$poly = $nubs.evaluate(5/2, Polynomial.new(0, 1));
for (2.1, 5/2, 2.74) -> $t
{
- is_approx($poly.evaluate($t), $nubs.Evaluate($t), "Polynomial sum and evaluation == Nubs evaluation");
+ is_approx($poly.evaluate($t), $nubs.evaluate($t), "Polynomial sum and evaluation == Nubs evaluation");
}

0 comments on commit 2ba7df8

Please sign in to comment.