Skip to content

Commit d820651

Browse files
authored
Merge pull request #7600 from processing/remove-old-shape-overloads
Remove old overloads for bezierVertex() and quadraticVertex()
2 parents 3be8ce4 + a954f9b commit d820651

File tree

4 files changed

+32
-292
lines changed

4 files changed

+32
-292
lines changed

src/shape/vertex.js

+1-271
Original file line numberDiff line numberDiff line change
@@ -663,20 +663,7 @@ function vertex(p5, fn){
663663
* @param {Number} z4 z-coordinate of the anchor point.
664664
*/
665665
fn.bezierVertex = function(...args) {
666-
if (args.length === 2 * 3 || args.length === 3 * 3) {
667-
// Handle the legacy case where all bezier control points are provided
668-
// at once. We'll translate them into 3 individual calls.
669-
const stride = args.length / 3;
670-
671-
const prevOrder = this._renderer.bezierOrder();
672-
this._renderer.bezierOrder(3);
673-
for (let i = 0; i < args.length; i += stride) {
674-
this._renderer.bezierVertex(...args.slice(i, i + stride));
675-
}
676-
this._renderer.bezierOrder(prevOrder);
677-
} else {
678-
this._renderer.bezierVertex(...args);
679-
}
666+
this._renderer.bezierVertex(...args);
680667
};
681668

682669
/**
@@ -1239,263 +1226,6 @@ function vertex(p5, fn){
12391226
this._renderer.endShape(mode, count);
12401227
};
12411228

1242-
/**
1243-
* Adds a quadratic Bézier curve segment to a custom shape.
1244-
*
1245-
* `quadraticVertex()` adds a curved segment to custom shapes. The Bézier
1246-
* curve segments it creates are similar to those made by the
1247-
* <a href="#/p5/bezierVertex">bezierVertex()</a> function.
1248-
* `quadraticVertex()` must be called between the
1249-
* <a href="#/p5/beginShape">beginShape()</a> and
1250-
* <a href="#/p5/endShape">endShape()</a> functions. The curved segment uses
1251-
* the previous vertex as the first anchor point, so there must be at least
1252-
* one call to <a href="#/p5/vertex">vertex()</a> before `quadraticVertex()` can
1253-
* be used.
1254-
*
1255-
* The first two parameters, `cx` and `cy`, set the curve’s control point.
1256-
* The control point "pulls" the curve towards its.
1257-
*
1258-
* The last two parameters, `x3`, and `y3`, set the last anchor point. The
1259-
* last anchor point is where the curve ends.
1260-
*
1261-
* Bézier curves can also be drawn in 3D using WebGL mode. The 3D version of
1262-
* `bezierVertex()` has eight arguments because each point has x-, y-, and
1263-
* z-coordinates.
1264-
*
1265-
* Note: `quadraticVertex()` won’t work when an argument is passed to
1266-
* <a href="#/p5/beginShape">beginShape()</a>.
1267-
*
1268-
* @method quadraticVertex
1269-
* @param {Number} cx x-coordinate of the control point.
1270-
* @param {Number} cy y-coordinate of the control point.
1271-
* @param {Number} x3 x-coordinate of the anchor point.
1272-
* @param {Number} y3 y-coordinate of the anchor point.
1273-
* @chainable
1274-
*
1275-
* @example
1276-
* <div>
1277-
* <code>
1278-
* function setup() {
1279-
* createCanvas(100, 100);
1280-
*
1281-
* background(200);
1282-
*
1283-
* // Style the curve.
1284-
* noFill();
1285-
*
1286-
* // Draw the curve.
1287-
* beginShape();
1288-
* vertex(20, 20);
1289-
* quadraticVertex(80, 20, 50, 50);
1290-
* endShape();
1291-
*
1292-
* describe('A black curve drawn on a gray square. The curve starts at the top-left corner and ends at the center.');
1293-
* }
1294-
* </code>
1295-
* </div>
1296-
*
1297-
* <div>
1298-
* <code>
1299-
* function setup() {
1300-
* createCanvas(100, 100);
1301-
*
1302-
* background(200);
1303-
*
1304-
* // Draw the curve.
1305-
* noFill();
1306-
* beginShape();
1307-
* vertex(20, 20);
1308-
* quadraticVertex(80, 20, 50, 50);
1309-
* endShape();
1310-
*
1311-
* // Draw red lines from the anchor points to the control point.
1312-
* stroke(255, 0, 0);
1313-
* line(20, 20, 80, 20);
1314-
* line(50, 50, 80, 20);
1315-
*
1316-
* // Draw the anchor points in black.
1317-
* strokeWeight(5);
1318-
* stroke(0);
1319-
* point(20, 20);
1320-
* point(50, 50);
1321-
*
1322-
* // Draw the control point in red.
1323-
* stroke(255, 0, 0);
1324-
* point(80, 20);
1325-
*
1326-
* describe('A black curve that starts at the top-left corner and ends at the center. Its anchor and control points are marked with dots. Red lines connect both anchor points to the control point.');
1327-
* }
1328-
* </code>
1329-
* </div>
1330-
*
1331-
* <div>
1332-
* <code>
1333-
* // Click the mouse near the red dot in the top-right corner
1334-
* // and drag to change the curve's shape.
1335-
*
1336-
* let x2 = 80;
1337-
* let y2 = 20;
1338-
* let isChanging = false;
1339-
*
1340-
* function setup() {
1341-
* createCanvas(100, 100);
1342-
*
1343-
* describe('A black curve that starts at the top-left corner and ends at the center. Its anchor and control points are marked with dots. Red lines connect both anchor points to the control point.');
1344-
* }
1345-
*
1346-
* function draw() {
1347-
* background(200);
1348-
*
1349-
* // Style the curve.
1350-
* noFill();
1351-
* strokeWeight(1);
1352-
* stroke(0);
1353-
*
1354-
* // Draw the curve.
1355-
* beginShape();
1356-
* vertex(20, 20);
1357-
* quadraticVertex(x2, y2, 50, 50);
1358-
* endShape();
1359-
*
1360-
* // Draw red lines from the anchor points to the control point.
1361-
* stroke(255, 0, 0);
1362-
* line(20, 20, x2, y2);
1363-
* line(50, 50, x2, y2);
1364-
*
1365-
* // Draw the anchor points in black.
1366-
* strokeWeight(5);
1367-
* stroke(0);
1368-
* point(20, 20);
1369-
* point(50, 50);
1370-
*
1371-
* // Draw the control point in red.
1372-
* stroke(255, 0, 0);
1373-
* point(x2, y2);
1374-
* }
1375-
*
1376-
* // Start changing the first control point if the user clicks near it.
1377-
* function mousePressed() {
1378-
* if (dist(mouseX, mouseY, x2, y2) < 20) {
1379-
* isChanging = true;
1380-
* }
1381-
* }
1382-
*
1383-
* // Stop changing the first control point when the user releases the mouse.
1384-
* function mouseReleased() {
1385-
* isChanging = false;
1386-
* }
1387-
*
1388-
* // Update the first control point while the user drags the mouse.
1389-
* function mouseDragged() {
1390-
* if (isChanging === true) {
1391-
* x2 = mouseX;
1392-
* y2 = mouseY;
1393-
* }
1394-
* }
1395-
* </code>
1396-
* </div>
1397-
*
1398-
* <div>
1399-
* <code>
1400-
* function setup() {
1401-
* createCanvas(100, 100);
1402-
*
1403-
* background(200);
1404-
*
1405-
* // Start drawing the shape.
1406-
* beginShape();
1407-
*
1408-
* // Add the curved segments.
1409-
* vertex(20, 20);
1410-
* quadraticVertex(80, 20, 50, 50);
1411-
* quadraticVertex(20, 80, 80, 80);
1412-
*
1413-
* // Add the straight segments.
1414-
* vertex(80, 10);
1415-
* vertex(20, 10);
1416-
* vertex(20, 20);
1417-
*
1418-
* // Stop drawing the shape.
1419-
* endShape();
1420-
*
1421-
* describe('A white puzzle piece drawn on a gray background.');
1422-
* }
1423-
* </code>
1424-
* </div>
1425-
*
1426-
* <div>
1427-
* <code>
1428-
* // Click the and drag the mouse to view the scene from a different angle.
1429-
*
1430-
* function setup() {
1431-
* createCanvas(100, 100, WEBGL);
1432-
*
1433-
* describe('A white puzzle piece on a dark gray background. When the user clicks and drags the scene, the outline of a second puzzle piece is revealed.');
1434-
* }
1435-
*
1436-
* function draw() {
1437-
* background(50);
1438-
*
1439-
* // Enable orbiting with the mouse.
1440-
* orbitControl();
1441-
*
1442-
* // Style the first puzzle piece.
1443-
* noStroke();
1444-
* fill(255);
1445-
*
1446-
* // Draw the first puzzle piece.
1447-
* beginShape();
1448-
* vertex(-30, -30, 0);
1449-
* quadraticVertex(30, -30, 0, 0, 0, 0);
1450-
* quadraticVertex(-30, 30, 0, 30, 30, 0);
1451-
* vertex(30, -40, 0);
1452-
* vertex(-30, -40, 0);
1453-
* vertex(-30, -30, 0);
1454-
* endShape();
1455-
*
1456-
* // Style the second puzzle piece.
1457-
* stroke(255);
1458-
* noFill();
1459-
*
1460-
* // Draw the second puzzle piece.
1461-
* beginShape();
1462-
* vertex(-30, -30, -20);
1463-
* quadraticVertex(30, -30, -20, 0, 0, -20);
1464-
* quadraticVertex(-30, 30, -20, 30, 30, -20);
1465-
* vertex(30, -40, -20);
1466-
* vertex(-30, -40, -20);
1467-
* vertex(-30, -30, -20);
1468-
* endShape();
1469-
* }
1470-
* </code>
1471-
* </div>
1472-
*/
1473-
1474-
/**
1475-
* @method quadraticVertex
1476-
* @param {Number} cx
1477-
* @param {Number} cy
1478-
* @param {Number} cz z-coordinate of the control point.
1479-
* @param {Number} x3
1480-
* @param {Number} y3
1481-
* @param {Number} z3 z-coordinate of the anchor point.
1482-
*/
1483-
fn.quadraticVertex = function(...args) {
1484-
let x1, y1, z1, x2, y2, z2 = 0;
1485-
if (args.length === 4) {
1486-
[x1, y1, x2, y2] = args;
1487-
} else {
1488-
[x1, y1, z1, x2, y2, z2] = args;
1489-
}
1490-
// p5._validateParameters('quadraticVertex', args);
1491-
const prevOrder = this.bezierOrder();
1492-
this.bezierOrder(2);
1493-
this.bezierVertex(x1, y1, z1);
1494-
this.bezierVertex(x2, y2, z2);
1495-
this.bezierOrder(prevOrder);
1496-
return this;
1497-
};
1498-
14991229
/**
15001230
* Sets the normal vector for vertices in a custom 3D shape.
15011231
*

test/unit/core/vertex.js

-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ suite('Vertex', function() {
2626
});
2727
});
2828

29-
suite('p5.prototype.quadraticVertex', function() {
30-
test('should be a function', function() {
31-
assert.ok(myp5.quadraticVertex);
32-
assert.typeOf(myp5.quadraticVertex, 'function');
33-
});
34-
});
35-
3629
suite('p5.prototype.bezierVertex', function() {
3730
test('should be a function', function() {
3831
assert.ok(myp5.bezierVertex);

test/unit/visual/cases/shapes.js

+26-9
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,33 @@ visualSuite('Shape drawing', function() {
193193
visualTest('Drawing with cubic beziers', function(p5, screenshot) {
194194
setup(p5);
195195
p5.beginShape();
196-
p5.vertex(10, 10);
197-
p5.bezierVertex(10, 10, 15, 40, 40, 35);
198-
p5.bezierVertex(25, 15, 15, 25, 15, 25);
196+
p5.bezierVertex(10, 10);
197+
198+
p5.bezierVertex(10, 10);
199+
p5.bezierVertex(15, 40);
200+
p5.bezierVertex(40, 35);
201+
202+
p5.bezierVertex(25, 15)
203+
p5.bezierVertex(15, 25)
204+
p5.bezierVertex(15, 25);
199205
p5.endShape();
200206
screenshot();
201207
});
202208

203209
visualTest('Drawing with quadratic beziers', function(p5, screenshot) {
204210
setup(p5);
205211
p5.beginShape();
206-
p5.vertex(10, 10);
207-
p5.quadraticVertex(10, 10, 15, 40);
208-
p5.quadraticVertex(40, 35, 25, 15);
209-
p5.quadraticVertex(15, 25, 10, 10);
212+
p5.bezierOrder(2);
213+
p5.bezierVertex(10, 10);
214+
215+
p5.bezierVertex(10, 10);
216+
p5.bezierVertex(15, 40);
217+
218+
p5.bezierVertex(40, 35);
219+
p5.bezierVertex(25, 15);
220+
221+
p5.bezierVertex(15, 25);
222+
p5.bezierVertex(10, 10);
210223
p5.endShape();
211224
screenshot();
212225
});
@@ -367,7 +380,9 @@ visualSuite('Shape drawing', function() {
367380
p5.beginShape();
368381
p5.vertex(10, 10, 0);
369382
p5.vertex(10, 40, -150);
370-
p5.quadraticVertex(40, 40, 200, 40, 10, 150);
383+
p5.bezierOrder(2);
384+
p5.bezierVertex(40, 40, 200);
385+
p5.bezierVertex(40, 10, 150);
371386
p5.endShape(p5.CLOSE);
372387

373388
screenshot();
@@ -379,7 +394,9 @@ visualSuite('Shape drawing', function() {
379394
p5.beginShape();
380395
p5.vertex(10, 10, 0);
381396
p5.vertex(10, 40, -150);
382-
p5.bezierVertex(40, 40, 200, 40, 10, 150, 10, 10, 0);
397+
p5.bezierVertex(40, 40, 200);
398+
p5.bezierVertex(40, 10, 150);
399+
p5.bezierVertex(10, 10, 0);
383400
p5.endShape();
384401

385402
screenshot();

test/unit/webgl/p5.Geometry.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ suite('p5.Geometry', function() {
223223
myp5.cone();
224224

225225
myp5.beginShape();
226-
myp5.vertex(-20, -50);
227-
myp5.quadraticVertex(
228-
-40, -70,
229-
0, -60
230-
);
226+
myp5.bezierOrder(2);
227+
myp5.bezierVertex(-20, -50);
228+
229+
myp5.bezierVertex(-40, -70);
230+
myp5.bezierVertex(0, -60);
231231
myp5.endShape();
232232

233233
myp5.beginShape(myp5.TRIANGLE_STRIP);

0 commit comments

Comments
 (0)