@@ -2,6 +2,7 @@ function addShapes(p5, fn, lifecycles) {
22 const oldBezierVertex = fn . bezierVertex ;
33 const oldEndContour = fn . endContour ;
44 const oldEndShape = fn . endShape ;
5+ const oldCurveDetail = fn . curveDetail ;
56
67 lifecycles . predraw = function ( ) {
78 this . splineProperty ( 'ends' , this . EXCLUDE ) ;
@@ -70,6 +71,22 @@ function addShapes(p5, fn, lifecycles) {
7071 fn . endGeometry = function ( ...args ) {
7172 return this . _renderer . endGeometry ( ...args ) ;
7273 }
74+
75+ for ( const key of [ 'curveDetail' , 'bezierDetail' ] ) {
76+ fn [ key ] = function ( numPoints ) {
77+ // p5 2.0's curveDetail defined *density* while 1.x's defined *absolute number of points.*
78+ // The only way to do a true conversion would involve updating the value dynamically based
79+ // on the length of the curve. Since this would be complex to do as an addon, we do
80+ // the calculation based on an approximate average curve length.
81+ const avgLength = Math . hypot ( this . width , this . height ) / 3 ;
82+ if ( numPoints ) {
83+ const density = numPoints / avgLength ;
84+ return oldCurveDetail . call ( this , density ) ;
85+ } else {
86+ return oldCurveDetail . call ( this ) * avgLength ;
87+ }
88+ }
89+ }
7390}
7491
7592if ( typeof p5 !== undefined ) {
0 commit comments