This commit is contained in:
treeform 2022-06-30 10:59:38 -07:00
parent dffad18641
commit ba5681e452

View file

@ -1056,19 +1056,21 @@ proc shapesToSegments(shapes: seq[Polygon]): seq[(Segment, int16)] =
## Converts the shapes into a set of filtered segments with winding value.
# Quantize the segment to prevent leaks
template quantize(v: Vec2, q: float32): Vec2 =
vec2(v.x.quantize(q), v.y.quantize(q))
template quantizeY(v: Vec2): Vec2 =
vec2(v.x, v.y.quantize(1 / 256))
for poly in shapes:
var
vec1 = poly[^1].quantize(1 / 256)
vec2 = poly[0].quantize(1 / 256)
vec1 = poly[^1].quantizeY()
vec2: Vec2
segment: Segment
for i in 0 ..< poly.len:
if i != 0:
vec2 = vec1
vec1 = poly[i].quantize(1 / 256)
vec2 = poly[i].quantizeY()
if i == 0 and vec1 == vec2:
continue
segment = segment(vec1, vec2)
vec1 = vec2
if segment.at.y == segment.to.y: # Skip horizontal
continue
var