Repository: hyrodium/BasicBSpline.jl
Pull request #121 (2021-12-28 07:47:30)

rename `knots` to `knotvector`
related: #119 


Patch:
diff --git a/README.md b/README.md
index 93fb5c50..7e1be740 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ save_png("2dim.png", M) # save image
 ### Refinement
 #### h-refinemnet
 ```julia
-k₊=[KnotVector(3.3,4.2),KnotVector(3.8,3.2,5.3)] # additional knots
+k₊=[KnotVector(3.3,4.2),KnotVector(3.8,3.2,5.3)] # additional knotvectors
 M′ = refinement(M,k₊=k₊) # refinement of B-spline manifold
 save_png("2dim_h-refinement.png", M′) # save image
 ```
@@ -130,7 +130,7 @@ save_png("fitting.png", M, unitlength=50, up=10, down=-10, left=-10, right=10)
 ![](docs/src/img/fitting_desmos.png)
 ![](docs/src/img/fitting.png)
 
-If the knots span is too coarse, the approximation will be coarse.
+If the knotvector span is too coarse, the approximation will be coarse.
 ```julia
 p1 = 2
 p2 = 2
diff --git a/docs/src/math.md b/docs/src/math.md
index 7c3c76d9..032be372 100644
--- a/docs/src/math.md
+++ b/docs/src/math.md
@@ -112,7 +112,7 @@ k = KnotVector([1,3,5,6,8,9])
 BSplineSpace{p}(k)
 ```
 
-A B-spline space is said to be **proper** if its degree and knots satisfies following property:
+A B-spline space is said to be **proper** if its degree and knotvector satisfies following property:
 ```math
 \begin{aligned}
 k_{i}&<k_{i+p+1} & (1 \le i \le l-p-1)
diff --git a/src/BasicBSpline.jl b/src/BasicBSpline.jl
index 65a62d94..965d869c 100644
--- a/src/BasicBSpline.jl
+++ b/src/BasicBSpline.jl
@@ -13,7 +13,7 @@ export bsplinesupport, domain, changebasis, expandspace
 export bsplinebasisall, intervalindex
 export refinement, bsplinespaces, controlpoints
 export isproper, properdim
-export degree, knots
+export degree, knotvector
 export 𝔫
 export AbstractBSplineManifold, AbstractBSplineSpace
 export fittingcontrolpoints
diff --git a/src/_BSplineBasis.jl b/src/_BSplineBasis.jl
index 63229871..7ea80be5 100644
--- a/src/_BSplineBasis.jl
+++ b/src/_BSplineBasis.jl
@@ -36,7 +36,7 @@ Right-sided limit version.
         push!(exs, :($(B_l(p+1-i)) = $(B_r(p+1-i))))
     end
     Expr(:block,
-        :(v = knots(P).vector),
+        :(v = knotvector(P).vector),
         :($k_l = $k_r),
         :($(B_l(p+1)) = $(A_r(p+1))),
         exs...,
@@ -78,7 +78,7 @@ Left-sided limit version.
         push!(exs, :($(B_l(p+1-i)) = $(B_r(p+1-i))))
     end
     Expr(:block,
-        :(v = knots(P).vector),
+        :(v = knotvector(P).vector),
         :($k_l = $k_r),
         :($(B_l(p+1)) = $(A_r(p+1))),
         exs...,
@@ -121,7 +121,7 @@ Modified version.
         push!(exs, :($(B_l(p+1-i)) = $(B_r(p+1-i))))
     end
     Expr(:block,
-        :(v = knots(P).vector),
+        :(v = knotvector(P).vector),
         :($k_l = $k_r),
         :($(B_l(p+1)) = $(A_r(p+1))),
         :($(Bs[end]) += $(T)(t == $(ks[end]) == v[end])),
@@ -142,7 +142,7 @@ bsplinebasisall
 end
 
 @inline function bsplinebasisall(P::BSplineSpace{1,T}, i::Integer, t::T) where T
-    k = knots(P)
+    k = knotvector(P)
     B1 = (k[i+2]-t)/(k[i+2]-k[i+1])
     B2 = (t-k[i+1])/(k[i+2]-k[i+1])
     return (B1, B2)
@@ -158,7 +158,7 @@ end
     exs = [:($(Bs[j+1]) = ($(K1s[j+1])*$(bs[j+1]) + $(K2s[j])*$(bs[j]))) for j in 1:p-1]
     Expr(:block,
         :($(Expr(:meta, :inline))),
-        :(k = knots(P)),
+        :(k = knotvector(P)),
         :($b = bsplinebasisall(_lower(P),i+1,t)),
         :($(Bs[1]) = $(K1s[1])*$(bs[1])),
         exs...,
diff --git a/src/_BSplineSpace.jl b/src/_BSplineSpace.jl
index 3aa27f59..5aa18f16 100644
--- a/src/_BSplineSpace.jl
+++ b/src/_BSplineSpace.jl
@@ -9,7 +9,7 @@ Construct B-spline space from given polynominal degree and knot vector.
 ```
 """
 struct BSplineSpace{p, T<:Real} <: AbstractBSplineSpace{p,T}
-    knots::KnotVector{T}
+    knotvector::KnotVector{T}
     global unsafe_bsplinespace(::Val{p}, k::KnotVector{T}) where {p,T} = new{p,T}(k)
 end
 function BSplineSpace{p}(k::KnotVector) where p
@@ -22,20 +22,20 @@ end
 Convert AbstractBSplineSpace to BSplineSpace
 """
 function BSplineSpace(P::AbstractBSplineSpace{p}) where p
-    return BSplineSpace{p}(knots(P))
+    return BSplineSpace{p}(knotvector(P))
 end
 
 @inline function degree(::BSplineSpace{p}) where p
     return p
 end
 
-@inline function knots(P::BSplineSpace)
-    return P.knots
+@inline function knotvector(P::BSplineSpace)
+    return P.knotvector
 end
 
 function domain(P::AbstractBSplineSpace)
     p = degree(P)
-    k = knots(P)
+    k = knotvector(P)
     return k[1+p]..k[end-p]
 end
 
@@ -47,7 +47,7 @@ Return dimention of a B-spline space.
 ```
 """
 function dim(bsplinespace::AbstractBSplineSpace{p}) where p
-    k = knots(bsplinespace)
+    k = knotvector(bsplinespace)
     return length(k) - p - 1
 end
 
@@ -59,8 +59,8 @@ Check inclusive relationship between B-spline spaces.
 ```
 """
 function Base.issubset(P::AbstractBSplineSpace{p}, P′::AbstractBSplineSpace{p′}) where {p, p′}
-    k = knots(P)
-    k′ = knots(P′)
+    k = knotvector(P)
+    k′ = knotvector(P′)
     p₊ = p′ - p
 
     return p₊ ≥ 0 && (k + p₊ * unique(k) ⊆ k′)
@@ -77,8 +77,8 @@ Check inclusive relationship between B-spline spaces.
 ```
 """
 function issqsubset(P::AbstractBSplineSpace{p}, P′::AbstractBSplineSpace{p′}) where {p, p′}
-    k = knots(P)
-    k′ = knots(P′)
+    k = knotvector(P)
+    k′ = knotvector(P′)
     p₊ = p′ - p
 
     if p₊ < 0
