Skip to content

Commit 291f70f

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 e76c040 commit 291f70f

2 files changed

Lines changed: 22 additions & 26 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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -695,31 +695,32 @@ visualSuite('WebGL', function() {
695695
});
696696

697697
visualSuite('Tessellation', function() {
698-
visualTest('Handles nearly identical consecutive vertices', function(p5, screenshot) {
699-
p5.createCanvas(100, 100, p5.WEBGL);
700-
p5.pixelDensity(1);
698+
visualTest('Handles nearly identical consecutive vertices from textToContours', async function(p5, screenshot) {
699+
p5.createCanvas(200, 200, p5.WEBGL);
701700
p5.background(255);
702701
p5.fill(0);
703702
p5.noStroke();
704703

705-
// Contours with nearly identical consecutive vertices (as can occur with textToContours)
706-
// Outer contour
707-
p5.beginShape();
708-
p5.vertex(-30, -30, 0);
709-
p5.vertex(30, -30, 0);
710-
p5.vertex(30, 30, 0);
711-
p5.vertex(-30, 30, 0);
712-
713-
// Inner contour (hole) with nearly identical vertices
714-
p5.beginContour();
715-
p5.vertex(-10, -10, 0);
716-
p5.vertex(-10, 10, 0);
717-
// This vertex has x coordinate almost equal to previous (10.00000001 vs 10)
718-
p5.vertex(10.00000001, 10, 0);
719-
p5.vertex(10, -10, 0);
720-
p5.endContour();
721-
722-
p5.endShape(p5.CLOSE);
704+
const font = await p5.loadFont('/unit/assets/Inconsolata-Bold.ttf');
705+
const contours = font.textToContours('p', 0, 0, 60);
706+
707+
if (contours && contours.length > 0) {
708+
p5.translate(-p5.width / 4, -p5.height / 4);
709+
p5.beginShape();
710+
for (let contourIdx = 0; contourIdx < contours.length; contourIdx++) {
711+
const contour = contours[contourIdx];
712+
if (contourIdx > 0) {
713+
p5.beginContour();
714+
}
715+
for (let i = 0; i < contour.length; i++) {
716+
p5.vertex(contour[i].x, contour[i].y, 0);
717+
}
718+
if (contourIdx > 0) {
719+
p5.endContour();
720+
}
721+
}
722+
p5.endShape(p5.CLOSE);
723+
}
723724

724725
screenshot();
725726
});

0 commit comments

Comments
 (0)