fixing tesselation

This commit is contained in:
Val Erastov 2023-03-12 16:15:17 -07:00
parent 8d27ea74dc
commit 10295d0e92
2 changed files with 9 additions and 5 deletions

View file

@ -19,8 +19,12 @@ export function curveTessParams(curve, min, max, tessTol, scale) {
splits.push(max); splits.push(max);
function refine(u1, u2, step) { function refine(u1, u2, step) {
if (step < u2 - u1) { const uDist = u2 - u1;
const mid = u1 + (u2 - u1) * 0.5; if (uDist < 1e-3) {
return
}
if (step < uDist) {
const mid = u1 + uDist * 0.5;
refine(u1, mid, step); refine(u1, mid, step);
out.push(mid); out.push(mid);
refine(mid, u2, curveStep(curve, mid, tessTol, scale)); refine(mid, u2, curveStep(curve, mid, tessTol, scale));

View file

@ -457,10 +457,10 @@ export class Contour {
return cc; return cc;
} }
tessellate(resolution) { tessellate() {
const tessellation = []; const tessellation = [];
for (const segment of this.segments) { for (const segment of this.segments) {
const segmentTessellation = segment.tessellate(resolution); const segmentTessellation = segment.tessellate(segment.massiveness() * 0.1);
//skip last one because it's guaranteed to be closed //skip last one because it's guaranteed to be closed
for (let i = 0; i < segmentTessellation.length - 1; ++i) { for (let i = 0; i < segmentTessellation.length - 1; ++i) {
tessellation.push(segmentTessellation[i]); tessellation.push(segmentTessellation[i]);
@ -470,7 +470,7 @@ export class Contour {
} }
isCCW() { isCCW() {
return isCCW(this.tessellate(10)); return isCCW(this.tessellate());
} }
reverse() { reverse() {