Skip to content

NURBSCurve: Fix clone(). - #34542

Merged
Mugen87 merged 1 commit into
mrdoob:devfrom
Dev-next-gen:nurbscurve-clone
Sep 11, 2026
Merged

Mugen87 merged 1 commit into
mrdoob:devfrom
Dev-next-gen:nurbscurve-clone

Conversation

@Dev-next-gen

Copy link
Copy Markdown

Related issue: none

Description

I noticed that NURBSCurve.clone() returns a curve that can't be used. NURBSCurve got toJSON() and fromJSON() in #29514 but never a copy(), so clone() falls back to Curve.copy(), which only copies arcLengthDivisions. The clone ends up with degree and knots undefined and no control points, and the first getPoint() call throws:

const curve = new NURBSCurve( 3, knots, controlPoints );
const clone = curve.clone();

clone.degree; // undefined
clone.controlPoints.length; // 0
clone.getPoint( 0.5 ); // TypeError: Cannot read properties of undefined (reading '0')

The same thing happens to a CurvePath (and so a Path or Shape) holding a NURBSCurve, since CurvePath.copy() clones each of its curves.

The new copy() mirrors fromJSON(). The knots array is copied and the control points are cloned, so the clone doesn't share state with the source.

I added a clone test next to the existing toJSON/fromJSON ones. Without the fix it fails on the degree, knots, control points and end knot assertions, then dies in getPoint(). With it, npm run test-unit-addons passes (398/398) and eslint is clean on both files.

AI tools used

@Mugen87 Mugen87 added this to the r187 milestone Sep 11, 2026
@Mugen87
Mugen87 merged commit a09daae into mrdoob:dev Sep 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants