Repository: hyrodium/BasicBSpline.jl
Pull request #39 (2020-10-15 15:30:15)

Fixed the bug and add tests
The PR #38 was incomplete.


Patch:
diff --git a/src/_Refinement.jl b/src/_Refinement.jl
index aff6e953..5739615b 100644
--- a/src/_Refinement.jl
+++ b/src/_Refinement.jl
@@ -222,7 +222,10 @@ function refinement(M::AbstractBSplineManifold; p₊::Union{Nothing,AbstractVect
         error("dimension does not match")
     end
 
-    Ps′ = [typeof(Ps[i])(degree(P) + p₊[i], knots(P) + p₊[i] * unique(k) + k₊[i]) for i in eachindex(Ps)]
+    Ps′ = [(P = Ps[i];
+    p = degree(P);
+    k = knots(P);
+    typeof(P)(p + p₊[i], k + p₊[i] * unique(k) + k₊[i])) for i in eachindex(Ps)]
 
     return refinement(M, Ps′)
 end


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index f3aaf17a..74fbb03f 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -224,13 +224,17 @@ using Random
 
         P1′ = BSplineSpace(2, Knots([-2, 0, 0, 1, 1, 2]))
         P2′ = BSplineSpace(1, Knots([-3, 1, 2, 1.45, 3, 4]))
+        p₊ = [1, 0]
+        k₊ = [Knots(), Knots(1.45)]
 
         @test P1 ⊑ P1′
         @test P2 ⊑ P2′
 
         M′ = refinement(M, [P1′, P2′])
+        M′′ = refinement(M, p₊=p₊, k₊=k₊)
         ts = [[rand(), 1 + 2 * rand()] for _ in 1:10]
         @test prod([M(t) ≈ M′(t) for t in ts])
+        @test prod([M(t) ≈ M′′(t) for t in ts])
     end
 
     @testset "FastBSplineManifold-2dim" begin
@@ -246,13 +250,17 @@ using Random
 
         P1′ = FastBSplineSpace(2, Knots([0, 0, 0, 1, 1, 1]))
         P2′ = FastBSplineSpace(1, Knots([1, 1, 2, 1.45, 3, 3]))
+        p₊ = [1, 0]
+        k₊ = [Knots(), Knots(1.45)]
 
         @test P1 ⊆ P1′
         @test P2 ⊆ P2′
 
         M′ = refinement(M, [P1′, P2′])
+        M′′ = refinement(M, p₊=p₊, k₊=k₊)
         ts = [[rand(), 1 + 2 * rand()] for _ in 1:10]
         @test prod([M(t) ≈ M′(t) for t in ts])
+        @test prod([M(t) ≈ M′′(t) for t in ts])
     end
 
     @testset "BSplineSurface" begin
@@ -268,13 +276,17 @@ using Random
 
         P1′ = FastBSplineSpace(2, Knots([0, 0, 0, 1, 1, 1]))
         P2′ = FastBSplineSpace(1, Knots([1, 1, 2, 1.45, 3, 3]))
+        p₊ = [1, 0]
+        k₊ = [Knots(), Knots(1.45)]
 
         @test P1 ⊆ P1′
         @test P2 ⊆ P2′
 
         M′ = refinement(M, [P1′, P2′])
+        M′′ = refinement(M, p₊=p₊, k₊=k₊)
         ts = [[rand(), 1 + 2 * rand()] for _ in 1:10]
         @test prod([M(t) ≈ M′(t) for t in ts])
+        @test prod([M(t) ≈ M′′(t) for t in ts])
     end
 
     @testset "Fitting-curve_R" begin
@@ -304,7 +316,7 @@ using Random
         Random.seed!(42)
 
         p1 = 2
-        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1+rand()])
+        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1 + rand()])
         P1 = FastBSplineSpace(p1, k1)
         n1 = dim(P1)
         a_org = [[i1, rand()] for i1 in 1:n1]
@@ -357,11 +369,11 @@ using Random
         Random.seed!(42)
 
         p1 = 2
-        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1+rand()])
+        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1 + rand()])
         P1 = FastBSplineSpace(p1, k1)
         n1 = dim(P1)
         p2 = 1
-        k2 = Knots(rand(4)) + Knots([0, 1]) + p2 * Knots([-rand(), 1+rand()])
+        k2 = Knots(rand(4)) + Knots([0, 1]) + p2 * Knots([-rand(), 1 + rand()])
         P2 = FastBSplineSpace(p2, k2)
         n2 = dim(P2)
         a_org = [[i1, i2, rand()] for i1 in 1:n1, i2 in 1:n2]
@@ -424,15 +436,15 @@ using Random
         Random.seed!(42)
 
         p1 = 2
-        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1+rand()])
+        k1 = Knots(rand(3)) + Knots([0, 1]) + p1 * Knots([-rand(), 1 + rand()])
         P1 = FastBSplineSpace(p1, k1)
         n1 = dim(P1)
         p2 = 1
-        k2 = Knots(rand(4)) + Knots([0, 1]) + p1 * Knots([-rand(), 1+rand()])
+        k2 = Knots(rand(4)) + Knots([0, 1]) + p1 * Knots([-rand(), 1 + rand()])
         P2 = FastBSplineSpace(p2, k2)
         n2 = dim(P2)
         p3 = 2
-        k3 = Knots(rand(5)) + Knots([0, 1]) + p1 * Knots([-rand(), 1+rand()])
+        k3 = Knots(rand(5)) + Knots([0, 1]) + p1 * Knots([-rand(), 1 + rand()])
         P3 = FastBSplineSpace(p3, k3)
         n3 = dim(P3)
         a_org = [[i1, i2, i3, rand()] for i1 in 1:n1, i2 in 1:n2, i3 in 1:n3]