Skip to content

Commit af9bc2e

Browse files
authored
Merge pull request #7703 from processing/spline-point-tangent
Rename curvePoint/curveTangent to splinePoint/splineTangent
2 parents a19995f + acb82f7 commit af9bc2e

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

src/shape/curves.js

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ function curves(p5, fn){
505505
* noFill();
506506
* strokeWeight(1);
507507
* stroke(0);
508-
* curve(5, 26, 73, 24, 73, 61, 15, 65);
508+
* spline(5, 26, 73, 24, 73, 61, 15, 65);
509509
*
510510
* // Draw red spline curves from the anchor points to the control points.
511511
* stroke(255, 0, 0);
@@ -653,8 +653,6 @@ function curves(p5, fn){
653653
* @chainable
654654
*/
655655
fn.spline = function(...args) {
656-
// p5._validateParameters('curve', args);
657-
658656
if (!this._renderer.states.strokeColor && !this._renderer.states.fillColor) {
659657
return this;
660658
}
@@ -666,9 +664,9 @@ function curves(p5, fn){
666664
/**
667665
* Calculates coordinates along a spline curve using interpolation.
668666
*
669-
* `curvePoint()` calculates coordinates along a spline curve using the
667+
* `splinePoint()` calculates coordinates along a spline curve using the
670668
* anchor and control points. It expects points in the same order as the
671-
* <a href="#/p5/curve">curve()</a> function. `curvePoint()` works one axis
669+
* <a href="#/p5/spline">spline()</a> function. `splinePoint()` works one axis
672670
* at a time. Passing the anchor and control points' x-coordinates will
673671
* calculate the x-coordinate of a point on the curve. Passing the anchor and
674672
* control points' y-coordinates will calculate the y-coordinate of a point on
@@ -685,7 +683,7 @@ function curves(p5, fn){
685683
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
686684
* between them.
687685
*
688-
* @method curvePoint
686+
* @method splinePoint
689687
* @param {Number} a coordinate of first anchor point.
690688
* @param {Number} b coordinate of first control point.
691689
* @param {Number} c coordinate of second control point.
@@ -713,24 +711,24 @@ function curves(p5, fn){
713711
*
714712
* // Draw the curve.
715713
* noFill();
716-
* curve(x1, y1, x2, y2, x3, y3, x4, y4);
714+
* spline(x1, y1, x2, y2, x3, y3, x4, y4);
717715
*
718716
* // Draw circles along the curve's path.
719717
* fill(255);
720718
*
721719
* // Top.
722-
* let x = curvePoint(x1, x2, x3, x4, 0);
723-
* let y = curvePoint(y1, y2, y3, y4, 0);
720+
* let x = splinePoint(x1, x2, x3, x4, 0);
721+
* let y = splinePoint(y1, y2, y3, y4, 0);
724722
* circle(x, y, 5);
725723
*
726724
* // Center.
727-
* x = curvePoint(x1, x2, x3, x4, 0.5);
728-
* y = curvePoint(y1, y2, y3, y4, 0.5);
725+
* x = splinePoint(x1, x2, x3, x4, 0.5);
726+
* y = splinePoint(y1, y2, y3, y4, 0.5);
729727
* circle(x, y, 5);
730728
*
731729
* // Bottom.
732-
* x = curvePoint(x1, x2, x3, x4, 1);
733-
* y = curvePoint(y1, y2, y3, y4, 1);
730+
* x = splinePoint(x1, x2, x3, x4, 1);
731+
* y = splinePoint(y1, y2, y3, y4, 1);
734732
* circle(x, y, 5);
735733
*
736734
* describe('A black curve on a gray square. The endpoints and center of the curve are marked with white circles.');
@@ -761,12 +759,12 @@ function curves(p5, fn){
761759
*
762760
* // Draw the curve.
763761
* noFill();
764-
* curve(x1, y1, x2, y2, x3, y3, x4, y4);
762+
* spline(x1, y1, x2, y2, x3, y3, x4, y4);
765763
*
766764
* // Calculate the circle's coordinates.
767765
* let t = 0.5 * sin(frameCount * 0.01) + 0.5;
768-
* let x = curvePoint(x1, x2, x3, x4, t);
769-
* let y = curvePoint(y1, y2, y3, y4, t);
766+
* let x = splinePoint(x1, x2, x3, x4, t);
767+
* let y = splinePoint(y1, y2, y3, y4, t);
770768
*
771769
* // Draw the circle.
772770
* fill(255);
@@ -775,8 +773,7 @@ function curves(p5, fn){
775773
* </code>
776774
* </div>
777775
*/
778-
fn.curvePoint = function(a, b, c, d, t) {
779-
// p5._validateParameters('curvePoint', arguments);
776+
fn.splinePoint = function(a, b, c, d, t) {
780777
const s = this._renderer.states.splineProperties.tightness,
781778
t3 = t * t * t,
782779
t2 = t * t,
@@ -793,9 +790,9 @@ function curves(p5, fn){
793790
* Tangent lines skim the surface of a curve. A tangent line's slope equals
794791
* the curve's slope at the point where it intersects.
795792
*
796-
* `curveTangent()` calculates coordinates along a tangent line using the
793+
* `splineTangent()` calculates coordinates along a tangent line using the
797794
* spline curve's anchor and control points. It expects points in the same
798-
* order as the <a href="#/p5/curve">curve()</a> function. `curveTangent()`
795+
* order as the <a href="#/p5/spline">spline()</a> function. `splineTangent()`
799796
* works one axis at a time. Passing the anchor and control points'
800797
* x-coordinates will calculate the x-coordinate of a point on the tangent
801798
* line. Passing the anchor and control points' y-coordinates will calculate
@@ -812,7 +809,7 @@ function curves(p5, fn){
812809
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
813810
* between them.
814811
*
815-
* @method curveTangent
812+
* @method splineTangent
816813
* @param {Number} a coordinate of first control point.
817814
* @param {Number} b coordinate of first anchor point.
818815
* @param {Number} c coordinate of second anchor point.
@@ -840,48 +837,48 @@ function curves(p5, fn){
840837
*
841838
* // Draw the curve.
842839
* noFill();
843-
* curve(x1, y1, x2, y2, x3, y3, x4, y4);
840+
* spline(x1, y1, x2, y2, x3, y3, x4, y4);
844841
*
845842
* // Draw tangents along the curve's path.
846843
* fill(255);
847844
*
848845
* // Top circle.
849846
* stroke(0);
850-
* let x = curvePoint(x1, x2, x3, x4, 0);
851-
* let y = curvePoint(y1, y2, y3, y4, 0);
847+
* let x = splinePoint(x1, x2, x3, x4, 0);
848+
* let y = splinePoint(y1, y2, y3, y4, 0);
852849
* circle(x, y, 5);
853850
*
854851
* // Top tangent line.
855852
* // Scale the tangent point to draw a shorter line.
856853
* stroke(255, 0, 0);
857-
* let tx = 0.2 * curveTangent(x1, x2, x3, x4, 0);
858-
* let ty = 0.2 * curveTangent(y1, y2, y3, y4, 0);
854+
* let tx = 0.2 * splineTangent(x1, x2, x3, x4, 0);
855+
* let ty = 0.2 * splineTangent(y1, y2, y3, y4, 0);
859856
* line(x + tx, y + ty, x - tx, y - ty);
860857
*
861858
* // Center circle.
862859
* stroke(0);
863-
* x = curvePoint(x1, x2, x3, x4, 0.5);
864-
* y = curvePoint(y1, y2, y3, y4, 0.5);
860+
* x = splinePoint(x1, x2, x3, x4, 0.5);
861+
* y = splinePoint(y1, y2, y3, y4, 0.5);
865862
* circle(x, y, 5);
866863
*
867864
* // Center tangent line.
868865
* // Scale the tangent point to draw a shorter line.
869866
* stroke(255, 0, 0);
870-
* tx = 0.2 * curveTangent(x1, x2, x3, x4, 0.5);
871-
* ty = 0.2 * curveTangent(y1, y2, y3, y4, 0.5);
867+
* tx = 0.2 * splineTangent(x1, x2, x3, x4, 0.5);
868+
* ty = 0.2 * splineTangent(y1, y2, y3, y4, 0.5);
872869
* line(x + tx, y + ty, x - tx, y - ty);
873870
*
874871
* // Bottom circle.
875872
* stroke(0);
876-
* x = curvePoint(x1, x2, x3, x4, 1);
877-
* y = curvePoint(y1, y2, y3, y4, 1);
873+
* x = splinePoint(x1, x2, x3, x4, 1);
874+
* y = splinePoint(y1, y2, y3, y4, 1);
878875
* circle(x, y, 5);
879876
*
880877
* // Bottom tangent line.
881878
* // Scale the tangent point to draw a shorter line.
882879
* stroke(255, 0, 0);
883-
* tx = 0.2 * curveTangent(x1, x2, x3, x4, 1);
884-
* ty = 0.2 * curveTangent(y1, y2, y3, y4, 1);
880+
* tx = 0.2 * splineTangent(x1, x2, x3, x4, 1);
881+
* ty = 0.2 * splineTangent(y1, y2, y3, y4, 1);
885882
* line(x + tx, y + ty, x - tx, y - ty);
886883
*
887884
* describe(
@@ -891,9 +888,7 @@ function curves(p5, fn){
891888
* </code>
892889
* </div>
893890
*/
894-
fn.curveTangent = function(a, b, c, d, t) {
895-
// p5._validateParameters('curveTangent', arguments);
896-
891+
fn.splineTangent = function(a, b, c, d, t) {
897892
const s = this._renderer.states.splineProperties.tightness,
898893
tt3 = t * t * 3,
899894
t2 = t * 2,

test/unit/core/curves.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ suite('Curves', function() {
5757
});
5858
});
5959

60-
suite('p5.prototype.curvePoint', function() {
60+
suite('p5.prototype.splinePoint', function() {
6161
var result;
6262
test('should be a function', function() {
63-
assert.ok(mockP5Prototype.curvePoint);
64-
assert.typeOf(mockP5Prototype.curvePoint, 'function');
63+
assert.ok(mockP5Prototype.splinePoint);
64+
assert.typeOf(mockP5Prototype.splinePoint, 'function');
6565
});
6666
test('should return the correct point on a Catmull-Rom Curve', function() {
67-
result = mockP5Prototype.curvePoint(5, 5, 73, 73, 0.5);
67+
result = mockP5Prototype.splinePoint(5, 5, 73, 73, 0.5);
6868
assert.equal(result, 39);
6969
assert.notEqual(result, -1);
7070
});
7171
});
7272

73-
suite('p5.prototype.curveTangent', function() {
73+
suite('p5.prototype.splineTangent', function() {
7474
var result;
7575
test('should be a function', function() {
76-
assert.ok(mockP5Prototype.curveTangent);
77-
assert.typeOf(mockP5Prototype.curveTangent, 'function');
76+
assert.ok(mockP5Prototype.splineTangent);
77+
assert.typeOf(mockP5Prototype.splineTangent, 'function');
7878
});
7979
test('should return the correct point on a Catmull-Rom Curve', function() {
80-
result = mockP5Prototype.curveTangent(95, 73, 73, 15, 0.5);
80+
result = mockP5Prototype.splineTangent(95, 73, 73, 15, 0.5);
8181
assert.equal(result, 10);
8282
assert.notEqual(result, -1);
8383
});

0 commit comments

Comments
 (0)