diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index f2360b9..280f4de 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1054,8 +1054,21 @@ proc commandsToShapes( proc shapesToSegments(shapes: seq[Polygon]): seq[(Segment, int16)] = ## Converts the shapes into a set of filtered segments with winding value. - for shape in shapes: - for segment in shape.segments: + + # Quantize the segment to prevent leaks + template quantize(v: Vec2, q: float32): Vec2 = + vec2(v.x.quantize(q), v.y.quantize(q)) + + for poly in shapes: + var + vec1 = poly[^1].quantize(1 / 256) + vec2 = poly[0].quantize(1 / 256) + segment: Segment + for i in 0 ..< poly.len: + if i != 0: + vec2 = vec1 + vec1 = poly[i].quantize(1 / 256) + segment = segment(vec1, vec2) if segment.at.y == segment.to.y: # Skip horizontal continue var @@ -1065,12 +1078,6 @@ proc shapesToSegments(shapes: seq[Polygon]): seq[(Segment, int16)] = swap(segment.at, segment.to) winding = -1 - # Quantize the segment to prevent leaks - segment = segment( - vec2(segment.at.x.quantize(1 / 256), segment.at.y.quantize(1 / 256)), - vec2(segment.to.x.quantize(1 / 256), segment.to.y.quantize(1 / 256)) - ) - result.add((segment, winding)) proc transform(shapes: var seq[Polygon], transform: Mat3) =