Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Put new KnotVector.N into play, remove pointless tests.

  • Loading branch information...
commit f28749864f820791552406597413a089973a7775 1 parent 7df4c9e
SF authored
Showing with 2 additions and 63 deletions.
  1. +2 −56 lib/KnotVector.pm
  2. +0 −7 t/02-knots.t
View
58 lib/KnotVector.pm
@@ -27,61 +27,7 @@ class KnotVector
{
self.WHAT.perl ~ ".new((" ~ @.knots.map({.perl}).join(', ') ~ "))";
}
-
- multi method N(Int $p where { $p == 0 }, $u, KnotBasisDirection $direction = Left)
- {
- my $impluse_function;
- given $direction
- {
- when Left { $impluse_function = { @.knots[$_] <= $u < @.knots[$_ + 1] ?? 1 !! 0; }; }
- when Right { $impluse_function = { @.knots[$_] < $u <= @.knots[$_ + 1] ?? 1 !! 0; }; }
- }
- return (0..(@.knots.end - 1)).map($impluse_function);
- }
-
- multi method N(Int $p, $u, KnotBasisDirection $direction = Left)
- {
- my @N_prev = self.N($p - 1, $u, $direction);
- my $end = @.knots.end;
-
- # return
- # (
- # (
- # ($u «-« @.knots[0..($end - $p - 1)])
- # »/«
- # (@.knots[$p..($end - 1)] »-« @.knots[0..($end - $p - 1)]).map({abs($_) < 1e-10 ?? 1.0 !! $_})
- # )
- # »*«
- # @N_prev[0..(@N_prev.end - 1)]
- # )
- # »+«
- # (
- # (
- # (@.knots[($p + 1)..$end] »-» $u)
- # »/«
- # (@.knots[($p + 1)..$end] »-« @.knots[1..($end - $p)]).map({abs($_) < 1e-10 ?? 1.0 !! $_})
- # )
- # »*«
- # @N_prev[1..(@N_prev.end)]
- # );
-
- my @left = (
- (
- ($u <<-<< @.knots[0..($end - $p - 1)])
- »/«
- (@.knots[$p..($end - 1)] »-« @.knots[0..($end - $p - 1)]).map({abs($_) < 1e-10 ?? 1.0 !! $_})
- )
- »*«
- @N_prev[0..(@N_prev.end - 1)]
- );
-
- my @right1a = @.knots[($p + 1)..$end] >>->> $u;
- my @right1b = @.knots[($p + 1)..$end] »-« @.knots[1..($end - $p)];
- my @right1 = gather for @right1a Z @right1b -> $a, $b { take $a O/ $b; };
- my @right = @right1 »*« @N_prev[1..(@N_prev.end)];
- return @left »+« @right;
- }
-
+
multi method N0_index($u, KnotBasisDirection $direction = Left)
{
given $direction
@@ -112,7 +58,7 @@ class KnotVector
return @N;
}
- multi method Nnew(Int $p, $u, KnotBasisDirection $direction = Left)
+ multi method N(Int $p, $u, KnotBasisDirection $direction = Left)
{
my $n0 = self.N0_index($u, $direction);
my @N = 0 xx (@.knots.elems - $p - 1);
View
7 t/02-knots.t
@@ -80,19 +80,12 @@ isa_ok($kv, KnotVector, "Variable is of type KnotVector");
is(~eval($kv.perl), ~$kv, ".perl works, tested with Str");
isa_ok(eval($kv.perl), KnotVector, ".perl works, tested with isa");
-is($kv.N(0, 0.5), (0..2).map({ N(@knots, $_, 0, 0.5) }), "KnotVector.N degree 0 matches test N");
is($kv.N(1, 0.5), (0..1).map({ N(@knots, $_, 1, 0.5) }), "KnotVector.N degree 1 matches test N");
my @knots2 = (0, 0, 0, 1, 2, 2, 2);
$kv = KnotVector.new(@knots2);
-is($kv.N(0, 0.25), (0..5).map({ N(@knots2, $_, 0, 0.25) }), "KnotVector.N degree 0 matches test N");
-is($kv.N(1, 0.25), (0..4).map({ N(@knots2, $_, 1, 0.25) }), "KnotVector.N degree 1 matches test N");
is($kv.N(2, 0.25), (0..3).map({ N(@knots2, $_, 2, 0.25) }), "KnotVector.N degree 2 matches test N");
-is($kv.N(0, 0.5), (0..5).map({ N(@knots2, $_, 0, 0.5) }), "KnotVector.N degree 0 matches test N");
-is($kv.N(1, 0.5), (0..4).map({ N(@knots2, $_, 1, 0.5) }), "KnotVector.N degree 1 matches test N");
is($kv.N(2, 0.5), (0..3).map({ N(@knots2, $_, 2, 0.5) }), "KnotVector.N degree 2 matches test N");
-is($kv.N(0, 1.25), (0..5).map({ N(@knots2, $_, 0, 1.25) }), "KnotVector.N degree 0 matches test N");
-is($kv.N(1, 1.25), (0..4).map({ N(@knots2, $_, 1, 1.25) }), "KnotVector.N degree 1 matches test N");
is($kv.N(2, 1.25), (0..3).map({ N(@knots2, $_, 2, 1.25) }), "KnotVector.N degree 2 matches test N");
Please sign in to comment.
Something went wrong with that request. Please try again.