Skip to content

Commit d08e9da

Browse files
committed
Rename curve() to spline()
1 parent b1870eb commit d08e9da

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

src/core/p5.Renderer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ class Renderer {
212212
this.currentShape.vertex(position, textureCoordinates);
213213
}
214214

215+
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
216+
this._pInst.beginShape();
217+
this._pInst.vertex(x1, y1);
218+
this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4);
219+
this._pInst.endShape();
220+
return this;
221+
}
222+
223+
spline(x1, y1, x2, y2, x3, y3, x4, y4) {
224+
this._pInst.beginShape();
225+
this._pInst.splineVertex(x1, y1);
226+
this._pInst.splineVertex(x2, y2);
227+
this._pInst.splineVertex(x3, y3);
228+
this._pInst.splineVertex(x4, y4);
229+
this._pInst.endShape();
230+
return this;
231+
}
232+
215233
beginClip(options = {}) {
216234
if (this._clipping) {
217235
throw new Error("It looks like you're trying to clip while already in the middle of clipping. Did you forget to endClip()?");

src/core/p5.Renderer2D.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Renderer2D extends Renderer {
264264
shape.accept(visitor);
265265
if (this._clipping) {
266266
this.clipPath.addPath(visitor.path);
267-
this.clipPath.closePath();
267+
this.clipPath.closePath();
268268
} else {
269269
if (this.states.fillColor) {
270270
this.drawingContext.fill(visitor.path);
@@ -969,27 +969,6 @@ class Renderer2D extends Renderer {
969969
}
970970
}
971971

972-
//////////////////////////////////////////////
973-
// SHAPE | Curves
974-
//////////////////////////////////////////////
975-
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
976-
this._pInst.beginShape();
977-
this._pInst.vertex(x1, y1);
978-
this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4);
979-
this._pInst.endShape();
980-
return this;
981-
}
982-
983-
curve(x1, y1, x2, y2, x3, y3, x4, y4) {
984-
this._pInst.beginShape();
985-
this._pInst.splineVertex(x1, y1);
986-
this._pInst.splineVertex(x2, y2);
987-
this._pInst.splineVertex(x3, y3);
988-
this._pInst.splineVertex(x4, y4);
989-
this._pInst.endShape();
990-
return this;
991-
}
992-
993972
//////////////////////////////////////////////
994973
// TRANSFORM
995974
//////////////////////////////////////////////

src/shape/curves.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ function curves(p5, fn){
582582
* point.
583583
*
584584
* Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
585-
* `curve()` has twelve arguments because each point has x-, y-, and
585+
* `spline()` has twelve arguments because each point has x-, y-, and
586586
* z-coordinates.
587587
*
588-
* @method curve
588+
* @method spline
589589
* @param {Number} x1 x-coordinate of the first control point.
590590
* @param {Number} y1 y-coordinate of the first control point.
591591
* @param {Number} x2 x-coordinate of the first anchor point.
@@ -612,8 +612,8 @@ function curves(p5, fn){
612612
*
613613
* // Draw red spline curves from the anchor points to the control points.
614614
* stroke(255, 0, 0);
615-
* curve(5, 26, 5, 26, 73, 24, 73, 61);
616-
* curve(73, 24, 73, 61, 15, 65, 15, 65);
615+
* spline(5, 26, 5, 26, 73, 24, 73, 61);
616+
* spline(73, 24, 73, 61, 15, 65, 15, 65);
617617
*
618618
* // Draw the anchor points in black.
619619
* strokeWeight(5);
@@ -654,12 +654,12 @@ function curves(p5, fn){
654654
* noFill();
655655
* strokeWeight(1);
656656
* stroke(0);
657-
* curve(x1, y1, 73, 24, 73, 61, 15, 65);
657+
* spline(x1, y1, 73, 24, 73, 61, 15, 65);
658658
*
659659
* // Draw red spline curves from the anchor points to the control points.
660660
* stroke(255, 0, 0);
661-
* curve(x1, y1, x1, y1, 73, 24, 73, 61);
662-
* curve(73, 24, 73, 61, 15, 65, 15, 65);
661+
* spline(x1, y1, x1, y1, 73, 24, 73, 61);
662+
* spline(73, 24, 73, 61, 15, 65, 15, 65);
663663
*
664664
* // Draw the anchor points in black.
665665
* strokeWeight(5);
@@ -704,7 +704,7 @@ function curves(p5, fn){
704704
*
705705
* // Draw the red balloon.
706706
* fill('red');
707-
* curve(-150, 275, 50, 60, 50, 60, 250, 275);
707+
* spline(-150, 275, 50, 60, 50, 60, 250, 275);
708708
*
709709
* // Draw the balloon string.
710710
* line(50, 60, 50, 80);
@@ -730,7 +730,7 @@ function curves(p5, fn){
730730
*
731731
* // Draw the red balloon.
732732
* fill('red');
733-
* curve(-200, 225, 0, 0, 10, 0, 0, 10, 0, 200, 225, 0);
733+
* spline(-200, 225, 0, 0, 10, 0, 0, 10, 0, 200, 225, 0);
734734
*
735735
* // Draw the balloon string.
736736
* line(0, 10, 0, 0, 30, 0);
@@ -740,7 +740,7 @@ function curves(p5, fn){
740740
*/
741741

742742
/**
743-
* @method curve
743+
* @method spline
744744
* @param {Number} x1
745745
* @param {Number} y1
746746
* @param {Number} z1 z-coordinate of the first control point.
@@ -755,12 +755,13 @@ function curves(p5, fn){
755755
* @param {Number} z4 z-coordinate of the second control point.
756756
* @chainable
757757
*/
758-
fn.curve = function(...args) {
758+
fn.spline = function(...args) {
759759
// p5._validateParameters('curve', args);
760760

761-
if (this._renderer.states.strokeColor) {
762-
this._renderer.curve(...args);
761+
if (!this._renderer.states.strokeColor && !this._renderer.states.fillColor) {
762+
return this;
763763
}
764+
this._renderer.spline(...args);
764765

765766
return this;
766767
};

test/unit/core/curves.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ suite('Curves', function() {
5050
});
5151
});
5252

53-
suite('p5.prototype.curve', function() {
53+
suite('p5.prototype.spline', function() {
5454
test('should be a function', function() {
55-
assert.ok(mockP5Prototype.curve);
56-
assert.typeOf(mockP5Prototype.curve, 'function');
55+
assert.ok(mockP5Prototype.spline);
56+
assert.typeOf(mockP5Prototype.spline, 'function');
5757
});
5858
});
5959

0 commit comments

Comments
 (0)