diff --git a/docs/pixie.html b/docs/pixie.html
index 4d686ef..b33b4df 100644
--- a/docs/pixie.html
+++ b/docs/pixie.html
@@ -310,7 +310,7 @@ Writes an image to a file.
proc fillRect(image: Image; rect: Rect; color: ColorRGBA) {...}{.raises: [], tags: [].}
-
+Fill a rectangle.
@@ -318,7 +318,7 @@ Writes an image to a file.
tags: [RootEffect].}
-
+Fill a rectangle.
@@ -326,7 +326,7 @@ Writes an image to a file.
raises: [], tags: [].}
-
+Stroke a rounded rectangle.
@@ -334,7 +334,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Stroke a rounded rectangle.
@@ -342,7 +342,7 @@ Writes an image to a file.
color: ColorRGBA) {...}{.raises: [], tags: [].}
-
+Fill a rounded rectangle.
@@ -350,7 +350,7 @@ Writes an image to a file.
raises: [], tags: [].}
-
+Fill a rounded rectangle.
@@ -358,7 +358,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Fill a rounded rectangle.
@@ -366,7 +366,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Fill a rounded rectangle.
@@ -375,7 +375,7 @@ Writes an image to a file.
tags: [].}
-
+Stroke a rounded rectangle.
@@ -384,7 +384,7 @@ Writes an image to a file.
tags: [].}
-
+Stroke a rounded rectangle.
@@ -393,7 +393,7 @@ Writes an image to a file.
tags: [RootEffect].}
-
+Stroke a rounded rectangle.
@@ -402,7 +402,7 @@ Writes an image to a file.
tags: [RootEffect].}
-
+Stroke a rounded rectangle.
@@ -410,7 +410,7 @@ Writes an image to a file.
strokeWidth = 1.0) {...}{.raises: [], tags: [].}
-
+Stroke a segment (draws a line from segment.at to segment.to).
@@ -418,7 +418,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Stroke a segment (draws a line from segment.at to segment.to).
@@ -426,7 +426,7 @@ Writes an image to a file.
blendMode = bmNormal) {...}{.raises: [], tags: [].}
-
+Fill an ellipse.
@@ -434,7 +434,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Fill an ellipse.
@@ -442,7 +442,7 @@ Writes an image to a file.
color: ColorRGBA; strokeWidth = 1.0) {...}{.raises: [], tags: [].}
-
+Stroke an ellipse.
@@ -450,7 +450,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Stroke an ellipse.
@@ -458,7 +458,7 @@ Writes an image to a file.
raises: [], tags: [].}
-
+Fills a circle.
@@ -466,7 +466,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Fills a circle.
@@ -474,7 +474,7 @@ Writes an image to a file.
strokeWidth = 1.0) {...}{.raises: [], tags: [].}
-
+Strokes a circle.
@@ -482,7 +482,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Strokes a circle.
@@ -490,7 +490,7 @@ Writes an image to a file.
color: ColorRGBA) {...}{.raises: [], tags: [].}
-
+Fills a polygon.
@@ -498,7 +498,7 @@ Writes an image to a file.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Fills a polygon.
@@ -506,7 +506,7 @@ Writes an image to a file.
color: ColorRGBA; strokeWidth = 1.0) {...}{.raises: [], tags: [].}
-
+Strokes a polygon.
@@ -515,7 +515,7 @@ Writes an image to a file.
tags: [RootEffect].}
-
+Strokes a polygon.
@@ -533,7 +533,7 @@ Writes an image to a file.
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:05 UTC
diff --git a/docs/pixie/blends.html b/docs/pixie/blends.html
index f12bee3..b6ba9fd 100644
--- a/docs/pixie/blends.html
+++ b/docs/pixie/blends.html
@@ -310,7 +310,7 @@ Unpack the first 32 bits into 4 rgba(0, 0, 0, value)
- Made with Nim. Generated: 2021-02-25 14:22:56 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:03 UTC
diff --git a/docs/pixie/common.html b/docs/pixie/common.html
index 13f573f..c3c7bbf 100644
--- a/docs/pixie/common.html
+++ b/docs/pixie/common.html
@@ -228,7 +228,7 @@ Converts a color from premultiplied alpha to straight alpha.
- Made with Nim. Generated: 2021-02-25 14:22:55 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:03 UTC
diff --git a/docs/pixie/fileformats/bmp.html b/docs/pixie/fileformats/bmp.html
index d42b4b4..c036c8d 100644
--- a/docs/pixie/fileformats/bmp.html
+++ b/docs/pixie/fileformats/bmp.html
@@ -185,7 +185,7 @@ Encodes an image into the BMP file format.
- Made with Nim. Generated: 2021-02-25 14:22:56 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:04 UTC
diff --git a/docs/pixie/fileformats/jpg.html b/docs/pixie/fileformats/jpg.html
index 36a011d..4be6cfb 100644
--- a/docs/pixie/fileformats/jpg.html
+++ b/docs/pixie/fileformats/jpg.html
@@ -185,7 +185,7 @@ Decodes the JPEG into an Image.
- Made with Nim. Generated: 2021-02-25 14:22:56 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:04 UTC
diff --git a/docs/pixie/fileformats/png.html b/docs/pixie/fileformats/png.html
index e4174f9..7484c30 100644
--- a/docs/pixie/fileformats/png.html
+++ b/docs/pixie/fileformats/png.html
@@ -204,7 +204,7 @@ Encodes the mask data into the PNG file format.
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:04 UTC
diff --git a/docs/pixie/fileformats/svg.html b/docs/pixie/fileformats/svg.html
index ec7bb42..d7abdf0 100644
--- a/docs/pixie/fileformats/svg.html
+++ b/docs/pixie/fileformats/svg.html
@@ -174,7 +174,7 @@ Render SVG file and return the image.
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:05 UTC
diff --git a/docs/pixie/images.html b/docs/pixie/images.html
index e72e1d1..7bf11b8 100644
--- a/docs/pixie/images.html
+++ b/docs/pixie/images.html
@@ -559,7 +559,7 @@ Draws one image onto another using matrix with color blending.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Resize an image to a given hight and width.
@@ -579,7 +579,7 @@ Shifts the target by offset.
- Made with Nim. Generated: 2021-02-25 14:22:56 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:04 UTC
diff --git a/docs/pixie/masks.html b/docs/pixie/masks.html
index c0dbbcf..57ec4b5 100644
--- a/docs/pixie/masks.html
+++ b/docs/pixie/masks.html
@@ -330,7 +330,7 @@ Fills the mask with the parameter value.
proc getValueSmooth(mask: Mask; x, y: float32): uint8 {...}{.raises: [], tags: [].}
-
+Gets a interpolated value with float point coordinates.
@@ -357,7 +357,7 @@ A value of 0 stays 0. Anything else turns into 255.
- Made with Nim. Generated: 2021-02-25 14:22:56 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:04 UTC
diff --git a/docs/pixie/paints.html b/docs/pixie/paints.html
index bfa69c1..e0fcc6e 100644
--- a/docs/pixie/paints.html
+++ b/docs/pixie/paints.html
@@ -108,17 +108,23 @@ window.addEventListener('DOMContentLoaded', main);
pkGradientAngular">PaintKind
Paint
+ case kind*: PaintKind
+ of pkSolid:
+ color*: ColorRGBA ## Color to fill with.
+
+ of pkImage, pkImageTiled:
+ image*: Image ## Image to fill with.
+ imageMat*: Mat3 ## Matrix of the filled image.
+
+ of pkGradientLinear, pkGradientRadial, pkGradientAngular:
+ gradientHandlePositions*: seq[Vec2] ## Gradient positions (image space).
+ gradientStops*: seq[ColorStop] ## Color stops (gradient space).
+
+ blendMode*: BlendMode ## Blend mode.">Paint
ColorStop
+ color*: Color ## Color of the stop
+ position*: float32 ## Gradient Stop position 0..1.">ColorStop
@@ -182,27 +188,33 @@ window.addEventListener('DOMContentLoaded', main);
Paint = ref object
- kind*: PaintKind
- color*: ColorRGBA
- image*: Image
- imageMat*: Mat3
- gradientHandlePositions*: seq[Vec2]
- gradientStops*: seq[ColorStop]
- blendMode*: BlendMode
-
+ case kind*: PaintKind
+ of pkSolid:
+ color*: ColorRGBA
+
+ of pkImage, pkImageTiled:
+ image*: Image
+ imageMat*: Mat3
+
+ of pkGradientLinear, pkGradientRadial, pkGradientAngular:
+ gradientHandlePositions*: seq[Vec2]
+ gradientStops*: seq[ColorStop]
+
+ blendMode*: BlendMode
+
-
+Paint used to fill paths.
ColorStop = object
- color*: Color
- position*: float32
-
+ color*: Color
+ position*: float32
+
-Represents color on a gradient curve.
+Color stop on a gradient curve.
@@ -215,7 +227,7 @@ Represents color on a gradient curve.
raises: [PixieError, Exception], tags: [RootEffect].}
-
+Draws and basic image fill.
@@ -223,7 +235,7 @@ Represents color on a gradient curve.
tags: [].}
-
+Draws a tiled image fill.
@@ -231,7 +243,7 @@ Represents color on a gradient curve.
raises: [], tags: [].}
-Linear gradient.
+Fills a linear gradient.
@@ -239,7 +251,7 @@ Linear gradient.
stops: seq[ColorStop]) {...}{.raises: [], tags: [].}
-Radial gradient. start, stop, and skew.
+Fills a radial gradient.
@@ -247,7 +259,7 @@ Radial gradient. start, stop, and skew.
stops: seq[ColorStop]) {...}{.raises: [], tags: [].}
-
+Angular gradient.
@@ -260,7 +272,7 @@ Radial gradient. start, stop, and skew.
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:05 UTC
diff --git a/docs/pixie/paths.html b/docs/pixie/paths.html
index a9422d9..7cc4b99 100644
--- a/docs/pixie/paths.html
+++ b/docs/pixie/paths.html
@@ -287,7 +287,7 @@ window.addEventListener('DOMContentLoaded', main);
wrNonZero, wrEvenOdd
-
+Winding rules.
@@ -295,7 +295,7 @@ window.addEventListener('DOMContentLoaded', main);
lcButt, lcRound, lcSquare
-
+Line cap type for strokes.
@@ -303,7 +303,7 @@ window.addEventListener('DOMContentLoaded', main);
ljMiter, ljRound, ljBevel
-
+Line join type for strokes.
@@ -332,7 +332,7 @@ Binary version of an SVG command
-
+Used to hold paths and create paths.
@@ -365,35 +365,35 @@ Adds a path to the current path.
proc closePath(path: var Path) {...}{.raises: [], tags: [].}
-
+Closes a path (draws a line to the start).
proc moveTo(path: var Path; x, y: float32) {...}{.raises: [], tags: [].}
-
+Moves the current drawing pen to a new position and starts a new shape.
proc moveTo(path: var Path; v: Vec2) {...}{.inline, raises: [], tags: [].}
-
+Moves the current drawing pen to a new position and starts a new shape.
proc lineTo(path: var Path; x, y: float32) {...}{.raises: [], tags: [].}
-
+Adds a line.
proc lineTo(path: var Path; v: Vec2) {...}{.inline, raises: [], tags: [].}
-
+Adds a line.
@@ -425,7 +425,7 @@ Adds a quadratic Bézier curve to the path. This requires 2 points. The first po
tags: [].}
-
+Adds a quadratic Bézier curve to the path. This requires 2 points. The first point is the control point and the second is the end point. The starting point is the last point in the current path, which can be changed using moveTo() before creating the curve.
@@ -450,7 +450,7 @@ Adds a circular arc to the current sub-path, using the given control points and
tags: [].}
-
+Adds an elliptical arc to the current sub-path, using the given radius ratios, sweep flags, and end position.
@@ -466,7 +466,7 @@ Adds a circular arc to the current sub-path, using the given control points and
raises: [], tags: [].}
-
+Adds a rectangle. Clockwise param can be used to subtract a rect from a path using even-odd.
@@ -474,7 +474,7 @@ Adds a circular arc to the current sub-path, using the given control points and
tags: [].}
-
+Adds a rectangle. Clockwise param can be used to subtract a rect from a path using even-odd.
@@ -482,7 +482,7 @@ Adds a circular arc to the current sub-path, using the given control points and
clockwise = true) {...}{.raises: [], tags: [].}
-
+Adds a rounded rectangle. Clockwise param can be used to subtract a rect from a path using even-odd.
@@ -490,7 +490,7 @@ Adds a circular arc to the current sub-path, using the given control points and
clockwise = true) {...}{.inline, raises: [], tags: [].}
-
+Adds a rounded rectangle. Clockwise param can be used to subtract a rect from a path using even-odd.
@@ -498,14 +498,14 @@ Adds a circular arc to the current sub-path, using the given control points and
clockwise = true) {...}{.inline, raises: [], tags: [].}
-
+Adds a rounded rectangle. Clockwise param can be used to subtract a rect from a path using even-odd.
proc ellipse(path: var Path; cx, cy, rx, ry: float32) {...}{.raises: [], tags: [].}
-
+Adds a ellipse.
@@ -513,7 +513,7 @@ Adds a circular arc to the current sub-path, using the given control points and
raises: [], tags: [].}
-
+Adds a ellipse.
@@ -521,7 +521,7 @@ Adds a circular arc to the current sub-path, using the given control points and
tags: [].}
-Draws a n sided regular polygon at (x, y) with size.
+Draws a n-sided regular polygon at (x, y) with a size.
@@ -529,7 +529,7 @@ Draws a n sided regular polygon at (x, y) with size.
raises: [], tags: [].}
-
+Draws a n-sided regular polygon at (x, y) with a size.
@@ -537,7 +537,7 @@ Draws a n sided regular polygon at (x, y) with size.
windingRule = wrNonZero; blendMode = bmNormal) {...}{.inline.}
-
+Fills a path.
@@ -546,14 +546,14 @@ Draws a n sided regular polygon at (x, y) with size.
blendMode = bmNormal)
-
+Fills a path.
proc fillPath(mask: Mask; path: SomePath; windingRule = wrNonZero) {...}{.inline.}
-
+Fills a path.
@@ -561,7 +561,7 @@ Draws a n sided regular polygon at (x, y) with size.
windingRule = wrNonZero)
-
+Fills a path.
@@ -569,7 +569,7 @@ Draws a n sided regular polygon at (x, y) with size.
windingRule = wrNonZero)
-
+Fills a path.
@@ -578,7 +578,7 @@ Draws a n sided regular polygon at (x, y) with size.
blendMode = bmNormal)
-
+Strokes a path.
@@ -587,7 +587,7 @@ Draws a n sided regular polygon at (x, y) with size.
lineJoin = ljMiter; blendMode = bmNormal)
-
+Strokes a path.
@@ -595,7 +595,7 @@ Draws a n sided regular polygon at (x, y) with size.
lineJoin = ljMiter)
-
+Strokes a path.
@@ -603,7 +603,7 @@ Draws a n sided regular polygon at (x, y) with size.
strokeWidth = 1.0; lineCap = lcButt; lineJoin = ljMiter)
-
+Strokes a path.
@@ -628,7 +628,7 @@ Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last).
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:05 UTC
diff --git a/docs/theindex.html b/docs/theindex.html
index af2ef30..0fd7ff7 100644
--- a/docs/theindex.html
+++ b/docs/theindex.html
@@ -917,7 +917,7 @@ window.addEventListener('DOMContentLoaded', main);
- Made with Nim. Generated: 2021-02-25 14:22:57 UTC
+ Made with Nim. Generated: 2021-02-25 14:52:05 UTC
diff --git a/src/pixie/images.nim b/src/pixie/images.nim
index 3281def..36d365e 100644
--- a/src/pixie/images.nim
+++ b/src/pixie/images.nim
@@ -804,31 +804,39 @@ proc draw*(a, b: Image, mat: Mat3, blendMode = bmNormal) {.inline.} =
a.drawUber(b, mat, blendMode)
proc draw*(a, b: Image, pos = vec2(0, 0), blendMode = bmNormal) {.inline.} =
+ # Draws one image onto another using a position offset with color blending.
a.draw(b, translate(pos), blendMode)
proc draw*(image: Image, mask: Mask, mat: Mat3, blendMode = bmMask) {.inline.} =
+ # Draws a mask onto an image using a matrix with color blending.
image.drawUber(mask, mat, blendMode)
proc draw*(
image: Image, mask: Mask, pos = vec2(0, 0), blendMode = bmMask
) {.inline.} =
+ # Draws a mask onto an image using a position offset with color blending.
image.drawUber(mask, translate(pos), blendMode)
proc draw*(a, b: Mask, mat: Mat3, blendMode = bmMask) {.inline.} =
+ # Draws a mask onto a mask using a matrix with color blending.
a.drawUber(b, mat, blendMode)
proc draw*(a, b: Mask, pos = vec2(0, 0), blendMode = bmMask) {.inline.} =
+ # Draws a mask onto a mask using a position offset with color blending.
a.draw(b, translate(pos), blendMode)
proc draw*(mask: Mask, image: Image, mat: Mat3, blendMode = bmMask) {.inline.} =
+ # Draws a image onto a mask using a matrix with color blending.
mask.drawUber(image, mat, blendMode)
proc draw*(
mask: Mask, image: Image, pos = vec2(0, 0), blendMode = bmMask
) {.inline.} =
+ # Draws a image onto a mask using a position offset with color blending.
mask.draw(image, translate(pos), blendMode)
proc resize*(srcImage: Image, width, height: int): Image =
+ ## Resize an image to a given hight and width.
if width == srcImage.width and height == srcImage.height:
result = srcImage.copy()
else:
diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim
index 16f62c8..dd56bbb 100644
--- a/src/pixie/masks.nim
+++ b/src/pixie/masks.nim
@@ -94,6 +94,7 @@ proc fill*(mask: Mask, value: uint8) {.inline.} =
fillUnsafe(mask.data, value, 0, mask.data.len)
proc getValueSmooth*(mask: Mask, x, y: float32): uint8 =
+ ## Gets a interpolated value with float point coordinates.
let
minX = floor(x)
minY = floor(y)
diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim
index 01742c0..76e34d9 100644
--- a/src/pixie/paints.nim
+++ b/src/pixie/paints.nim
@@ -10,24 +10,29 @@ type
pkGradientAngular
Paint* = ref object
- kind*: PaintKind
- color*: ColorRGBA
- image*: Image
- imageMat*: Mat3
- gradientHandlePositions*: seq[Vec2]
- gradientStops*: seq[ColorStop]
- blendMode*: BlendMode
+ ## Paint used to fill paths.
+ case kind*: PaintKind
+ of pkSolid:
+ color*: ColorRGBA ## Color to fill with.
+ of pkImage, pkImageTiled:
+ image*: Image ## Image to fill with.
+ imageMat*: Mat3 ## Matrix of the filled image.
+ of pkGradientLinear, pkGradientRadial, pkGradientAngular:
+ gradientHandlePositions*: seq[Vec2] ## Gradient positions (image space).
+ gradientStops*: seq[ColorStop] ## Color stops (gradient space).
+ blendMode*: BlendMode ## Blend mode.
ColorStop* = object
- ## Represents color on a gradient curve.
- color*: Color
- position*: float32
+ ## Color stop on a gradient curve.
+ color*: Color ## Color of the stop
+ position*: float32 ## Gradient Stop position 0..1.
proc fillImage*(
dest: Image,
src: Image,
mat: Mat3
) =
+ ## Draws and basic image fill.
dest.draw(
src,
mat
@@ -38,6 +43,7 @@ proc fillImageTiled*(
src: Image,
mat: Mat3
) =
+ ## Draws a tiled image fill.
var
matInv = mat.inverse()
src = src
@@ -102,7 +108,7 @@ proc fillLinearGradient*(
at, to: Vec2,
stops: seq[ColorStop]
) =
- ## Linear gradient.
+ ## Fills a linear gradient.
for y in 0 ..< image.height:
for x in 0 ..< image.width:
let xy = vec2(x.float32, y.float32)
@@ -114,8 +120,7 @@ proc fillRadialGradient*(
center, edge, skew: Vec2,
stops: seq[ColorStop]
) =
- ## Radial gradient.
- ## start, stop, and skew.
+ ## Fills a radial gradient.
let
distanceX = dist(center, edge)
distanceY = dist(center, skew)
@@ -136,6 +141,7 @@ proc fillAngularGradient*(
center, edge, skew: Vec2,
stops: seq[ColorStop]
) =
+ ## Angular gradient.
# TODO: make edge between start and end anti-aliased.
let
gradientAngle = normalize(edge - center).angle().fixAngle()
diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim
index 94bc37a..2abbdc8 100644
--- a/src/pixie/paths.nim
+++ b/src/pixie/paths.nim
@@ -5,13 +5,16 @@ when defined(amd64) and not defined(pixieNoSimd):
type
WindingRule* = enum
+ ## Winding rules.
wrNonZero
wrEvenOdd
LineCap* = enum
+ ## Line cap type for strokes.
lcButt, lcRound, lcSquare
LineJoin* = enum
+ ## Line join type for strokes.
ljMiter, ljRound, ljBevel
PathCommandKind* = enum
@@ -26,23 +29,26 @@ type
numbers*: seq[float32]
Path* = object
+ ## Used to hold paths and create paths.
commands*: seq[PathCommand]
start, at: Vec2 # Maintained by moveTo, lineTo, etc. Used by arcTo.
SomePath* = Path | string | seq[seq[Vec2]]
-const epsilon = 0.0001 * PI
+const epsilon = 0.0001 * PI ## Tiny value used for some computations.
when defined(release):
{.push checks: off.}
proc maxScale(m: Mat3): float32 =
+ ## What is the largest scale of this matrix.
max(
vec2(m[0, 0], m[0, 1]).length,
vec2(m[1, 0], m[1, 1]).length
)
proc parameterCount(kind: PathCommandKind): int =
+ ## Returns number of parameters a path command has.
case kind:
of Close: 0
of Move, Line, RMove, RLine, TQuad, RTQuad: 2
@@ -52,6 +58,7 @@ proc parameterCount(kind: PathCommandKind): int =
of Arc, RArc: 7
proc `$`*(path: Path): string =
+ ## Turn path int into a string.
for i, command in path.commands:
case command.kind
of Move: result.add "M"
@@ -222,6 +229,7 @@ proc parsePath*(path: string): Path =
finishCommand(result)
proc transform*(path: var Path, mat: Mat3) =
+ ## Apply a matrix transform to a path.
for command in path.commands.mitems:
case command.kind:
of Close:
@@ -280,22 +288,27 @@ proc addPath*(path: var Path, other: Path) =
path.commands.add(other.commands)
proc closePath*(path: var Path) =
+ ## Closes a path (draws a line to the start).
path.commands.add(PathCommand(kind: Close))
path.at = path.start
proc moveTo*(path: var Path, x, y: float32) =
+ ## Moves the current drawing pen to a new position and starts a new shape.
path.commands.add(PathCommand(kind: Move, numbers: @[x, y]))
path.start = vec2(x, y)
path.at = path.start
proc moveTo*(path: var Path, v: Vec2) {.inline.} =
+ ## Moves the current drawing pen to a new position and starts a new shape.
path.moveTo(v.x, v.y)
proc lineTo*(path: var Path, x, y: float32) =
+ ## Adds a line.
path.commands.add(PathCommand(kind: Line, numbers: @[x, y]))
path.at = vec2(x, y)
proc lineTo*(path: var Path, v: Vec2) {.inline.} =
+ ## Adds a line.
path.lineTo(v.x, v.y)
proc bezierCurveTo*(path: var Path, x1, y1, x2, y2, x3, y3: float32) =
@@ -324,6 +337,11 @@ proc quadraticCurveTo*(path: var Path, x1, y1, x2, y2: float32) =
path.at = vec2(x2, y2)
proc quadraticCurveTo*(path: var Path, ctrl, to: Vec2) {.inline.} =
+ ## Adds a quadratic Bézier curve to the path. This requires 2 points.
+ ## The first point is the control point and the second is the end point.
+ ## The starting point is the last point in the current path, which can be
+ ## changed using moveTo() before creating the curve.
+ ##
path.quadraticCurveTo(ctrl.x, ctrl.y, to.x, to.y)
proc arcTo*(path: var Path, ctrl1, ctrl2: Vec2, radius: float32) {.inline.} =
@@ -390,6 +408,8 @@ proc ellipticalArcTo*(
largeArcFlag, sweepFlag: bool,
x, y: float32
) =
+ ## Adds an elliptical arc to the current sub-path, using the given radius
+ ## ratios, sweep flags, and end position.
path.commands.add(PathCommand(
kind: Arc,
numbers: @[
@@ -413,9 +433,13 @@ proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
path.closePath()
proc rect*(path: var Path, pos: Vec2, wh: Vec2, clockwise = true) {.inline.} =
+ ## Adds a rectangle.
+ ## Clockwise param can be used to subtract a rect from a path using even-odd.
path.rect(pos.x, pos.y, wh.x, wh.y, clockwise)
proc rect*(path: var Path, rect: Rect, clockwise = true) {.inline.} =
+ ## Adds a rectangle.
+ ## Clockwise param can be used to subtract a rect from a path using even-odd.
path.rect(rect.x, rect.y, rect.w, rect.h, clockwise)
const splineCircleK = 4.0 * (-1.0 + sqrt(2.0)) / 3
@@ -425,6 +449,8 @@ const splineCircleK = 4.0 * (-1.0 + sqrt(2.0)) / 3
proc roundedRect*(
path: var Path, x, y, w, h, nw, ne, se, sw: float32, clockwise = true
) =
+ ## Adds a rounded rectangle.
+ ## Clockwise param can be used to subtract a rect from a path using even-odd.
let
s = splineCircleK
@@ -478,14 +504,19 @@ proc roundedRect*(
proc roundedRect*(
path: var Path, pos, wh: Vec2, nw, ne, se, sw: float32, clockwise = true
) {.inline.} =
+ ## Adds a rounded rectangle.
+ ## Clockwise param can be used to subtract a rect from a path using even-odd.
path.roundedRect(pos.x, pos.y, wh.x, wh.y, nw, ne, se, sw, clockwise)
proc roundedRect*(
path: var Path, rect: Rect, nw, ne, se, sw: float32, clockwise = true
) {.inline.} =
+ ## Adds a rounded rectangle.
+ ## Clockwise param can be used to subtract a rect from a path using even-odd.
path.roundedRect(rect.x, rect.y, rect.w, rect.h, nw, ne, se, sw, clockwise)
proc ellipse*(path: var Path, cx, cy, rx, ry: float32) =
+ ## Adds a ellipse.
let
magicX = splineCircleK * rx
magicY = splineCircleK * ry
@@ -498,10 +529,11 @@ proc ellipse*(path: var Path, cx, cy, rx, ry: float32) =
path.closePath()
proc ellipse*(path: var Path, center: Vec2, rx, ry: float32) {.inline.} =
+ ## Adds a ellipse.
path.ellipse(center.x, center.y, rx, ry)
proc polygon*(path: var Path, x, y, size: float32, sides: int) =
- ## Draws a n sided regular polygon at (x, y) with size.
+ ## Draws a n-sided regular polygon at (x, y) with a size.
path.moveTo(x + size * cos(0.0), y + size * sin(0.0))
for side in 0 .. sides:
path.lineTo(
@@ -510,6 +542,7 @@ proc polygon*(path: var Path, x, y, size: float32, sides: int) =
)
proc polygon*(path: var Path, pos: Vec2, size: float32, sides: int) {.inline.} =
+ ## Draws a n-sided regular polygon at (x, y) with a size.
path.polygon(pos.x, pos.y, size, sides)
proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] =
@@ -535,7 +568,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] =
shape.add(to)
proc addCubic(shape: var seq[Vec2], at, ctrl1, ctrl2, to: Vec2) =
-
+ ## Adds cubic segments to shape.
proc compute(at, ctrl1, ctrl2, to: Vec2, t: float32): Vec2 {.inline.} =
pow(1 - t, 3) * at +
pow(1 - t, 2) * 3 * t * ctrl1 +
@@ -565,7 +598,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] =
shape.discretize(1, 1)
proc addQuadratic(shape: var seq[Vec2], at, ctrl, to: Vec2) =
-
+ ## Adds quadratic segments to shape.
proc compute(at, ctrl, to: Vec2, t: float32): Vec2 {.inline.} =
pow(1 - t, 2) * at +
2 * (1 - t) * t * ctrl +
@@ -600,6 +633,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] =
large, sweep: bool,
to: Vec2
) =
+ ## Adds arc segments to shape.
type ArcParams = object
radii: Vec2
rotMat: Mat3
@@ -876,6 +910,7 @@ iterator segments*(s: seq[Vec2]): Segment =
yield(segment(s[i], s[i + 1]))
proc quickSort(a: var seq[(float32, int16)], inl, inr: int) =
+ ## Quick sorts inline faster then standard lib.
var
r = inr
l = inl
@@ -896,6 +931,7 @@ proc quickSort(a: var seq[(float32, int16)], inl, inr: int) =
quickSort(a, l, inr)
proc computeBounds(partitions: seq[seq[(Segment, int16)]]): Rect =
+ ## Compute bounds of a shape segments with windings.
var
xMin = float32.high
xMax = float32.low
@@ -919,6 +955,7 @@ proc computeBounds(partitions: seq[seq[(Segment, int16)]]): Rect =
result.h = yMax - yMin
proc shouldFill(windingRule: WindingRule, count: int): bool {.inline.} =
+ ## Should we fill based on the current winding rule and count?
case windingRule:
of wrNonZero:
count != 0
@@ -1361,6 +1398,7 @@ proc strokeShapes(
proc parseSomePath(
path: SomePath, pixelScale: float32 = 1.0
): seq[seq[Vec2]] {.inline.} =
+ ## Given SomePath, parse it in different ways.
when type(path) is string:
parsePath(path).commandsToShapes(pixelScale)
elif type(path) is Path:
@@ -1375,6 +1413,7 @@ proc fillPath*(
windingRule = wrNonZero,
blendMode = bmNormal
) {.inline.} =
+ ## Fills a path.
image.fillShapes(parseSomePath(path), color, windingRule, blendMode)
proc fillPath*(
@@ -1385,6 +1424,7 @@ proc fillPath*(
windingRule = wrNonZero,
blendMode = bmNormal
) =
+ ## Fills a path.
when type(transform) is Mat3:
let pixelScale = transform.maxScale()
else:
@@ -1403,6 +1443,7 @@ proc fillPath*(
path: SomePath,
windingRule = wrNonZero
) {.inline.} =
+ ## Fills a path.
mask.fillShapes(parseSomePath(path), windingRule)
proc fillPath*(
@@ -1411,6 +1452,7 @@ proc fillPath*(
transform: Vec2 | Mat3,
windingRule = wrNonZero
) =
+ ## Fills a path.
when type(transform) is Mat3:
let pixelScale = transform.maxScale()
else:
@@ -1430,6 +1472,7 @@ proc fillPath*(
paint: Paint,
windingRule = wrNonZero,
) =
+ ## Fills a path.
var mask = newMask(image.width, image.height)
var fill = newImage(image.width, image.height)
mask.fillPath(parseSomePath(path), windingRule)
@@ -1480,6 +1523,7 @@ proc strokePath*(
lineJoin = ljMiter,
blendMode = bmNormal
) =
+ ## Strokes a path.
let strokeShapes = strokeShapes(
parseSomePath(path), strokeWidth, lineCap, lineJoin
)
@@ -1495,6 +1539,7 @@ proc strokePath*(
lineJoin = ljMiter,
blendMode = bmNormal
) =
+ ## Strokes a path.
when type(transform) is Mat3:
let pixelScale = transform.maxScale()
else:
@@ -1517,6 +1562,7 @@ proc strokePath*(
lineCap = lcButt,
lineJoin = ljMiter
) =
+ ## Strokes a path.
let strokeShapes = strokeShapes(
parseSomePath(path), strokeWidth, lineCap, lineJoin
)
@@ -1530,6 +1576,7 @@ proc strokePath*(
lineCap = lcButt,
lineJoin = ljMiter
) =
+ ## Strokes a path.
when type(transform) is Mat3:
let pixelScale = transform.maxScale()
else: