From 55d67eec5133d2ab11e61584c3bf0991c3dccfc7 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sat, 22 Mar 2025 14:03:21 -0400 Subject: [PATCH 1/3] Handle rename of curve() to spline() --- src/shapes.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shapes.js b/src/shapes.js index f9b7225..463b849 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -59,6 +59,10 @@ function addShapes(p5, fn, lifecycles) { this._renderer._currentShape.at(-1, -1).handlesClose = () => false; oldEndShape.call(this, mode); } + + fn.curve = function(...args) { + return this.spline(...args); + } } if (typeof p5 !== undefined) { From ff9e11dfa70d0c8669dff74b1df62627478b970e Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sat, 22 Mar 2025 14:05:17 -0400 Subject: [PATCH 2/3] Put back beginGeometry/endGeometry --- src/shapes.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/shapes.js b/src/shapes.js index 463b849..606a77b 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -63,6 +63,13 @@ function addShapes(p5, fn, lifecycles) { fn.curve = function(...args) { return this.spline(...args); } + + fn.beginGeometry = function(...args) { + return this._renderer.beginGeometry(...args); + } + fn.endGeometry = function(...args) { + return this._renderer.endGeometry(...args); + } } if (typeof p5 !== undefined) { From 29bcf5ae7e1088b2ecb9e88afb828587df73a0cc Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sat, 22 Mar 2025 14:32:16 -0400 Subject: [PATCH 3/3] Add approximate curveDetail implementation --- src/shapes.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/shapes.js b/src/shapes.js index 606a77b..0fd686c 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -2,6 +2,7 @@ function addShapes(p5, fn, lifecycles) { const oldBezierVertex = fn.bezierVertex; const oldEndContour = fn.endContour; const oldEndShape = fn.endShape; + const oldCurveDetail = fn.curveDetail; lifecycles.predraw = function() { this.splineProperty('ends', this.EXCLUDE); @@ -70,6 +71,22 @@ function addShapes(p5, fn, lifecycles) { fn.endGeometry = function(...args) { return this._renderer.endGeometry(...args); } + + for (const key of ['curveDetail', 'bezierDetail']) { + fn[key] = function(numPoints) { + // p5 2.0's curveDetail defined *density* while 1.x's defined *absolute number of points.* + // The only way to do a true conversion would involve updating the value dynamically based + // on the length of the curve. Since this would be complex to do as an addon, we do + // the calculation based on an approximate average curve length. + const avgLength = Math.hypot(this.width, this.height) / 3; + if (numPoints) { + const density = numPoints / avgLength; + return oldCurveDetail.call(this, density); + } else { + return oldCurveDetail.call(this) * avgLength; + } + } + } } if (typeof p5 !== undefined) {