ensure float32

This commit is contained in:
Ryan Oldenburg 2021-11-23 04:38:37 -06:00
parent edaaeff2e3
commit c9d792823d
2 changed files with 18 additions and 1 deletions

View file

@ -214,6 +214,7 @@ proc fillGradientAngular(image: Image, paint: Paint) =
let
center = paint.gradientHandlePositions[0]
edge = paint.gradientHandlePositions[1]
f32PI = PI.float32
# TODO: make edge between start and end anti-aliased.
let gradientAngle = normalize(edge - center).angle().fixAngle()
for y in 0 ..< image.height:
@ -221,7 +222,7 @@ proc fillGradientAngular(image: Image, paint: Paint) =
let
xy = vec2(x.float32, y.float32)
angle = normalize(xy - center).angle()
t = (angle + gradientAngle + PI / 2).fixAngle() / 2 / PI + 0.5
t = (angle + gradientAngle + f32PI / 2).fixAngle() / 2 / f32PI + 0.5.float32
image.setRgbaUnsafe(x, y, paint.gradientColor(t))
proc fillGradient*(image: Image, paint: Paint) {.raises: [PixieError].} =

View file

@ -25,3 +25,19 @@ timeIt "GradientLinear horizontal":
ColorStop(color: color(1, 0, 0, 0.15625), position: 1.0),
]
image.fillGradient(paint)
# timeIt "GradientLinear radial":
# discard
timeIt "GradientLinear angular":
let paint = newPaint(pkGradientAngular)
paint.gradientHandlePositions = @[
vec2(500, 500),
vec2(1000, 500),
vec2(500, 1000)
]
paint.gradientStops = @[
ColorStop(color: color(1, 0, 0, 1), position: 0),
ColorStop(color: color(1, 0, 0, 0.15625), position: 1.0),
]
image.fillGradient(paint)