diff --git a/pixie.nimble b/pixie.nimble index e5ef86c..cbea163 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -1,4 +1,4 @@ -version = "4.0.1" +version = "4.0.2" author = "Andre von Houck and Ryan Oldenburg" description = "Full-featured 2d graphics library for Nim." license = "MIT" diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index 1f69004..85a9f0b 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -669,13 +669,13 @@ proc circle*(ctx: Context, circle: Circle) {.inline, raises: [].} = proc polygon*( ctx: Context, x, y, size: float32, sides: int -) {.inline, raises: [].} = +) {.inline, raises: [PixieError].} = ## Adds an n-sided regular polygon at (x, y) of size to the current path. ctx.path.polygon(x, y, size, sides) proc polygon*( ctx: Context, pos: Vec2, size: float32, sides: int -) {.inline, raises: [].} = +) {.inline, raises: [PixieError].} = ## Adds an n-sided regular polygon at (x, y) of size to the current path. ctx.path.polygon(pos, size, sides) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index d1d69b0..9bc124f 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -628,8 +628,12 @@ proc circle*(path: Path, circle: Circle) {.inline, raises: [].} = ## Adds a circle. path.ellipse(circle.pos.x, circle.pos.y, circle.radius, circle.radius) -proc polygon*(path: Path, x, y, size: float32, sides: int) {.raises: [].} = +proc polygon*( + path: Path, x, y, size: float32, sides: int +) {.raises: [PixieError].} = ## Adds an n-sided regular polygon at (x, y) with the parameter size. + if sides <= 0: + raise newException(PixieError, "Invalid polygon sides value") path.moveTo(x + size * cos(0.0), y + size * sin(0.0)) for side in 0 .. sides: path.lineTo( @@ -639,7 +643,7 @@ proc polygon*(path: Path, x, y, size: float32, sides: int) {.raises: [].} = proc polygon*( path: Path, pos: Vec2, size: float32, sides: int -) {.inline, raises: [].} = +) {.inline, raises: [PixieError].} = ## Adds a n-sided regular polygon at (x, y) with the parameter size. path.polygon(pos.x, pos.y, size, sides) diff --git a/tests/test_paths.nim b/tests/test_paths.nim index d3c21bf..fe09072 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -665,3 +665,13 @@ block: color = rgba(255, 0, 0, 255) image.fillPath(pathStr, color) image.writeFile("tests/paths/path0pxCover.png") + +block: + let image = newImage(200, 200) + image.fill(rgba(255, 255, 255, 255)) + + let ctx = newContext(image) + ctx.setLineDash(@[2.0.float32]) + + doAssertRaises PixieError: + ctx.strokePolygon(vec2(0.0, 0.0), 0.0, 0)