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.

Exports

-maskerSimd, Masker, blender, hasSimdBlender, Blender, BlenderSimd, MaskerSimd, blenderSimd, hasSimdMasker, masker, BlendMode, blendAlpha, PixieError, lerp, lerp, fractional, lerp, getRgbaUnsafe, draw, []=, Image, copy, wh, setRgbaUnsafe, inside, getRgbaSmooth, invert, flipVertical, magnifyBy2, draw, draw, flipHorizontal, shadow, subImage, diff, $, draw, shift, dataIndex, minifyBy2, draw, draw, fill, draw, newMask, blur, newImage, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, [], $, setValueUnsafe, ceil, dataIndex, []=, spread, copy, wh, newMask, minifyBy2, fill, Mask, getValueUnsafe, getValueSmooth, blur, fillUnsafe, inside, [], ColorStop, PaintKind, fillLinearGradient, fillRadialGradient, fillAngularGradient, Paint, bezierCurveTo, LineCap, arcTo, LineJoin, rect, bezierCurveTo, SomePath, strokePath, $, parsePath, fillPath, lineTo, polygon, roundedRect, quadraticCurveTo, fillPath, strokePath, ellipticalArcTo, Path, lineTo, ellipse, quadraticCurveTo, arcTo, moveTo, roundedRect, PathCommandKind, polygon, strokePath, transform, PathCommand, roundedRect, rect, fillPath, segments, closePath, addPath, rect, strokePath, commandsToShapes, ellipse, WindingRule, fillPath, moveTo, fillPath +maskerSimd, Masker, blender, hasSimdBlender, Blender, BlenderSimd, MaskerSimd, blenderSimd, hasSimdMasker, masker, BlendMode, blendAlpha, PixieError, lerp, lerp, fractional, lerp, getRgbaUnsafe, draw, []=, Image, copy, wh, setRgbaUnsafe, inside, getRgbaSmooth, invert, flipVertical, magnifyBy2, draw, draw, flipHorizontal, shadow, subImage, diff, $, draw, shift, dataIndex, minifyBy2, draw, draw, fill, draw, newMask, blur, newImage, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, [], $, setValueUnsafe, ceil, dataIndex, []=, spread, copy, wh, newMask, minifyBy2, fill, Mask, getValueUnsafe, getValueSmooth, blur, fillUnsafe, inside, [], ColorStop, PaintKind, fillLinearGradient, fillRadialGradient, fillAngularGradient, Paint, bezierCurveTo, LineCap, arcTo, LineJoin, rect, bezierCurveTo, SomePath, strokePath, $, parsePath, fillPath, lineTo, polygon, fillPath, roundedRect, quadraticCurveTo, circle, strokePath, ellipticalArcTo, Path, lineTo, ellipse, quadraticCurveTo, arcTo, moveTo, roundedRect, PathCommandKind, polygon, strokePath, transform, PathCommand, roundedRect, rect, fillPath, closePath, addPath, rect, strokePath, commandsToShapes, ellipse, WindingRule, fillPath, moveTo, fillPath
@@ -556,7 +556,7 @@ Convert a straight alpha RGBA to a premultiplied alpha RGBA. diff --git a/docs/pixie/blends.html b/docs/pixie/blends.html index 0b2ac40..2612d50 100644 --- a/docs/pixie/blends.html +++ b/docs/pixie/blends.html @@ -283,7 +283,7 @@ Is there a blend masking function with SIMD support? diff --git a/docs/pixie/common.html b/docs/pixie/common.html index 87fdee2..9ec5719 100644 --- a/docs/pixie/common.html +++ b/docs/pixie/common.html @@ -196,7 +196,7 @@ Linearly interpolate between a and b using t. diff --git a/docs/pixie/fileformats/bmp.html b/docs/pixie/fileformats/bmp.html index 0d49704..c593f06 100644 --- a/docs/pixie/fileformats/bmp.html +++ b/docs/pixie/fileformats/bmp.html @@ -182,7 +182,7 @@ Encodes an image into the BMP file format. diff --git a/docs/pixie/fileformats/gif.html b/docs/pixie/fileformats/gif.html index 1dad08b..80d2263 100644 --- a/docs/pixie/fileformats/gif.html +++ b/docs/pixie/fileformats/gif.html @@ -161,7 +161,7 @@ Decodes GIF data into an Image. diff --git a/docs/pixie/fileformats/jpg.html b/docs/pixie/fileformats/jpg.html index fee3d34..1b24dfd 100644 --- a/docs/pixie/fileformats/jpg.html +++ b/docs/pixie/fileformats/jpg.html @@ -182,7 +182,7 @@ Encodes Image into a JPEG data string. diff --git a/docs/pixie/fileformats/png.html b/docs/pixie/fileformats/png.html index 784785d..2d29809 100644 --- a/docs/pixie/fileformats/png.html +++ b/docs/pixie/fileformats/png.html @@ -201,7 +201,7 @@ Encodes the mask data into the PNG file format. diff --git a/docs/pixie/fileformats/svg.html b/docs/pixie/fileformats/svg.html index 6fc809b..e3608bc 100644 --- a/docs/pixie/fileformats/svg.html +++ b/docs/pixie/fileformats/svg.html @@ -171,7 +171,7 @@ Render SVG file and return the image. Defaults to the SVG's view box size. diff --git a/docs/pixie/images.html b/docs/pixie/images.html index 8698aeb..ad6e878 100644 --- a/docs/pixie/images.html +++ b/docs/pixie/images.html @@ -586,7 +586,7 @@ Create a shadow of the image with the offset, spread and blur. diff --git a/docs/pixie/internal.html b/docs/pixie/internal.html index c40eb42..4bbf568 100644 --- a/docs/pixie/internal.html +++ b/docs/pixie/internal.html @@ -178,7 +178,7 @@ Unpack the first 32 bits into 4 rgba(0, 0, 0, value) diff --git a/docs/pixie/masks.html b/docs/pixie/masks.html index 4af957d..6ee9bbf 100644 --- a/docs/pixie/masks.html +++ b/docs/pixie/masks.html @@ -367,7 +367,7 @@ Applies Gaussian blur to the image given a radius. diff --git a/docs/pixie/paints.html b/docs/pixie/paints.html index a63ea80..cba5c82 100644 --- a/docs/pixie/paints.html +++ b/docs/pixie/paints.html @@ -243,7 +243,7 @@ Angular gradient. diff --git a/docs/pixie/paths.html b/docs/pixie/paths.html index d0ca581..015a1e6 100644 --- a/docs/pixie/paths.html +++ b/docs/pixie/paths.html @@ -150,6 +150,11 @@ function main() {
  • $,Path
  • + + @@ -541,6 +538,14 @@ Adds a ellipse. Adds a ellipse. + + +
    proc circle(path: var Path; center: Vec2; r: float32) {...}{.inline, raises: [],
    +    tags: [].}
    +
    + +Adds a circle. +
    proc polygon(path: var Path; x, y, size: float32; sides: int) {...}{.raises: [],
    @@ -641,18 +646,6 @@ Strokes a path.
     
     
     
    -
    -
    -

    Iterators

    -
    - -
    iterator segments(s: seq[Vec2]): Segment {...}{.raises: [], tags: [].}
    -
    - -Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last). - -
    -
    @@ -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() {
  • masks: ceil(mask: Mask)
  • +
    circle:
    Close:
    -
    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: