Skip to content

Commit

Permalink
fully handle multiplicity check
Browse files Browse the repository at this point in the history
  • Loading branch information
HoBeZwe committed May 8, 2024
1 parent a8edf23 commit 0851812
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/fundamentalOperations/knotInsertion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ function extendKnotVector!(knotVecOrig, degree::Int, newParametricPoint::Real, m

# --- check whether resulting mulitplicity makes sense
newMult = multiplicity + oldMult
if newMult > degree
@info "The multiplicity of the inserted knot is limited to $(degree)."
newMult = degree
end
newMult = limitMultiplicity(newMult, degree)

# --- generate new knot vector
toInsert = repeat([newParametricPoint], newMult) # repeat the parametric point to the final multiplicity (old + new)
Expand All @@ -245,6 +242,27 @@ function extendKnotVector!(knotVecOrig, degree::Int, newParametricPoint::Real, m
end


"""
limitMultiplicity(newMult::Int, degree::Int)
Limit the multiplicity to the maximum allowed value.
"""
function limitMultiplicity(newMult::Int, degree::Int)

if degree == 0
newMult > 1 && @info "The multiplicity of the inserted knot is limited to 1."
return 1
end

if newMult > degree
@info "The multiplicity of the inserted knot is limited to $(degree)."
return degree
end

return newMult
end


"""
extendControlPoints!(controlPoints, knotVecOrig, degree::Int, pos::Int, uNew::Real, multiplicity::Int, oldMult::Int, weights)
Expand All @@ -258,8 +276,7 @@ function extendControlPoints!(
controlPoints, knotVecOrig, degree::Int, pos::Int, uNew::Real, multiplicity::Int, oldMult::Int, weights=[]
)

degree == 0 && return extendControlPoints!(controlPoints, pos, multiplicity, oldMult) # not so nice - why does algorithm not hold for degree=0?
#T = eltype(controlPoints[1])
degree == 0 && return extendControlPoints!(controlPoints, pos, multiplicity, oldMult)

# --- computation including weights
if !isempty(weights)
Expand Down Expand Up @@ -335,15 +352,10 @@ Can multiplicity be maximum 1 and/or oldMult maximum 0? => simplify below algori
"""
function extendControlPoints!(controlPoints, pos::Int, multiplicity::Int, oldMult::Int)

newControlPoints = similar(controlPoints, oldMult + multiplicity)
multiplicity == 0 && return nothing

aux = controlPoints[(pos):(pos - oldMult)]
for r in 1:multiplicity
newControlPoints[r] = aux[1]
end

# splice new computed points into array (replacing the correct amount)
splice!(controlPoints, (pos + 1):(pos - oldMult - 1), newControlPoints)
# splice new points into array
splice!(controlPoints, (pos + 1):pos, [controlPoints[pos]])

return nothing
end
16 changes: 16 additions & 0 deletions test/fundamentalOperations/knotInsertion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@
# verify
@test minimum(C1 .≈ C2)
end

@testset "Degree = 0 case" begin

kV2 = Float64[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
cP = [P1, P2, P3, P4, P5]

N = BsplineCurve(Bspline(0, kV2), cP)
C1 = N(evalpoints)

# insert a list of parametric points
N2 = insertKnot(N, 0.1, 2)
C2 = N2(evalpoints)

# verify
@test minimum(C1 .≈ C2)
end
end


Expand Down

2 comments on commit 0851812

@HoBeZwe
Copy link
Owner Author

@HoBeZwe HoBeZwe commented on 0851812 May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/106430

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 08518127f7f53d81b723d420d12f4f71be6d99f8
git push origin v0.6.1

Please sign in to comment.