Add vector overloads of arc and arcTo.

This commit is contained in:
treeform 2021-07-10 23:31:25 -07:00
parent bd46136952
commit 48694ad735
2 changed files with 16 additions and 0 deletions

View file

@ -636,6 +636,14 @@ proc arc*(ctx: Context, x, y, r, a0, a1: float32, ccw: bool = false) =
## Draws a circular arc. ## Draws a circular arc.
ctx.path.arc(x, y, r, a0, a1, ccw) 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) = proc arcTo*(ctx: Context, x1, y1, x2, y2, radius: float32) =
## Draws a circular arc using the given control points and radius. ## Draws a circular arc using the given control points and radius.
ctx.path.arcTo(x1, y1, x2, y2, 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)

View file

@ -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.at.y = y + r * sin(a1)
path.ellipticalArcTo(r, r, 0, angle >= PI, cw, path.at.x, path.at.y) 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) = proc arcTo*(path: var Path, x1, y1, x2, y2, r: float32) =
## Adds a circular arc using the given control points and radius. ## Adds a circular arc using the given control points and radius.
## Commonly used for making rounded corners. ## 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.at.y = y1 + t21 * y21
path.ellipticalArcTo(r, r, 0, false, y01 * x20 > x01 * y20, path.at.x, path.at.y) 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) = proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
## Adds a rectangle. ## Adds a rectangle.
## Clockwise param can be used to subtract a rect from a path when using ## Clockwise param can be used to subtract a rect from a path when using