Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/shape/custom_shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,17 @@ function customShapes(p5, fn) {
* @returns {Number} The current Bézier order.
*/
fn.bezierOrder = function (order) {
if (
!p5.disableFriendlyErrors &&
order !== undefined &&
order !== 2 &&
order !== 3
) {
p5._friendlyError(
`bezierOrder() expects an order of 2 or 3, but received ${order}.`,
'bezierOrder'
);
}
return this._renderer.bezierOrder(order);
};

Expand Down
32 changes: 32 additions & 0 deletions test/unit/core/vertex.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@ suite('Vertex', function () {
});
});

suite('p5.prototype.bezierOrder', function () {
test('should be a function', function () {
assert.ok(myp5.bezierOrder);
assert.typeOf(myp5.bezierOrder,'function');
});

test('should warn when the order is not 2 or 3', function () {
const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError');
myp5.bezierOrder(4);
expect(_friendlyErrorStub).toHaveBeenCalledTimes(1);
});

test('should not warn for an order of 2', function () {
const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError');
myp5.bezierOrder(2);
expect(_friendlyErrorStub).not.toHaveBeenCalled();
});

test('should not warn for an order of 3', function () {
const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError');
myp5.bezierOrder(3);
expect(_friendlyErrorStub).not.toHaveBeenCalled();
});

test('should not warn when reading the current order', function () {
const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError');
myp5.bezierOrder();
expect(_friendlyErrorStub).not.toHaveBeenCalled();
});

});

suite('p5.prototype.splineVertex', function () {
test('should be a function', function () {
assert.ok(myp5.splineVertex);
Expand Down