small comment things
This commit is contained in:
parent
34b5f07f1f
commit
7b9d968381
5 changed files with 62 additions and 54 deletions
|
@ -52,13 +52,13 @@ proc writeFile*(image: Image, filePath: string) =
|
|||
image.writeFile(filePath, fileformat)
|
||||
|
||||
proc fillRect*(image: Image, rect: Rect, color: ColorRGBA) =
|
||||
## Fill a rectangle.
|
||||
## Fills a rectangle.
|
||||
var path: Path
|
||||
path.rect(rect)
|
||||
image.fillPath(path, color)
|
||||
|
||||
proc fillRect*(mask: Mask, rect: Rect) =
|
||||
## Fill a rectangle.
|
||||
## Fills a rectangle.
|
||||
var path: Path
|
||||
path.rect(rect)
|
||||
mask.fillPath(path)
|
||||
|
@ -66,13 +66,13 @@ proc fillRect*(mask: Mask, rect: Rect) =
|
|||
proc strokeRect*(
|
||||
image: Image, rect: Rect, color: ColorRGBA, strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rectangle.
|
||||
var path: Path
|
||||
path.rect(rect)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
||||
proc strokeRect*(mask: Mask, rect: Rect, strokeWidth = 1.0) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rectangle.
|
||||
var path: Path
|
||||
path.rect(rect)
|
||||
mask.strokePath(path, strokeWidth)
|
||||
|
@ -83,7 +83,7 @@ proc fillRoundedRect*(
|
|||
nw, ne, se, sw: float32,
|
||||
color: ColorRGBA
|
||||
) =
|
||||
## Fill a rounded rectangle.
|
||||
## Fills a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, nw, ne, se, sw)
|
||||
image.fillPath(path, color)
|
||||
|
@ -94,19 +94,19 @@ proc fillRoundedRect*(
|
|||
radius: float32,
|
||||
color: ColorRGBA
|
||||
) =
|
||||
## Fill a rounded rectangle.
|
||||
## Fills a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, radius, radius, radius, radius)
|
||||
image.fillPath(path, color)
|
||||
|
||||
proc fillRoundedRect*(mask: Mask, rect: Rect, nw, ne, se, sw: float32) =
|
||||
## Fill a rounded rectangle.
|
||||
## Fills a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, nw, ne, se, sw)
|
||||
mask.fillPath(path)
|
||||
|
||||
proc fillRoundedRect*(mask: Mask, rect: Rect, radius: float32) =
|
||||
## Fill a rounded rectangle.
|
||||
## Fills a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, radius, radius, radius, radius)
|
||||
mask.fillPath(path)
|
||||
|
@ -118,7 +118,7 @@ proc strokeRoundedRect*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, nw, ne, se, sw)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
@ -130,7 +130,7 @@ proc strokeRoundedRect*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, radius, radius, radius, radius)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
@ -138,7 +138,7 @@ proc strokeRoundedRect*(
|
|||
proc strokeRoundedRect*(
|
||||
mask: Mask, rect: Rect, nw, ne, se, sw: float32, strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, nw, ne, se, sw)
|
||||
mask.strokePath(path, strokeWidth)
|
||||
|
@ -146,7 +146,7 @@ proc strokeRoundedRect*(
|
|||
proc strokeRoundedRect*(
|
||||
mask: Mask, rect: Rect, radius: float32, strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a rounded rectangle.
|
||||
## Strokes a rounded rectangle.
|
||||
var path: Path
|
||||
path.roundedRect(rect, radius, radius, radius, radius)
|
||||
mask.strokePath(path, strokeWidth)
|
||||
|
@ -157,14 +157,14 @@ proc strokeSegment*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke a segment (draws a line from segment.at to segment.to).
|
||||
## Strokes a segment (draws a line from segment.at to segment.to).
|
||||
var path: Path
|
||||
path.moveTo(segment.at)
|
||||
path.lineTo(segment.to)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
||||
proc strokeSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
|
||||
## Stroke a segment (draws a line from segment.at to segment.to).
|
||||
## Strokes a segment (draws a line from segment.at to segment.to).
|
||||
var path: Path
|
||||
path.moveTo(segment.at)
|
||||
path.lineTo(segment.to)
|
||||
|
@ -177,7 +177,7 @@ proc fillEllipse*(
|
|||
color: ColorRGBA,
|
||||
blendMode = bmNormal
|
||||
) =
|
||||
## Fill an ellipse.
|
||||
## Fills an ellipse.
|
||||
var path: Path
|
||||
path.ellipse(center, rx, ry)
|
||||
image.fillPath(path, color, wrNonZero, blendMode)
|
||||
|
@ -187,7 +187,7 @@ proc fillEllipse*(
|
|||
center: Vec2,
|
||||
rx, ry: float32
|
||||
) =
|
||||
## Fill an ellipse.
|
||||
## Fills an ellipse.
|
||||
var path: Path
|
||||
path.ellipse(center, rx, ry)
|
||||
mask.fillPath(path)
|
||||
|
@ -199,7 +199,7 @@ proc strokeEllipse*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke an ellipse.
|
||||
## Strokes an ellipse.
|
||||
var path: Path
|
||||
path.ellipse(center, rx, ry)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
@ -210,7 +210,7 @@ proc strokeEllipse*(
|
|||
rx, ry: float32,
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
## Stroke an ellipse.
|
||||
## Strokes an ellipse.
|
||||
var path: Path
|
||||
path.ellipse(center, rx, ry)
|
||||
mask.strokePath(path, strokeWidth)
|
||||
|
|
|
@ -210,15 +210,15 @@ proc blendMultiply(backdrop, source: ColorRGBA): ColorRGBA =
|
|||
result.b = blend(backdrop.b, backdrop.a, source.b, source.a)
|
||||
result.a = blendAlpha(backdrop.a, source.a)
|
||||
|
||||
proc blendLinearBurn(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
let
|
||||
backdrop = backdrop.toStraightAlpha()
|
||||
source = source.toStraightAlpha()
|
||||
result.r = min(0, backdrop.r.int32 + source.r.int32 - 255).uint8
|
||||
result.g = min(0, backdrop.g.int32 + source.g.int32 - 255).uint8
|
||||
result.b = min(0, backdrop.b.int32 + source.b.int32 - 255).uint8
|
||||
result = alphaFix(backdrop, source, result)
|
||||
result = result.toPremultipliedAlpha()
|
||||
# proc blendLinearBurn(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
# let
|
||||
# backdrop = backdrop.toStraightAlpha()
|
||||
# source = source.toStraightAlpha()
|
||||
# result.r = min(0, backdrop.r.int32 + source.r.int32 - 255).uint8
|
||||
# result.g = min(0, backdrop.g.int32 + source.g.int32 - 255).uint8
|
||||
# result.b = min(0, backdrop.b.int32 + source.b.int32 - 255).uint8
|
||||
# result = alphaFix(backdrop, source, result)
|
||||
# result = result.toPremultipliedAlpha()
|
||||
|
||||
proc blendColorBurn(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
let
|
||||
|
@ -257,15 +257,15 @@ proc blendScreen(backdrop, source: ColorRGBA): ColorRGBA =
|
|||
result.b = screen(backdrop.b, source.b)
|
||||
result.a = blendAlpha(backdrop.a, source.a)
|
||||
|
||||
proc blendLinearDodge(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
let
|
||||
backdrop = backdrop.toStraightAlpha()
|
||||
source = source.toStraightAlpha()
|
||||
result.r = min(backdrop.r.uint32 + source.r, 255).uint8
|
||||
result.g = min(backdrop.g.uint32 + source.g, 255).uint8
|
||||
result.b = min(backdrop.b.uint32 + source.b, 255).uint8
|
||||
result = alphaFix(backdrop, source, result)
|
||||
result = result.toPremultipliedAlpha()
|
||||
# proc blendLinearDodge(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
# let
|
||||
# backdrop = backdrop.toStraightAlpha()
|
||||
# source = source.toStraightAlpha()
|
||||
# result.r = min(backdrop.r.uint32 + source.r, 255).uint8
|
||||
# result.g = min(backdrop.g.uint32 + source.g, 255).uint8
|
||||
# result.b = min(backdrop.b.uint32 + source.b, 255).uint8
|
||||
# result = alphaFix(backdrop, source, result)
|
||||
# result = result.toPremultipliedAlpha()
|
||||
|
||||
proc blendColorDodge(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
let
|
||||
|
@ -449,9 +449,9 @@ proc blendExcludeMask(backdrop, source: ColorRGBA): ColorRGBA =
|
|||
proc blendOverwrite(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
source
|
||||
|
||||
proc blendWhite(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
## For testing
|
||||
rgba(255, 255, 255, 255)
|
||||
# proc blendWhite(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
# ## For testing
|
||||
# rgba(255, 255, 255, 255)
|
||||
|
||||
proc blender*(blendMode: BlendMode): Blender =
|
||||
## Returns a blend function for a given blend mode.
|
||||
|
|
|
@ -339,7 +339,7 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
|
|||
raise newException(PixieError, "Unsupported SVG tag: " & node.tag & ".")
|
||||
|
||||
proc decodeSvg*(data: string, width = 0, height = 0): Image =
|
||||
## Render SVG file and return the image.
|
||||
## Render SVG file and return the image. Defaults to the SVG's view box size.
|
||||
try:
|
||||
let root = parseXml(data)
|
||||
if root.tag != "svg":
|
||||
|
|
|
@ -200,7 +200,7 @@ proc minifyBy2*(image: Image, power = 1): Image =
|
|||
src = result
|
||||
|
||||
proc magnifyBy2*(image: Image, power = 1): Image =
|
||||
## Scales image image up by 2 ^ power.
|
||||
## Scales image up by 2 ^ power.
|
||||
if power < 0:
|
||||
raise newException(PixieError, "Cannot magnifyBy2 with negative power")
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ when defined(release):
|
|||
{.push checks: off.}
|
||||
|
||||
proc maxScale(m: Mat3): float32 =
|
||||
## What is the largest scale of this matrix.
|
||||
## What is the largest scale factor of this matrix?
|
||||
max(
|
||||
vec2(m[0, 0], m[0, 1]).length,
|
||||
vec2(m[1, 0], m[1, 1]).length
|
||||
|
@ -89,7 +89,7 @@ proc `$`*(path: Path): string =
|
|||
result.add " "
|
||||
|
||||
proc parsePath*(path: string): Path =
|
||||
## Converts a SVG style path into seq of commands.
|
||||
## Converts a SVG style path string into seq of commands.
|
||||
|
||||
if path.len == 0:
|
||||
return
|
||||
|
@ -398,7 +398,9 @@ proc arcTo*(path: var Path, ctrl1, ctrl2: Vec2, radius: float32) {.inline.} =
|
|||
))
|
||||
path.at = to
|
||||
|
||||
proc arcTo*(path: var Path, x1, y1, x2, y2, radius: float32) =
|
||||
proc arcTo*(path: var Path, x1, y1, x2, y2, radius: float32) {.inline.} =
|
||||
## Adds a circular arc to the current sub-path, using the given control
|
||||
## points and radius.
|
||||
path.arcTo(vec2(x1, y1), vec2(x2, y2), radius)
|
||||
|
||||
proc ellipticalArcTo*(
|
||||
|
@ -419,6 +421,9 @@ proc ellipticalArcTo*(
|
|||
path.at = vec2(x, y)
|
||||
|
||||
proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
|
||||
## Adds a rectangle.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
if clockwise:
|
||||
path.moveTo(x, y)
|
||||
path.lineTo(x + w, y)
|
||||
|
@ -434,12 +439,14 @@ proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
|
|||
|
||||
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.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
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.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
path.rect(rect.x, rect.y, rect.w, rect.h, clockwise)
|
||||
|
||||
const splineCircleK = 4.0 * (-1.0 + sqrt(2.0)) / 3
|
||||
|
@ -450,7 +457,8 @@ 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.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
let
|
||||
s = splineCircleK
|
||||
|
||||
|
@ -505,14 +513,16 @@ 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.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
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.
|
||||
## Clockwise param can be used to subtract a rect from a path when using
|
||||
## even-odd winding rule.
|
||||
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) =
|
||||
|
@ -533,7 +543,7 @@ proc ellipse*(path: var Path, center: Vec2, rx, ry: float32) {.inline.} =
|
|||
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 a size.
|
||||
## Draws an n-sided regular polygon at (x, y) with the parameter size.
|
||||
path.moveTo(x + size * cos(0.0), y + size * sin(0.0))
|
||||
for side in 0 .. sides:
|
||||
path.lineTo(
|
||||
|
@ -542,12 +552,11 @@ 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.
|
||||
## Draws a n-sided regular polygon at (x, y) with the parameter size.
|
||||
path.polygon(pos.x, pos.y, size, sides)
|
||||
|
||||
proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] =
|
||||
## Converts SVG-like commands to line segments.
|
||||
|
||||
var
|
||||
start, at: Vec2
|
||||
shape: seq[Vec2]
|
||||
|
@ -910,7 +919,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.
|
||||
## Sorts in place + faster than standard lib sort.
|
||||
var
|
||||
r = inr
|
||||
l = inl
|
||||
|
@ -966,7 +975,6 @@ proc partitionSegments(
|
|||
shapes: seq[seq[Vec2]], height: int
|
||||
): seq[seq[(Segment, int16)]] =
|
||||
## Puts segments into the height partitions they intersect with.
|
||||
|
||||
var segmentCount: int
|
||||
for shape in shapes:
|
||||
segmentCount += shape.len - 1
|
||||
|
|
Loading…
Reference in a new issue