Skip to content

Commit

Permalink
Fix more tests referring to TESS
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Dec 14, 2024
1 parent 999339e commit 1cb1fde
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 47 deletions.
17 changes: 8 additions & 9 deletions src/shape/vertex.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ function vertex(p5, fn){
* vertices to a custom shape and <a href="#/p5/endShape">endShape()</a> stops
* adding them.
*
* The parameter, `kind`, sets the kind of shape to make. By default, any
* irregular polygon can be drawn. The available modes for kind are:
* The parameter, `kind`, sets the kind of shape to make. The available kinds are:
*
* - `PATH` (the default) to draw shapes by tracing out the path along their edges.
* - `POINTS` to draw a series of points.
* - `LINES` to draw a series of unconnected line segments.
* - `TRIANGLES` to draw a series of separate triangles.
* - `TRIANGLE_FAN` to draw a series of connected triangles sharing the first vertex in a fan-like fashion.
* - `TRIANGLE_STRIP` to draw a series of connected triangles in strip fashion.
* - `QUADS` to draw a series of separate quadrilaterals (quads).
* - `QUAD_STRIP` to draw quad strip using adjacent edges to form the next quad.
* - `TESS` to create a filling curve by explicit tessellation (WebGL only).
*
* After calling `beginShape()`, shapes can be built by calling
* <a href="#/p5/vertex">vertex()</a>,
* <a href="#/p5/bezierVertex">bezierVertex()</a>,
* <a href="#/p5/quadraticVertex">quadraticVertex()</a>, and/or
* <a href="#/p5/curveVertex">splineVertex()</a>. Calling
* <a href="#/p5/bezierVertex">bezierVertex()</a>, and/or
* <a href="#/p5/splineVertex">splineVertex()</a>. Calling
* <a href="#/p5/endShape">endShape()</a> will stop adding vertices to the
* shape. Each shape will be outlined with the current stroke color and filled
* with the current fill color.
Expand All @@ -47,8 +46,8 @@ function vertex(p5, fn){
* <a href="#/p5/endShape">endShape()</a>.
*
* @method beginShape
* @param {(POINTS|LINES|TRIANGLES|TRIANGLE_FAN|TRIANGLE_STRIP|QUADS|QUAD_STRIP|TESS)} [kind] either POINTS, LINES, TRIANGLES, TRIANGLE_FAN
* TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS.
* @param {(POINTS|LINES|TRIANGLES|TRIANGLE_FAN|TRIANGLE_STRIP|QUADS|QUAD_STRIP|PATH)} [kind=PATH] either POINTS, LINES, TRIANGLES, TRIANGLE_FAN
* TRIANGLE_STRIP, QUADS, QUAD_STRIP or PATH. Defaults to PATH.
* @chainable
*
* @example
Expand Down Expand Up @@ -334,7 +333,7 @@ function vertex(p5, fn){
*
* // Start drawing the shape.
* // Draw a series of quadrilaterals.
* beginShape(TESS);
* beginShape(PATH);
*
* // Add the vertices.
* vertex(-30, -30, 0);
Expand Down Expand Up @@ -373,7 +372,7 @@ function vertex(p5, fn){
*
* // Start drawing the shape.
* // Draw a series of quadrilaterals.
* beginShape(TESS);
* beginShape(PATH);
*
* // Add the vertices.
* fill('red');
Expand Down
4 changes: 2 additions & 2 deletions src/webgl/ShapeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const INITIAL_VERTEX_SIZE =
export class ShapeBuilder {
constructor(renderer) {
this.renderer = renderer;
this.shapeMode = constants.TESS;
this.shapeMode = constants.PATH;
this.geometry = new Geometry(undefined, undefined, undefined, this.renderer);
this.geometry.gid = '__IMMEDIATE_MODE_GEOMETRY__';

Expand Down Expand Up @@ -253,7 +253,7 @@ export class ShapeBuilder {
* @private
*/
_tesselateShape() {
// TODO: handle non-TESS shape modes that have contours
// TODO: handle non-PATH shape modes that have contours
this.shapeMode = constants.TRIANGLES;
// const contours = [[]];
const contours = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function drawStrip(mode) {
}

function ngon(n, x, y, d) {
beginShape(TESS);
beginShape(PATH);
for (let i = 0; i < n + 1; i++) {
angle = TWO_PI / n * i;
px = x + sin(angle) * d / 2;
Expand Down
13 changes: 1 addition & 12 deletions test/unit/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,7 @@ suite('Structure', function() {

suite('p5.prototype.push and p5.prototype.pop', function() {
function getRenderState() {
var state = {};
for (var key in myp5._renderer) {
var value = myp5._renderer[key];
if (
typeof value !== 'function' &&
key !== '_cachedFillStyle' &&
key !== '_cachedStrokeStyle'
) {
state[key] = value;
}
}
return state;
return { ...myp5._renderer.states };
}

function assertCanPreserveRenderState(work) {
Expand Down
12 changes: 1 addition & 11 deletions test/unit/visual/cases/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@ visualSuite('Shape drawing', function() {
p5.splineVertex(15, 40);
p5.splineVertex(40, 35);
p5.endShape();

p5.strokeWeight(10);
p5.stroke('red')
p5.beginShape(p5.POINTS)
p5.vertex(10, 10);
p5.vertex(15, 40);
p5.vertex(40, 35);
p5.vertex(25, 15);
p5.vertex(15, 25);
p5.endShape();
screenshot();
});

Expand Down Expand Up @@ -211,8 +201,8 @@ visualSuite('Shape drawing', function() {
p5.vertex(15, 40);
p5.vertex(40, 35);
p5.vertex(25, 15);
p5.vertex(15, 25);
p5.vertex(10, 10);
p5.vertex(15, 25);
p5.endShape();
screenshot();
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ visualSuite('WebGL', function() {
outColor = vec4(vCol, 1.0);
}`;
visualTest(
'on TESS shape mode', function(p5, screenshot) {
'on PATH shape mode', function(p5, screenshot) {
p5.createCanvas(50, 50, p5.WEBGL);
p5.background('white');
const myShader = p5.createShader(vertSrc, fragSrc);
p5.shader(myShader);
p5.beginShape(p5.TESS);
p5.beginShape(p5.PATH);
p5.noStroke();
for (let i = 0; i < 20; i++){
let x = 20 * p5.sin(i/20*p5.TWO_PI);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
20 changes: 10 additions & 10 deletions test/unit/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,11 +1641,11 @@ suite('p5.RendererGL', function() {
assert.equal(renderer.shapeBuilder.geometry.edges.length, 7);
});

test('TESS preserves vertex data', function() {
test('PATH preserves vertex data', function() {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);

myp5.textureMode(myp5.NORMAL);
myp5.beginShape(myp5.TESS);
myp5.beginShape(myp5.PATH);
myp5.fill(255, 255, 255);
myp5.normal(-1, -1, 1);
myp5.vertexProperty('aCustom', [1, 1, 1])
Expand Down Expand Up @@ -1744,11 +1744,11 @@ suite('p5.RendererGL', function() {
]);
});

test('TESS does not affect stroke colors', function() {
test('PATH does not affect stroke colors', function() {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);

myp5.textureMode(myp5.NORMAL);
myp5.beginShape(myp5.TESS);
myp5.beginShape(myp5.PATH);
myp5.noFill();
myp5.stroke(255, 255, 255);
myp5.vertex(-10, -10, 0, 0);
Expand All @@ -1769,13 +1769,13 @@ suite('p5.RendererGL', function() {
]);
});

test('TESS does not affect texture coordinates', function() {
test('PATH does not affect texture coordinates', function() {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);
const texture = new p5.Image(25, 25);

myp5.textureMode(myp5.IMAGE);
myp5.texture(texture);
myp5.beginShape(myp5.TESS);
myp5.beginShape(myp5.PATH);
myp5.noFill();
myp5.vertex(-10, -10, 0, 0);
myp5.vertex(10, -10, 25, 0);
Expand All @@ -1792,7 +1792,7 @@ suite('p5.RendererGL', function() {
]);
});

test('TESS interpolates vertex data at intersections', function() {
test('PATH interpolates vertex data at intersections', function() {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);

// Hourglass shape:
Expand All @@ -1806,7 +1806,7 @@ suite('p5.RendererGL', function() {
//
// Tessy will add a vertex in the middle
myp5.textureMode(myp5.NORMAL);
myp5.beginShape(myp5.TESS);
myp5.beginShape(myp5.PATH);
myp5.fill(255, 255, 255);
myp5.normal(-1, -1, 1);
myp5.vertex(-10, -10, 0, 0);
Expand Down Expand Up @@ -1892,11 +1892,11 @@ suite('p5.RendererGL', function() {
]);
});

test('TESS handles vertex data perpendicular to the camera', function() {
test('PATH handles vertex data perpendicular to the camera', function() {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);

myp5.textureMode(myp5.NORMAL);
myp5.beginShape(myp5.TESS);
myp5.beginShape(myp5.PATH);
myp5.vertex(-10, 0, -10);
myp5.vertex(10, 0, -10);
myp5.vertex(10, 0, 10);
Expand Down

0 comments on commit 1cb1fde

Please sign in to comment.