@@ -87,10 +87,10 @@ function issqsubset(P::AbstractBSplineSpace{p}, P′::AbstractBSplineSpace{p′}
         return false
     end
 
-    inner_knots = k[p+2:end-p-1]
-    inner_knots′ = k′[p′+2:end-p′-1]
+    inner_knotvector = k[p+2:end-p-1]
+    inner_knotvector′ = k′[p′+2:end-p′-1]
 
-    return inner_knots + p₊ * unique(inner_knots) ⊆ inner_knots′
+    return inner_knotvector + p₊ * unique(inner_knotvector) ⊆ inner_knotvector′
 end
 
 const ⊑ = issqsubset
@@ -101,7 +101,7 @@ const ⊑ = issqsubset
 ≃(P1::AbstractBSplineSpace, P2::AbstractBSplineSpace) = (P1 ⊑ P2) & (P2 ⊑ P1)
 
 function iszeros(P::AbstractBSplineSpace{p}) where p
-    k = knots(P)
+    k = knotvector(P)
     n = dim(P)
     return [k[i] == k[i+p+1] for i in 1:n]
 end
@@ -133,12 +133,12 @@ Return the support of ``i``-th B-spline basis function.
 ```
 """
 function bsplinesupport(P::AbstractBSplineSpace{p}, i::Integer) where p
-    k = knots(P)
+    k = knotvector(P)
     return k[i]..k[i+p+1]
 end
 
 function bsplinesupport(P::AbstractBSplineSpace{p}) where p
-    k = knots(P)
+    k = knotvector(P)
     return [k[i]..k[i+p+1] for i in 1:dim(P)]
 end
 
@@ -155,23 +155,23 @@ _lower
 # _lower(::Type{AbstractBSplineSpace{p,T}}) where {p,T} = AbstractBSplineSpace{p-1,T}
 # _lower(::Type{BSplineSpace{p}}) where p = BSplineSpace{p-1}
 # _lower(::Type{BSplineSpace{p,T}}) where {p,T} = BSplineSpace{p-1,T}
-_lower(P::BSplineSpace{p,T}) where {p,T} = BSplineSpace{p-1}(knots(P))
+_lower(P::BSplineSpace{p,T}) where {p,T} = BSplineSpace{p-1}(knotvector(P))
 
 """
 TODO: add docstring
 """
 function intervalindex(P::AbstractBSplineSpace{p},t::Real) where p
-    k = knots(P)
+    k = knotvector(P)
     l = length(k)
     v = view(k.vector,2+p:l-p-1)
     return searchsortedlast(v,t)+1
 end
 
 """
-Expand B-spline space with given additional degree and knots.
+Expand B-spline space with given additional degree and knotvector.
 """
 function expandspace(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector{T}=KnotVector{T}()) where {p,T}
-    k = knots(P)
+    k = knotvector(P)
     k0 = unique(k[1+p:end-p])
     p′ = p + p₊
     k′ = k + p₊*k0 + k₊
diff --git a/src/_ChangeBasis.jl b/src/_ChangeBasis.jl
index 4d75e9d3..01a61886 100644
--- a/src/_ChangeBasis.jl
+++ b/src/_ChangeBasis.jl
@@ -11,8 +11,8 @@ Assumption:
 * ``P ⊆ P′``
 """
 function _changebasis_R(P::BSplineSpace{p,T}, P′::BSplineSpace{p′,T})::Matrix{T} where {p,p′,T}
-    k = knots(P)
-    k′ = knots(P′)
+    k = knotvector(P)
+    k′ = knotvector(P′)
     p₊ = p′ - p
 
     if p == 0
@@ -101,7 +101,7 @@ function _changebasis_sim(P1::BSplineSpace{p1,T}, P2::BSplineSpace{p2,T}) where
     #     error("P2 ⋢ P1")
     # end
     n = dim(P1)
-    v = (knots(P1).vector)[p1+1:end-p1]
+    v = (knotvector(P1).vector)[p1+1:end-p1]
 
     if length(v) > p1
         A = Matrix{T}(I, n, n)
@@ -137,8 +137,8 @@ Assumption:
 """
 function _changebasis_I(P::BSplineSpace{p,T}, P′::BSplineSpace{p′,T})::Matrix{T} where {p, p′, T}
     I = domain(P)
-    k = knots(P)
-    k′ = knots(P′)
+    k = knotvector(P)
+    k′ = knotvector(P′)
     p₊ = p′ - p
 
     _P = BSplineSpace{p}(k[1+p:end-p] + p * KnotVector(k[1+p], k[end-p]))
diff --git a/src/_DerivativeBasis.jl b/src/_DerivativeBasis.jl
index 55599fc2..013a46e2 100644
--- a/src/_DerivativeBasis.jl
+++ b/src/_DerivativeBasis.jl
@@ -24,7 +24,7 @@
             push!(exs, :($(B_l(p+1-i)) = $(C_r(p+1-i))))
         end
         Expr(:block,
-            :(v = knots(dP).vector),
+            :(v = knotvector(dP).vector),
             :($k_l = $k_r),
             :($(B_l(p+1)) = $(A_r(p+1))),
             exs...,
@@ -59,7 +59,7 @@ end
             push!(exs, :($(B_l(p+1-i)) = $(C_r(p+1-i))))
         end
         Expr(:block,
-            :(v = knots(dP).vector),
+            :(v = knotvector(dP).vector),
             :($k_l = $k_r),
             :($(B_l(p+1)) = $(A_r(p+1))),
             exs...,
@@ -94,7 +94,7 @@ end
             push!(exs, :($(B_l(p+1-i)) = $(C_r(p+1-i))))
         end
         Expr(:block,
-            :(v = knots(dP).vector),
+            :(v = knotvector(dP).vector),
             :($k_l = $k_r),
             :($(B_l(p+1)) = $(A_r(p+1))),
             :($(Bs[end]) += $(T)(t == $(ks[end]) == v[end])),
@@ -160,7 +160,7 @@ end
     if r ≤ p
         Expr(:block,
             :($(Expr(:meta, :inline))),
-            :(k = knots(dP)),
+            :(k = knotvector(dP)),
             :($b = bsplinebasisall(_lower(dP),i+1,t)),
             :($(Bs[1]) = $(K1s[1])*$(bs[1])),
             exs...,
diff --git a/src/_DerivativeSpace.jl b/src/_DerivativeSpace.jl
index 33bf243e..b2ca0fe0 100644
--- a/src/_DerivativeSpace.jl
+++ b/src/_DerivativeSpace.jl
@@ -8,7 +8,7 @@ struct BSplineDerivativeSpace{r, T<:AbstractBSplineSpace}
 end
 
 bsplinespace(dP::BSplineDerivativeSpace) = dP.bsplinespace
-knots(dP::BSplineDerivativeSpace) = knots(bsplinespace(dP))
+knotvector(dP::BSplineDerivativeSpace) = knotvector(bsplinespace(dP))
 degree(dP::BSplineDerivativeSpace{r,<:AbstractBSplineSpace{p}}) where {r,p} = p - r
 dim(dP::BSplineDerivativeSpace{r,<:AbstractBSplineSpace{p}}) where {r,p} = dim(bsplinespace(dP))
 properdim(dP::BSplineDerivativeSpace{r,<:AbstractBSplineSpace{p}}) where {r,p} = properdim(bsplinespace(dP)) - r
@@ -17,7 +17,7 @@ domain(dP::BSplineDerivativeSpace) = domain(bsplinespace(dP))
 _lower(dP::BSplineDerivativeSpace{r}) where r = BSplineDerivativeSpace{r-1}(_lower(bsplinespace(dP)))
 
 function Base.issubset(dP::BSplineDerivativeSpace{r,<:AbstractBSplineSpace{p}}, P′::AbstractBSplineSpace) where {r,p}
-    k = knots(dP)
+    k = knotvector(dP)
     P = BSplineSpace{p-r}(k)
     return P ⊆ P′
 end
diff --git a/src/_Fitting.jl b/src/_Fitting.jl
index fc683506..0f9baa1f 100644
--- a/src/_Fitting.jl
+++ b/src/_Fitting.jl
@@ -10,7 +10,7 @@ Assumption:
 * ``1 ≤ n ≤ p-j+i+1``
 """
 function _b_b_int(P::BSplineSpace{p}, i, j, n, gl) where p
-    I = knots(P)[j+n-1]..knots(P)[j+n]
+    I = knotvector(P)[j+n-1]..knotvector(P)[j+n]
 
     f(t) = bsplinebasis(P, i, t) * bsplinebasis(P, j, t)
     return integrate(f, I, gl)
@@ -95,7 +95,7 @@ function innerproduct_I(P::BSplineSpace{p}) where p
 end
 
 function _f_b_int_R(func, i1, P1::BSplineSpace{p1}, gl1) where {p1}
-    k1 = knots(P1)
+    k1 = knotvector(P1)
     F(t1) = bsplinebasis(P1, i1, t1) * func(t1)
 
     f1,l1 = i1, i1+p1
@@ -108,7 +108,7 @@ function _f_b_int_R(func, i1, P1::BSplineSpace{p1}, gl1) where {p1}
 end
 
 function _f_b_int_I(func, i1, P1::BSplineSpace{p1}, gl1) where {p1}
-    k1 = knots(P1)
+    k1 = knotvector(P1)
     m1 = length(k1)
     F(t1) = bsplinebasis(P1, i1, t1) * func(t1)
 
@@ -123,7 +123,7 @@ end
 
 function _f_b_int_R(func, i1, i2, P::Tuple{<:AbstractBSplineSpace{p1}, <:AbstractBSplineSpace{p2}}, gl1, gl2) where {p1,p2}
     P1, P2 = P
-    k1, k2 = knots(P1), knots(P2)
+    k1, k2 = knotvector(P1), knotvector(P2)
     F(t1, t2) = bsplinebasis(P1, i1, t1) * bsplinebasis(P2, i2, t2) * func(t1, t2)
 
     f1, l1 = i1, i1+p1
@@ -146,7 +146,7 @@ end
 
 function _f_b_int_I(func, i1, i2, P::Tuple{<:AbstractBSplineSpace{p1}, <:AbstractBSplineSpace{p2}}, gl1, gl2) where {p1,p2}
     P1, P2 = P
-    k1, k2 = knots(P1), knots(P2)
+    k1, k2 = knotvector(P1), knotvector(P2)
     m1, m2 = length(k1), length(k2)
     F(t1, t2) = bsplinebasis(P1, i1, t1) * bsplinebasis(P2, i2, t2) * func(t1, t2)
 
@@ -170,7 +170,7 @@ end
 
 function _f_b_int_R(func, i1, i2, i3, P::Tuple{<:AbstractBSplineSpace{p1}, <:AbstractBSplineSpace{p2}, <:AbstractBSplineSpace{p3}}, gl1, gl2, gl3) where {p1,p2,p3}
     P1, P2, P3 = P
-    k1, k2, k3 = knots(P1), knots(P2), knots(P3)
+    k1, k2, k3 = knotvector(P1), knotvector(P2), knotvector(P3)
     F(t1, t2, t3) = bsplinebasis(P1, i1, t1) * bsplinebasis(P2, i2, t2) * bsplinebasis(P3, i3, t3) * func(t1, t2, t3)
 
     f1, l1 = i1, i1+p1
@@ -210,7 +210,7 @@ end
 
 function _f_b_int_I(func, i1, i2, i3, P::Tuple{<:AbstractBSplineSpace{p1}, <:AbstractBSplineSpace{p2}, <:AbstractBSplineSpace{p3}}, gl1, gl2, gl3) where {p1,p2,p3}
     P1, P2, P3 = P
-    k1, k2, k3 = knots(P1), knots(P2), knots(P3)
+    k1, k2, k3 = knotvector(P1), knotvector(P2), knotvector(P3)
     m1, m2, m3 = length(k1), length(k2), length(k3)
     F(t1, t2, t3) = bsplinebasis(P1, i1, t1) * bsplinebasis(P2, i2, t2) * bsplinebasis(P3, i3, t3) * func(t1, t2, t3)
 
diff --git a/src/_KnotVector.jl b/src/_KnotVector.jl
index 35cdfa62..2bc96dba 100644
--- a/src/_KnotVector.jl
+++ b/src/_KnotVector.jl
@@ -19,10 +19,10 @@ KnotVector([1.0, 2.0, 3.0])
 """
 struct KnotVector{T} <: AbstractKnotVector{T}
     vector::Vector{T}
-    global unsafe_knots(::Type{T}, v) where T = new{T}(v)
+    global unsafe_knotvector(::Type{T}, v) where T = new{T}(v)
 end
-KnotVector{T}(v::AbstractVector) where T = unsafe_knots(T,sort(v))
-KnotVector(v::AbstractVector{T}) where {T<:Real} = unsafe_knots(float(T),sort(v))
+KnotVector{T}(v::AbstractVector) where T = unsafe_knotvector(T,sort(v))
+KnotVector(v::AbstractVector{T}) where {T<:Real} = unsafe_knotvector(float(T),sort(v))
 
 @doc raw"""
 Construct knot vector from given real numbers.
@@ -36,13 +36,13 @@ julia> k = KnotVector()
 KnotVector([])
 ```
 """
-function KnotVector(knots::T...) where T<:Real
-    return unsafe_knots(float(T), sort!(collect(knots)))
+function KnotVector(knotvector::T...) where T<:Real
+    return unsafe_knotvector(float(T), sort!(collect(knotvector)))
 end
-function KnotVector{T}(knots::Real...) where T<:Real
-    return unsafe_knots(T, sort!(collect(knots)))
+function KnotVector{T}(knotvector::Real...) where T<:Real
+    return unsafe_knotvector(T, sort!(collect(knotvector)))
 end
-KnotVector() = unsafe_knots(Float64, Float64[])
+KnotVector() = unsafe_knotvector(Float64, Float64[])
 
 function Base.show(io::IO, k::KnotVector)
     if k.vector == Float64[]
@@ -78,7 +78,7 @@ julia> k1 + k2
 KnotVector([1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 8.0])
 ```
 """
-Base.:+(k1::KnotVector{T}, k2::KnotVector{T}) where T = unsafe_knots(T,sort!(vcat(k1.vector,k2.vector)))
+Base.:+(k1::KnotVector{T}, k2::KnotVector{T}) where T = unsafe_knotvector(T,sort!(vcat(k1.vector,k2.vector)))
 
 # TODO: add a method for KnotVector{Int} + KnotVector{Float64}
 
diff --git a/src/_Refinement.jl b/src/_Refinement.jl
index e4c6cb0b..70ad187a 100644
--- a/src/_Refinement.jl
+++ b/src/_Refinement.jl
@@ -75,7 +75,7 @@ end
 
 
 @doc raw"""
-Refinement of B-spline manifold with additional degree and knots.
+Refinement of B-spline manifold with additional degree and knotvector.
 """
 function refinement(M::BSplineManifold{Dim}; p₊::Union{Nothing,NTuple{Dim,Int}}=nothing, k₊::Union{Nothing,NTuple{Dim,KnotVector{T}}}=nothing) where {Dim, T}
     Ps = bsplinespaces(M)
@@ -96,7 +96,7 @@ function refinement(M::BSplineManifold{Dim}; p₊::Union{Nothing,NTuple{Dim,Int}
 end
 
 @doc raw"""
-Refinement of B-spline manifold with additional degree and knots.
+Refinement of B-spline manifold with additional degree and knotvector.
 """
 function refinement(M::CustomBSplineManifold; p₊::Union{Nothing,NTuple{Dim,Int}}=nothing, k₊::Union{Nothing,NTuple{Dim,KnotVector{T}}}=nothing) where {Dim, T}
     Ps = collect(bsplinespaces(M))


Test patch:
diff --git a/test/test_BSplineSpace.jl b/test/test_BSplineSpace.jl
index fca58143..291b1086 100644
--- a/test/test_BSplineSpace.jl
+++ b/test/test_BSplineSpace.jl
@@ -38,8 +38,8 @@
     @test P5 ⋢ P4
     @test P4 ⋣ P5
 
-    P4_ = BSplineSpace{degree(P4)-1}(knots(P4)[2:end-1])
-    P5_ = BSplineSpace{degree(P5)-1}(knots(P5)[2:end-1])
+    P4_ = BSplineSpace{degree(P4)-1}(knotvector(P4)[2:end-1])
+    P5_ = BSplineSpace{degree(P5)-1}(knotvector(P5)[2:end-1])
     @test P4_ ⊑ P5_
 
 end
diff --git a/test/test_ChangeBasis.jl b/test/test_ChangeBasis.jl
index 9462b289..a1814656 100644
--- a/test/test_ChangeBasis.jl
+++ b/test/test_ChangeBasis.jl
@@ -35,8 +35,8 @@
     Δ45 = [bsplinebasis(P4, i, t) - sum(A45[i, j] * bsplinebasis(P5, j, t) for j in 1:n5) for i in 1:n1, t in 2 * rand(10) .+ 2]
     @test norm(Δ45) < ε
 
-    P6 = BSplineSpace{p4-1}(knots(P4)[2:end-1])
-    P7 = BSplineSpace{p5-1}(knots(P5)[2:end-1])
+    P6 = BSplineSpace{p4-1}(knotvector(P4)[2:end-1])
+    P7 = BSplineSpace{p5-1}(knotvector(P5)[2:end-1])
     @test P6 ⊑ P7
     @test P6 ⊈ P7