@numericelements/knot-sequence
Version:
A library for generating and manipulating knot sequences for b-spline curves and surfaces
111 lines (107 loc) • 6.06 kB
JavaScript
'use strict';
var KnotSequences = require('./namedConstants/KnotSequences.cjs');
var AbstractIncreasingOpenKnotSequence = require('./AbstractIncreasingOpenKnotSequence.cjs');
var KnotIndexIncreasingSequence = require('./KnotIndexIncreasingSequence.cjs');
var KnotSequenceConstructorInterface = require('./KnotSequenceConstructorInterface.cjs');
var KnotSequences$1 = require('./ErrorMessages/KnotSequences.cjs');
var fromIncreasingToStrictlyIncreasingOpenKnotSequenceOC = require('./KnotSequenceAndUtilities/fromIncreasingToStrictlyIncreasingOpenKnotSequenceOC.cjs');
var KnotIndexStrictlyIncreasingSequence = require('./KnotIndexStrictlyIncreasingSequence.cjs');
class IncreasingOpenKnotSequenceOpenCurve extends AbstractIncreasingOpenKnotSequence.AbstractIncreasingOpenKnotSequence {
constructor(maxMultiplicityOrder, knotParameters) {
super(maxMultiplicityOrder, knotParameters);
if (knotParameters.type !== KnotSequenceConstructorInterface.INCREASINGOPENKNOTSEQUENCE_UPTOC0DISCONTINUITY)
this.updateNormalizedBasisOrigin();
this.checkNonUniformKnotMultiplicityOrder();
this.checkUniformityOfKnotMultiplicity();
this.checkUniformityOfKnotSpacing();
}
checkNonUniformKnotMultiplicityOrder() {
this._isKnotMultiplicityNonUniform = false;
if (this.knotSequence[0].multiplicity === this._maxMultiplicityOrder &&
this.knotSequence[this.knotSequence.length - 1].multiplicity === this._maxMultiplicityOrder)
this._isKnotMultiplicityNonUniform = true;
}
clone() {
if (this._isSequenceUpToC0Discontinuity) {
return new IncreasingOpenKnotSequenceOpenCurve(this._maxMultiplicityOrder, { type: KnotSequenceConstructorInterface.INCREASINGOPENKNOTSEQUENCE_UPTOC0DISCONTINUITY, knots: this.allAbscissae });
}
else {
return new IncreasingOpenKnotSequenceOpenCurve(this._maxMultiplicityOrder, { type: KnotSequenceConstructorInterface.INCREASINGOPENKNOTSEQUENCE, knots: this.allAbscissae });
}
}
toKnotIndexStrictlyIncreasingSequence(index) {
const strictlyIncreasingKnotSequence = fromIncreasingToStrictlyIncreasingOpenKnotSequenceOC.fromIncreasingToStrictlyIncreasingOpenKnotSequenceOC(this);
const abscissa = this.abscissaAtIndex(index);
let i = 0;
for (const knot of strictlyIncreasingKnotSequence.allAbscissae) {
if (knot !== undefined) {
if (knot === abscissa)
break;
i++;
}
}
return new KnotIndexStrictlyIncreasingSequence.KnotIndexStrictlyIncreasingSequence(i);
}
findSpan(u) {
let index = KnotSequences.UPPER_BOUND_NORMALIZED_BASIS_DEFAULT_ABSCISSA;
if (u < KnotSequences.KNOT_SEQUENCE_ORIGIN || u > this._uMax) {
this.throwRangeErrorMessage("findSpan", KnotSequences$1.EM_U_OUTOF_KNOTSEQ_RANGE);
}
else {
if (this.isAbscissaCoincidingWithKnot(u)) {
index = 0;
for (const knot of this.knotSequence) {
index += knot.multiplicity;
if (Math.abs(u - knot.abscissa) < KnotSequences.KNOT_COINCIDENCE_TOLERANCE) {
if (knot.abscissa === this.knotSequence[this.knotSequence.length - 1].abscissa) {
index -= this.knotSequence[this.knotSequence.length - 1].multiplicity;
}
const curveDegree = this._maxMultiplicityOrder - 1;
if (this.isKnotMultiplicityUniform && index === (this.knotSequence.length - curveDegree))
index -= 1;
index -= 1;
break;
}
}
return new KnotIndexIncreasingSequence.KnotIndexIncreasingSequence(index);
}
const indexAtUmax = this.getKnotIndexNormalizedBasisAtSequenceEnd();
index = this.findSpanWithAbscissaDistinctFromKnotIncreasingKnotSequence(u, indexAtUmax.knot.knotIndex);
}
return new KnotIndexIncreasingSequence.KnotIndexIncreasingSequence(index);
}
revertKnotSequence() {
const newKnotSequence = this.clone();
newKnotSequence.revertKnotSpacing();
return newKnotSequence;
}
decrementKnotMultiplicity(index, checkSequenceConsistency = true) {
const newKnotSequence = this.clone();
newKnotSequence.decrementKnotMultiplicityKnotArrayMutSeq(index, checkSequenceConsistency);
return newKnotSequence;
}
raiseKnotMultiplicity(arrayIndices, multiplicity = 1, checkSequenceConsistency = true) {
const newKnotSequence = this.clone();
newKnotSequence.raiseKnotMultiplicityKnotArrayMutSeq(arrayIndices, multiplicity, checkSequenceConsistency);
return newKnotSequence;
}
insertKnot(arrayAbscissae, multplicity = 1) {
const newKnotSequence = this.clone();
newKnotSequence.insertKnotAbscissaArrayMutSeq(arrayAbscissae, multplicity);
return newKnotSequence;
}
updateKnotSequenceThroughNormalizedBasisAnalysis() {
const previousKnotSequence = this.knotSequence.slice();
this.updateKnotSequenceThroughNormalizedBasisAnalysisMutSeq();
const knotAbscissae = [];
for (const knot of this.allAbscissae) {
knotAbscissae.push(knot);
}
let updatedSeq = new IncreasingOpenKnotSequenceOpenCurve(this._maxMultiplicityOrder, { type: KnotSequenceConstructorInterface.INCREASINGOPENKNOTSEQUENCE, knots: knotAbscissae });
if (this._isSequenceUpToC0Discontinuity)
updatedSeq = new IncreasingOpenKnotSequenceOpenCurve(this._maxMultiplicityOrder, { type: KnotSequenceConstructorInterface.INCREASINGOPENKNOTSEQUENCE_UPTOC0DISCONTINUITY, knots: knotAbscissae });
this.knotSequence = previousKnotSequence;
return updatedSeq;
}
}
exports.IncreasingOpenKnotSequenceOpenCurve = IncreasingOpenKnotSequenceOpenCurve;