diff --git a/docs/pixie.html b/docs/pixie.html index ae4f7a6..f807890 100644 --- a/docs/pixie.html +++ b/docs/pixie.html @@ -546,7 +546,7 @@ Convert a straight alpha RGBA to a premultiplied alpha RGBA.
proc circle(path: var Path; center: Vec2; r: float32) {...}{.inline, raises: [], + tags: [].}
proc polygon(path: var Path; x, y, size: float32; sides: int) {...}{.raises: [], @@ -641,18 +646,6 @@ Strokes a path. - --@@ -662,7 +655,7 @@ Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last). diff --git a/docs/pixie/paths.idx b/docs/pixie/paths.idx index b74e56f..98986cd 100644 --- a/docs/pixie/paths.idx +++ b/docs/pixie/paths.idx @@ -56,10 +56,10 @@ roundedRect pixie/paths.html#roundedRect,Path,Vec2,Vec2,float32,float32,float32, roundedRect pixie/paths.html#roundedRect,Path,Rect,float32,float32,float32,float32 paths: roundedRect(path: var Path; rect: Rect; nw, ne, se, sw: float32;\n clockwise = true) ellipse pixie/paths.html#ellipse,Path,float32,float32,float32,float32 paths: ellipse(path: var Path; cx, cy, rx, ry: float32) ellipse pixie/paths.html#ellipse,Path,Vec2,float32,float32 paths: ellipse(path: var Path; center: Vec2; rx, ry: float32) +circle pixie/paths.html#circle,Path,Vec2,float32 paths: circle(path: var Path; center: Vec2; r: float32) polygon pixie/paths.html#polygon,Path,float32,float32,float32,int paths: polygon(path: var Path; x, y, size: float32; sides: int) polygon pixie/paths.html#polygon,Path,Vec2,float32,int paths: polygon(path: var Path; pos: Vec2; size: float32; sides: int) commandsToShapes pixie/paths.html#commandsToShapes,Path,float32 paths: commandsToShapes(path: Path; pixelScale: float32 = 1.0): seq[seq[Vec2]] -segments pixie/paths.html#segments.i,seq[Vec2] paths: segments(s: seq[Vec2]): Segment fillPath pixie/paths.html#fillPath,Image,SomePath,SomeColor paths: fillPath(image: Image; path: SomePath; color: SomeColor;\n windingRule = wrNonZero; blendMode = bmNormal) fillPath pixie/paths.html#fillPath,Image,SomePath,SomeColor, paths: fillPath(image: Image; path: SomePath; color: SomeColor; transform: Vec2 | Mat3;\n windingRule = wrNonZero; blendMode = bmNormal) fillPath pixie/paths.html#fillPath,Mask,SomePath paths: fillPath(mask: Mask; path: SomePath; windingRule = wrNonZero) diff --git a/docs/theindex.html b/docs/theindex.html index edfbe23..3cf0d6a 100644 --- a/docs/theindex.html +++ b/docs/theindex.html @@ -238,6 +238,10 @@ function main() {Iterators
-- -
- -
iterator segments(s: seq[Vec2]): Segment {...}{.raises: [], tags: [].}- - -Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last). - -
-masks: ceil(mask: Mask) +circle: Close: -
- PathCommandKind.Close
@@ -772,10 +776,6 @@ function main() {- PathCommandKind.SCubic
segments: setRgbaUnsafe:
- images: setRgbaUnsafe(image: Image; x, y: int; color: SomeColor)
@@ -945,7 +945,7 @@ function main() { diff --git a/pixie.nimble b/pixie.nimble index 74909df..882e81c 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -1,4 +1,4 @@ -version = "1.1.1" +version = "1.1.2" author = "Andre von Houck and Ryan Oldenburg" description = "Full-featured 2d graphics library for Nim." license = "MIT" @@ -6,12 +6,12 @@ license = "MIT" srcDir = "src" requires "nim >= 1.2.6" -requires "vmath >= 0.4.0" +requires "vmath >= 1.0.0" requires "chroma >= 0.2.5" requires "zippy >= 0.3.5" requires "flatty >= 0.1.3" requires "nimsimd >= 1.0.0" -requires "bumpy >= 1.0.2" +requires "bumpy >= 1.0.3" task docs, "Generate API documents": exec "nim doc --index:on --project --out:docs --hints:off src/pixie.nim" diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 9dac187..4465ac9 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -163,12 +163,12 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = if arr.len != 6: failInvalidTransform(transform) var m = mat3() - m[0] = parseFloat(arr[0].strip()) - m[1] = parseFloat(arr[1].strip()) - m[3] = parseFloat(arr[2].strip()) - m[4] = parseFloat(arr[3].strip()) - m[6] = parseFloat(arr[4].strip()) - m[7] = parseFloat(arr[5].strip()) + m[0, 0] = parseFloat(arr[0].strip()) + m[0, 1] = parseFloat(arr[1].strip()) + m[1, 0] = parseFloat(arr[2].strip()) + m[1, 1] = parseFloat(arr[3].strip()) + m[2, 0] = parseFloat(arr[4].strip()) + m[2, 1] = parseFloat(arr[5].strip()) result.transform = result.transform * m elif f.startsWith("translate("): let @@ -183,7 +183,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = elif f.startsWith("rotate("): let values = f[7 .. ^2].split(" ") - angle = parseFloat(values[0].strip()) * -PI / 180 + angle: float32 = parseFloat(values[0].strip()) * -PI / 180 var cx, cy: float32 if values.len > 1: cx = parseFloat(values[1].strip()) @@ -191,7 +191,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = cy = parseFloat(values[2].strip()) let center = vec2(cx, cy) result.transform = result.transform * - translate(center) * rotationMat3(angle) * translate(-center) + translate(center) * rotate(angle) * translate(-center) else: failInvalidTransform(transform) diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim index d6cb4d1..36212a9 100644 --- a/src/pixie/paints.nim +++ b/src/pixie/paints.nim @@ -84,7 +84,7 @@ proc fillRadialGradient*( gradientAngle = normalize(center - edge).angle().fixAngle() mat = ( translate(center) * - rotationMat3(-gradientAngle) * + rotate(-gradientAngle) * scale(vec2(distanceX, distanceY)) ).inverse() for y in 0 ..< image.height: diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index b4cc235..49fb2ca 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -543,6 +543,10 @@ proc ellipse*(path: var Path, center: Vec2, rx, ry: float32) {.inline.} = ## Adds a ellipse. path.ellipse(center.x, center.y, rx, ry) +proc circle*(path: var Path, center: Vec2, r: float32) {.inline.} = + ## Adds a circle. + path.ellipse(center.x, center.y, r, r) + proc polygon*(path: var Path, x, y, size: float32, sides: int) = ## 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)) @@ -658,7 +662,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = radiiSq = vec2(radii.x * radii.x, radii.y * radii.y) let - radians = rotation / 180 * PI + radians: float32 = rotation / 180 * PI d = vec2((at.x - to.x) / 2.0, (at.y - to.y) / 2.0) p = vec2( cos(radians) * d.x + sin(radians) * d.y, @@ -714,7 +718,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = ArcParams( radii: radii, - rotMat: rotationMat3(-radians), + rotMat: rotate(-radians), center: center, theta: theta, delta: delta @@ -789,7 +793,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = ctrl2 = vec2(command.numbers[0], command.numbers[1]) to = vec2(command.numbers[2], command.numbers[3]) if prevCommandKind in {Cubic, SCubic, RCubic, RSCubic}: - let ctrl1 = 2 * at - prevCtrl2 + let ctrl1 = at * 2 - prevCtrl2 shape.addCubic(at, ctrl1, ctrl2, to) else: shape.addCubic(at, at, ctrl2, to) @@ -809,7 +813,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = to = vec2(command.numbers[0], command.numbers[1]) ctrl = if prevCommandKind in {Quad, TQuad, RQuad, RTQuad}: - 2 * at - prevCtrl + at * 2 - prevCtrl else: at shape.addQuadratic(at, ctrl, to) @@ -864,7 +868,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = to = vec2(at.x + command.numbers[2], at.y + command.numbers[3]) ctrl1 = if prevCommandKind in {Cubic, SCubic, RCubic, RSCubic}: - 2 * at - prevCtrl2 + at * 2 - prevCtrl2 else: at shape.addCubic(at, ctrl1, ctrl2, to) @@ -884,7 +888,7 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = to = vec2(at.x + command.numbers[0], at.y + command.numbers[1]) ctrl = if prevCommandKind in {Quad, TQuad, RQuad, RTQuad}: - 2 * at - prevCtrl + at * 2 - prevCtrl else: at shape.addQuadratic(at, ctrl, to) @@ -914,11 +918,6 @@ proc commandsToShapes*(path: Path, pixelScale: float32 = 1.0): seq[seq[Vec2]] = if shape.len > 0: result.add(shape) -iterator segments*(s: seq[Vec2]): Segment = - ## Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last). - for i in 0 ..< s.len - 1: - yield(segment(s[i], s[i + 1])) - proc quickSort(a: var seq[(float32, int16)], inl, inr: int) = ## Sorts in place + faster than standard lib sort. var diff --git a/tests/images/paths/gradientAngular.png b/tests/images/paths/gradientAngular.png index b6b8d6e..260e7d5 100644 Binary files a/tests/images/paths/gradientAngular.png and b/tests/images/paths/gradientAngular.png differ diff --git a/tests/test_images_draw.nim b/tests/test_images_draw.nim index b4d1c99..d5d5d38 100644 --- a/tests/test_images_draw.nim +++ b/tests/test_images_draw.nim @@ -17,7 +17,7 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - a.draw(b, translate(vec2(250, 250)) * rotationMat3(90 * PI / 180)) + a.draw(b, translate(vec2(250, 250)) * rotate(90 * PI.float32 / 180)) a.writeFile("tests/images/rotate90.png") block: @@ -27,7 +27,7 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - a.draw(b, translate(vec2(250, 250)) * rotationMat3(180 * PI / 180)) + a.draw(b, translate(vec2(250, 250)) * rotate(180 * PI.float32 / 180)) a.writeFile("tests/images/rotate180.png") block: @@ -37,7 +37,7 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - a.draw(b, translate(vec2(250, 250)) * rotationMat3(270 * PI / 180)) + a.draw(b, translate(vec2(250, 250)) * rotate(270 * PI.float32 / 180)) a.writeFile("tests/images/rotate270.png") block: @@ -47,7 +47,7 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - a.draw(b, translate(vec2(250, 250)) * rotationMat3(360 * PI / 180)) + a.draw(b, translate(vec2(250, 250)) * rotate(360 * PI.float32 / 180)) a.writeFile("tests/images/rotate360.png") block: