check for invalid

This commit is contained in:
Ryan Oldenburg 2021-05-10 13:54:47 -05:00
parent f9064af992
commit 10311fae70

View file

@ -27,7 +27,7 @@ type
color*: ColorRGBX ## Color of the stop color*: ColorRGBX ## Color of the stop
position*: float32 ## Gradient Stop position 0..1. position*: float32 ## Gradient Stop position 0..1.
proc toLineSpace(at, to, point: Vec2): float32 = proc toLineSpace(at, to, point: Vec2): float32 {.inline.} =
## Convert position on to where it would fall on a line between at and to. ## Convert position on to where it would fall on a line between at and to.
let let
d = to - at d = to - at
@ -69,6 +69,9 @@ proc fillGradientLinear*(image: Image, paint: Paint) =
if paint.gradientHandlePositions.len != 2: if paint.gradientHandlePositions.len != 2:
raise newException(PixieError, "Linear gradient requires 2 handles") raise newException(PixieError, "Linear gradient requires 2 handles")
if paint.gradientStops.len == 0:
raise newException(PixieError, "Gradient must have at least 1 color stop")
let let
at = paint.gradientHandlePositions[0] at = paint.gradientHandlePositions[0]
to = paint.gradientHandlePositions[1] to = paint.gradientHandlePositions[1]
@ -88,6 +91,9 @@ proc fillGradientRadial*(image: Image, paint: Paint) =
if paint.gradientHandlePositions.len != 3: if paint.gradientHandlePositions.len != 3:
raise newException(PixieError, "Radial gradient requires 3 handles") raise newException(PixieError, "Radial gradient requires 3 handles")
if paint.gradientStops.len == 0:
raise newException(PixieError, "Gradient must have at least 1 color stop")
let let
center = paint.gradientHandlePositions[0] center = paint.gradientHandlePositions[0]
edge = paint.gradientHandlePositions[1] edge = paint.gradientHandlePositions[1]
@ -116,6 +122,9 @@ proc fillGradientAngular*(image: Image, paint: Paint) =
if paint.gradientHandlePositions.len != 3: if paint.gradientHandlePositions.len != 3:
raise newException(PixieError, "Angular gradient requires 2 handles") raise newException(PixieError, "Angular gradient requires 2 handles")
if paint.gradientStops.len == 0:
raise newException(PixieError, "Gradient must have at least 1 color stop")
let let
center = paint.gradientHandlePositions[0] center = paint.gradientHandlePositions[0]
edge = paint.gradientHandlePositions[1] edge = paint.gradientHandlePositions[1]