Skip to content

Commit 0b5f5a0

Browse files
authored
Merge pull request #7528 from processing/splineProperties
Add splineProperties
2 parents d17c3ee + 35d1006 commit 0b5f5a0

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/core/p5.Renderer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ class Renderer {
170170
this.updateShapeProperties();
171171
}
172172

173+
splineProperties(values) {
174+
if (values) {
175+
for (const key in values) {
176+
this.splineProperty(key, values[key]);
177+
}
178+
} else {
179+
return { ...this.states.splineProperties };
180+
}
181+
}
182+
173183
splineVertex(x, y, z = 0, u = 0, v = 0) {
174184
const position = new Vector(x, y, z);
175185
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates

src/shape/custom_shapes.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,16 @@ class Shape {
836836
this._splineProperties[key] = value;
837837
}
838838

839+
splineProperties(values) {
840+
if (values) {
841+
for (const key in values) {
842+
this.splineProperty(key, values[key]);
843+
}
844+
} else {
845+
return this._splineProperties;
846+
}
847+
}
848+
839849
/*
840850
To-do: Maybe refactor #createVertex() since this has side effects that aren't advertised
841851
in the method name?
@@ -1597,12 +1607,20 @@ function customShapes(p5, fn) {
15971607
/**
15981608
* TODO: documentation
15991609
* @param {String} key
1600-
* @param value
1610+
* @param [value]
16011611
*/
16021612
fn.splineProperty = function(key, value) {
16031613
return this._renderer.splineProperty(key, value);
16041614
};
16051615

1616+
/**
1617+
* TODO: documentation
1618+
* @param {Object} [values]
1619+
*/
1620+
fn.splineProperties = function(values) {
1621+
return this._renderer.splineProperties(values);
1622+
};
1623+
16061624
/**
16071625
* Adds a vertex to a custom shape.
16081626
*

test/unit/core/rendering.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import p5 from '../../../src/app.js';
2-
import { vi } from 'vitest';
2+
import { vi, expect } from 'vitest';
33

44
suite('Rendering', function() {
55
var myp5;
@@ -185,7 +185,7 @@ suite('Rendering', function() {
185185
try {
186186
expect(function() {
187187
myp5[webglMethod].call(myp5);
188-
}).to.throw(Error, /is only supported in WEBGL mode/);
188+
}).toThrow(Error, /is only supported in WEBGL mode/);
189189
} finally {
190190
myp5.validateParameters = validateParamters;
191191
}
@@ -194,4 +194,18 @@ suite('Rendering', function() {
194194
);
195195
}
196196
});
197+
198+
suite('spline functions', function() {
199+
test('setting via splineProperty()', function() {
200+
myp5.splineProperty('tightness', 2);
201+
expect(myp5.splineProperty('tightness')).toEqual(2);
202+
expect(myp5.splineProperties()).toMatchObject({ tightness: 2 });
203+
});
204+
205+
test('setting via splineProperties()', function() {
206+
myp5.splineProperties({ tightness: 2 });
207+
expect(myp5.splineProperty('tightness')).toEqual(2);
208+
expect(myp5.splineProperties()).toMatchObject({ tightness: 2 });
209+
});
210+
});
197211
});

0 commit comments

Comments
 (0)