From 48694ad73537dcfde804f97e9152da4cdc933516 Mon Sep 17 00:00:00 2001 From: treeform Date: Sat, 10 Jul 2021 23:31:25 -0700 Subject: [PATCH] Add vector overloads of arc and arcTo. --- src/pixie/contexts.nim | 8 ++++++++ src/pixie/paths.nim | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index a1d6807..3e73989 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -636,6 +636,14 @@ proc arc*(ctx: Context, x, y, r, a0, a1: float32, ccw: bool = false) = ## Draws a circular arc. ctx.path.arc(x, y, r, a0, a1, ccw) +proc arc*(ctx: Context, pos: Vec2, r: float32, a: Vec2, ccw: bool = false) = + ## Adds a circular arc to the current sub-path. + ctx.path.arc(pos, r, a, ccw) + proc arcTo*(ctx: Context, x1, y1, x2, y2, radius: float32) = ## Draws a circular arc using the given control points and radius. ctx.path.arcTo(x1, y1, x2, y2, radius) + +proc arcTo*(ctx: Context, a, b: Vec2, r: float32) = + ## Adds a circular arc using the given control points and radius. + ctx.path.arcTo(a, b, r) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index d8399d0..ff28af9 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -437,6 +437,10 @@ proc arc*(path: var Path, x, y, r, a0, a1: float32, ccw: bool) = path.at.y = y + r * sin(a1) path.ellipticalArcTo(r, r, 0, angle >= PI, cw, path.at.x, path.at.y) +proc arc*(path: var Path, pos: Vec2, r: float32, a: Vec2, ccw: bool = false) = + ## Adds a circular arc to the current sub-path. + path.arc(pos.x, pos.y, r, a.x, a.y, ccw) + proc arcTo*(path: var Path, x1, y1, x2, y2, r: float32) = ## Adds a circular arc using the given control points and radius. ## Commonly used for making rounded corners. @@ -478,6 +482,10 @@ proc arcTo*(path: var Path, x1, y1, x2, y2, r: float32) = path.at.y = y1 + t21 * y21 path.ellipticalArcTo(r, r, 0, false, y01 * x20 > x01 * y20, path.at.x, path.at.y) +proc arcTo*(path: var Path, a, b: Vec2, r: float32) = + ## Adds a circular arc using the given control points and radius. + path.arcTo(a.x, a.y, b.x, b.y, r) + 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