Use Polygon.
This commit is contained in:
parent
df531a4e19
commit
20af3accd1
2 changed files with 19 additions and 19 deletions
|
@ -11,7 +11,7 @@ requires "chroma >= 0.2.5"
|
||||||
requires "zippy >= 0.9.7"
|
requires "zippy >= 0.9.7"
|
||||||
requires "flatty >= 0.2.4"
|
requires "flatty >= 0.2.4"
|
||||||
requires "nimsimd >= 1.0.0"
|
requires "nimsimd >= 1.0.0"
|
||||||
requires "bumpy >= 1.0.3"
|
requires "bumpy >= 1.1.0"
|
||||||
|
|
||||||
task bindings, "Generate bindings":
|
task bindings, "Generate bindings":
|
||||||
|
|
||||||
|
|
|
@ -650,11 +650,11 @@ proc polygon*(
|
||||||
|
|
||||||
proc commandsToShapes(
|
proc commandsToShapes(
|
||||||
path: Path, closeSubpaths: bool, pixelScale: float32
|
path: Path, closeSubpaths: bool, pixelScale: float32
|
||||||
): seq[seq[Vec2]] =
|
): seq[Polygon] =
|
||||||
## Converts SVG-like commands to sequences of vectors.
|
## Converts SVG-like commands to sequences of vectors.
|
||||||
var
|
var
|
||||||
start, at: Vec2
|
start, at: Vec2
|
||||||
shape: seq[Vec2]
|
shape: Polygon
|
||||||
|
|
||||||
# Some commands use data from the previous command
|
# Some commands use data from the previous command
|
||||||
var
|
var
|
||||||
|
@ -663,7 +663,7 @@ proc commandsToShapes(
|
||||||
|
|
||||||
let errorMarginSq = pow(pixelErrorMargin / pixelScale, 2)
|
let errorMarginSq = pow(pixelErrorMargin / pixelScale, 2)
|
||||||
|
|
||||||
proc addSegment(shape: var seq[Vec2], at, to: Vec2) =
|
proc addSegment(shape: var Polygon, at, to: Vec2) =
|
||||||
# Don't add any 0 length lines
|
# Don't add any 0 length lines
|
||||||
if at - to != vec2(0, 0):
|
if at - to != vec2(0, 0):
|
||||||
# Don't double up points
|
# Don't double up points
|
||||||
|
@ -671,7 +671,7 @@ proc commandsToShapes(
|
||||||
shape.add(at)
|
shape.add(at)
|
||||||
shape.add(to)
|
shape.add(to)
|
||||||
|
|
||||||
proc addCubic(shape: var seq[Vec2], at, ctrl1, ctrl2, to: Vec2) =
|
proc addCubic(shape: var Polygon, at, ctrl1, ctrl2, to: Vec2) =
|
||||||
## Adds cubic segments to shape.
|
## Adds cubic segments to shape.
|
||||||
proc compute(at, ctrl1, ctrl2, to: Vec2, t: float32): Vec2 {.inline.} =
|
proc compute(at, ctrl1, ctrl2, to: Vec2, t: float32): Vec2 {.inline.} =
|
||||||
pow(1 - t, 3) * at +
|
pow(1 - t, 3) * at +
|
||||||
|
@ -705,7 +705,7 @@ proc commandsToShapes(
|
||||||
next = compute(at, ctrl1, ctrl2, to, t + step)
|
next = compute(at, ctrl1, ctrl2, to, t + step)
|
||||||
halfway = compute(at, ctrl1, ctrl2, to, t + step / 2)
|
halfway = compute(at, ctrl1, ctrl2, to, t + step / 2)
|
||||||
|
|
||||||
proc addQuadratic(shape: var seq[Vec2], at, ctrl, to: Vec2) =
|
proc addQuadratic(shape: var Polygon, at, ctrl, to: Vec2) =
|
||||||
## Adds quadratic segments to shape.
|
## Adds quadratic segments to shape.
|
||||||
proc compute(at, ctrl, to: Vec2, t: float32): Vec2 {.inline.} =
|
proc compute(at, ctrl, to: Vec2, t: float32): Vec2 {.inline.} =
|
||||||
pow(1 - t, 2) * at +
|
pow(1 - t, 2) * at +
|
||||||
|
@ -744,7 +744,7 @@ proc commandsToShapes(
|
||||||
halfway = compute(at, ctrl, to, t + step / 2)
|
halfway = compute(at, ctrl, to, t + step / 2)
|
||||||
|
|
||||||
proc addArc(
|
proc addArc(
|
||||||
shape: var seq[Vec2],
|
shape: var Polygon,
|
||||||
at, radii: Vec2,
|
at, radii: Vec2,
|
||||||
rotation: float32,
|
rotation: float32,
|
||||||
large, sweep: bool,
|
large, sweep: bool,
|
||||||
|
@ -1036,7 +1036,7 @@ proc commandsToShapes(
|
||||||
shape.addSegment(at, start)
|
shape.addSegment(at, start)
|
||||||
result.add(shape)
|
result.add(shape)
|
||||||
|
|
||||||
proc shapesToSegments(shapes: seq[seq[Vec2]]): seq[(Segment, int16)] =
|
proc shapesToSegments(shapes: seq[Polygon]): seq[(Segment, int16)] =
|
||||||
## Converts the shapes into a set of filtered segments with winding value.
|
## Converts the shapes into a set of filtered segments with winding value.
|
||||||
for shape in shapes:
|
for shape in shapes:
|
||||||
for segment in shape.segments:
|
for segment in shape.segments:
|
||||||
|
@ -1051,7 +1051,7 @@ proc shapesToSegments(shapes: seq[seq[Vec2]]): seq[(Segment, int16)] =
|
||||||
|
|
||||||
result.add((segment, winding))
|
result.add((segment, winding))
|
||||||
|
|
||||||
proc transform(shapes: var seq[seq[Vec2]], transform: Mat3) =
|
proc transform(shapes: var seq[Polygon], transform: Mat3) =
|
||||||
if transform != mat3():
|
if transform != mat3():
|
||||||
for shape in shapes.mitems:
|
for shape in shapes.mitems:
|
||||||
for vec in shape.mitems:
|
for vec in shape.mitems:
|
||||||
|
@ -1599,7 +1599,7 @@ proc fillHits(
|
||||||
|
|
||||||
proc fillShapes(
|
proc fillShapes(
|
||||||
image: Image,
|
image: Image,
|
||||||
shapes: seq[seq[Vec2]],
|
shapes: seq[Polygon],
|
||||||
color: SomeColor,
|
color: SomeColor,
|
||||||
windingRule: WindingRule,
|
windingRule: WindingRule,
|
||||||
blendMode: BlendMode
|
blendMode: BlendMode
|
||||||
|
@ -1670,7 +1670,7 @@ proc fillShapes(
|
||||||
|
|
||||||
proc fillShapes(
|
proc fillShapes(
|
||||||
mask: Mask,
|
mask: Mask,
|
||||||
shapes: seq[seq[Vec2]],
|
shapes: seq[Polygon],
|
||||||
windingRule: WindingRule,
|
windingRule: WindingRule,
|
||||||
blendMode: BlendMode
|
blendMode: BlendMode
|
||||||
) =
|
) =
|
||||||
|
@ -1732,14 +1732,14 @@ proc angleToMiterLimit*(angle: float32): float32 {.inline.} =
|
||||||
1 / sin(angle / 2)
|
1 / sin(angle / 2)
|
||||||
|
|
||||||
proc strokeShapes(
|
proc strokeShapes(
|
||||||
shapes: seq[seq[Vec2]],
|
shapes: seq[Polygon],
|
||||||
strokeWidth: float32,
|
strokeWidth: float32,
|
||||||
lineCap: LineCap,
|
lineCap: LineCap,
|
||||||
lineJoin: LineJoin,
|
lineJoin: LineJoin,
|
||||||
miterLimit: float32,
|
miterLimit: float32,
|
||||||
dashes: seq[float32],
|
dashes: seq[float32],
|
||||||
pixelScale: float32
|
pixelScale: float32
|
||||||
): seq[seq[Vec2]] =
|
): seq[Polygon] =
|
||||||
if strokeWidth <= 0:
|
if strokeWidth <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1747,12 +1747,12 @@ proc strokeShapes(
|
||||||
halfStroke = strokeWidth / 2
|
halfStroke = strokeWidth / 2
|
||||||
miterAngleLimit = miterLimitToAngle(miterLimit)
|
miterAngleLimit = miterLimitToAngle(miterLimit)
|
||||||
|
|
||||||
proc makeCircle(at: Vec2): seq[Vec2] =
|
proc makeCircle(at: Vec2): Polygon =
|
||||||
let path = newPath()
|
let path = newPath()
|
||||||
path.ellipse(at, halfStroke, halfStroke)
|
path.ellipse(at, halfStroke, halfStroke)
|
||||||
path.commandsToShapes(true, pixelScale)[0]
|
path.commandsToShapes(true, pixelScale)[0]
|
||||||
|
|
||||||
proc makeRect(at, to: Vec2): seq[Vec2] =
|
proc makeRect(at, to: Vec2): Polygon =
|
||||||
# Rectangle corners
|
# Rectangle corners
|
||||||
let
|
let
|
||||||
tangent = (to - at).normalize()
|
tangent = (to - at).normalize()
|
||||||
|
@ -1776,7 +1776,7 @@ proc strokeShapes(
|
||||||
|
|
||||||
@[a, b, c, d, a]
|
@[a, b, c, d, a]
|
||||||
|
|
||||||
proc addJoin(shape: var seq[seq[Vec2]], prevPos, pos, nextPos: Vec2) =
|
proc addJoin(shape: var seq[Polygon], prevPos, pos, nextPos: Vec2) =
|
||||||
let minArea = pixelErrorMargin / pixelScale
|
let minArea = pixelErrorMargin / pixelScale
|
||||||
|
|
||||||
if lineJoin == RoundJoin:
|
if lineJoin == RoundJoin:
|
||||||
|
@ -1825,7 +1825,7 @@ proc strokeShapes(
|
||||||
discard # Handled above, skipping angle calculation
|
discard # Handled above, skipping angle calculation
|
||||||
|
|
||||||
for shape in shapes:
|
for shape in shapes:
|
||||||
var shapeStroke: seq[seq[Vec2]]
|
var shapeStroke: seq[Polygon]
|
||||||
|
|
||||||
if shape[0] != shape[^1]:
|
if shape[0] != shape[^1]:
|
||||||
# This shape does not end at the same point it starts so draw the
|
# This shape does not end at the same point it starts so draw the
|
||||||
|
@ -1895,7 +1895,7 @@ proc strokeShapes(
|
||||||
|
|
||||||
proc parseSomePath(
|
proc parseSomePath(
|
||||||
path: SomePath, closeSubpaths: bool, pixelScale: float32
|
path: SomePath, closeSubpaths: bool, pixelScale: float32
|
||||||
): seq[seq[Vec2]] {.inline.} =
|
): seq[Polygon] {.inline.} =
|
||||||
## Given SomePath, parse it in different ways.
|
## Given SomePath, parse it in different ways.
|
||||||
when type(path) is string:
|
when type(path) is string:
|
||||||
parsePath(path).commandsToShapes(closeSubpaths, pixelScale)
|
parsePath(path).commandsToShapes(closeSubpaths, pixelScale)
|
||||||
|
@ -2058,7 +2058,7 @@ proc strokePath*(
|
||||||
image.draw(fill, blendMode = paint.blendMode)
|
image.draw(fill, blendMode = paint.blendMode)
|
||||||
|
|
||||||
proc overlaps(
|
proc overlaps(
|
||||||
shapes: seq[seq[Vec2]],
|
shapes: seq[Polygon],
|
||||||
test: Vec2,
|
test: Vec2,
|
||||||
windingRule: WindingRule
|
windingRule: WindingRule
|
||||||
): bool =
|
): bool =
|
||||||
|
|
Loading…
Reference in a new issue