@@ -2,6 +2,7 @@ function addShapes(p5, fn, lifecycles) {
2
2
const oldBezierVertex = fn . bezierVertex ;
3
3
const oldEndContour = fn . endContour ;
4
4
const oldEndShape = fn . endShape ;
5
+ const oldCurveDetail = fn . curveDetail ;
5
6
6
7
lifecycles . predraw = function ( ) {
7
8
this . splineProperty ( 'ends' , this . EXCLUDE ) ;
@@ -59,6 +60,33 @@ function addShapes(p5, fn, lifecycles) {
59
60
this . _renderer . _currentShape . at ( - 1 , - 1 ) . handlesClose = ( ) => false ;
60
61
oldEndShape . call ( this , mode ) ;
61
62
}
63
+
64
+ fn . curve = function ( ...args ) {
65
+ return this . spline ( ...args ) ;
66
+ }
67
+
68
+ fn . beginGeometry = function ( ...args ) {
69
+ return this . _renderer . beginGeometry ( ...args ) ;
70
+ }
71
+ fn . endGeometry = function ( ...args ) {
72
+ return this . _renderer . endGeometry ( ...args ) ;
73
+ }
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
+ }
62
90
}
63
91
64
92
if ( typeof p5 !== undefined ) {
0 commit comments