Permalink
Browse files

Add KnotVector.ParameterRange and Nubs.ParameterRange, and KnotBasisD…

…ireciton.Reasonable.
  • Loading branch information...
SF
SF committed Nov 1, 2009
1 parent ec11216 commit a25b0e777be8db183bcf9f7b989c07c9f463bbb0
Showing with 19 additions and 1 deletion.
  1. +7 −1 lib/KnotVector.pm
  2. +5 −0 lib/Nurbs.pm
  3. +3 −0 t/02-knots.t
  4. +4 −0 t/03-nubs.t
View
@@ -1,7 +1,7 @@
use v6;
use BinarySearch;
-enum KnotBasisDirection <Left Right>;
+enum KnotBasisDirection <Left Right Reasonable>;
sub infix:<O/>($a, $b)
{
@@ -51,6 +51,7 @@ class KnotVector
{
when Left { UpperBound(@.knots, $u) - $p - 1; }
when Right { LowerBound(@.knots, $u) - $p - 1; }
+ when Reasonable { die "Must specify Left or Right for KnotBasisDirection"; }
}
}
@@ -80,4 +81,9 @@ class KnotVector
@N[($n0)..($n0 + $p)] = self.N_local($n0, $p, $u);
return @N;
}
+
+ multi method ParameterRange(Int $p)
+ {
+ ($.knots[$p], $.knots[*-$p]);
+ }
}
View
@@ -18,6 +18,11 @@ class Nubs
self.WHAT.perl ~ ".new($.degree, {$.knot_vector.perl}, {@.control_points.perl})";
}
+ multi method ParameterRange()
+ {
+ $.knot_vector.ParameterRange($.degree);
+ }
+
multi method Evaluate($t, KnotBasisDirection $direction = Left)
{
my $n0 = $.knot_vector.N0_index($.degree, $t, $direction);
View
@@ -69,6 +69,7 @@ is($kv.N0_index(1, 0.5), 0, "KnotVector.N0_index(0.5) == 0");
is($kv.N(1, 0.0), (1, 0), "KnotVector.N degree 1 at 0 == (1, 0)");
is($kv.N(1, 1.0, Right), (0, 1), "KnotVector.N degree 1 at 1 (Right) == (0, 1)");
+dies_ok( { $kv.N(1, 1.0, Reasonable) }, "Cannot pass reasonable to KnotVector.N");
is($kv.N(1, 0.5), (0..1).map({ N(@knots, $_, 1, 0.5) }), "KnotVector.N degree 1 matches test N");
is($kv.N(1, 0.5, Right), (0..1).map({ N(@knots, $_, 1, 0.5) }), "KnotVector.N degree 1 matches test N (Right)");
@@ -87,6 +88,8 @@ is($kv.N(2, 1.25, Right), (0..3).map({ N(@knots2, $_, 2, 1.25) }),
"KnotVector.N degree 2 matches test N for 1.25 from the Right");
is($kv.N(2, 2.0, Right), (0..3).map({ N(@knots2, $_, 2, 2.0, Right) }),
"KnotVector.N degree 2 matches test N for 2.0 from the Right");
+is_approx($kv.ParameterRange(2)[0], 0, "ParameterRange starts at 0");
+is_approx($kv.ParameterRange(2)[1], 2, "ParameterRange ends at 0");
done_testing;
View
@@ -18,6 +18,8 @@ is(eval($nubs1.perl).degree, $nubs1.degree, ".perl works for degree");
is(eval($nubs1.perl).knot_vector, $nubs1.knot_vector, ".perl works for knot vector");
is(eval($nubs1.perl).control_points, $nubs1.control_points, ".perl works for control points");
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)");
@@ -36,6 +38,8 @@ my @control_points = (Vector.new(-1, -2, -3),
Vector.new(1, 2, -1));
my @knots = (-1, -1, -1, -1, 1, 2, 2, 3, 3, 3, 3);
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)";

0 comments on commit a25b0e7

Please sign in to comment.