Skip to content

Commit c4a910c

Browse files
committed
fix(webgl): normalize nearly identical vertices before tessellation
- Remove Z-axis normalization (only X/Y needed based on testing) - Update visual test to use textToContours() example from issue #8186 - Test now reproduces the actual bug that gets fixed Resolves #8186
1 parent 52b93c7 commit c4a910c

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

src/webgl/ShapeBuilder.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,15 @@ export class ShapeBuilder {
322322
for (let i = stride; i < contour.length; i += stride) {
323323
const prevX = contour[i - stride];
324324
const prevY = contour[i - stride + 1];
325-
const prevZ = contour[i - stride + 2];
326325
const currX = contour[i];
327326
const currY = contour[i + 1];
328-
const currZ = contour[i + 2];
329327

330328
if (Math.abs(currX - prevX) < epsilon) {
331329
contour[i] = prevX;
332330
}
333331
if (Math.abs(currY - prevY) < epsilon) {
334332
contour[i + 1] = prevY;
335333
}
336-
if (Math.abs(currZ - prevZ) < epsilon) {
337-
contour[i + 2] = prevZ;
338-
}
339334
}
340335
}
341336

test/unit/visual/cases/webgl.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,29 +1244,32 @@ visualSuite('WebGL', function() {
12441244
});
12451245

12461246
visualSuite('Tessellation', function() {
1247-
visualTest('Handles nearly identical consecutive vertices', function(p5, screenshot) {
1248-
p5.createCanvas(100, 100, p5.WEBGL);
1249-
p5.pixelDensity(1);
1247+
visualTest('Handles nearly identical consecutive vertices from textToContours', async function(p5, screenshot) {
1248+
p5.createCanvas(200, 200, p5.WEBGL);
12501249
p5.background(255);
12511250
p5.fill(0);
12521251
p5.noStroke();
12531252

1254-
// Outer contour
1255-
p5.beginShape();
1256-
p5.vertex(-30, -30, 0);
1257-
p5.vertex(30, -30, 0);
1258-
p5.vertex(30, 30, 0);
1259-
p5.vertex(-30, 30, 0);
1260-
1261-
// Inner contour (hole)
1262-
p5.beginContour();
1263-
p5.vertex(-10, -10, 0);
1264-
p5.vertex(-10, 10, 0);
1265-
p5.vertex(10.00000001, 10, 0);
1266-
p5.vertex(10, -10, 0);
1267-
p5.endContour();
1268-
1269-
p5.endShape(p5.CLOSE);
1253+
const font = await p5.loadFont('/unit/assets/Inconsolata-Bold.ttf');
1254+
const contours = font.textToContours('p', 0, 0, 60);
1255+
1256+
if (contours && contours.length > 0) {
1257+
p5.translate(-p5.width / 4, -p5.height / 4);
1258+
p5.beginShape();
1259+
for (let contourIdx = 0; contourIdx < contours.length; contourIdx++) {
1260+
const contour = contours[contourIdx];
1261+
if (contourIdx > 0) {
1262+
p5.beginContour();
1263+
}
1264+
for (let i = 0; i < contour.length; i++) {
1265+
p5.vertex(contour[i].x, contour[i].y, 0);
1266+
}
1267+
if (contourIdx > 0) {
1268+
p5.endContour();
1269+
}
1270+
}
1271+
p5.endShape(p5.CLOSE);
1272+
}
12701273

12711274
screenshot();
12721275
});

0 commit comments

Comments
 (0)