ensure float32
This commit is contained in:
parent
edaaeff2e3
commit
c9d792823d
2 changed files with 18 additions and 1 deletions
|
@ -214,6 +214,7 @@ proc fillGradientAngular(image: Image, paint: Paint) =
|
||||||
let
|
let
|
||||||
center = paint.gradientHandlePositions[0]
|
center = paint.gradientHandlePositions[0]
|
||||||
edge = paint.gradientHandlePositions[1]
|
edge = paint.gradientHandlePositions[1]
|
||||||
|
f32PI = PI.float32
|
||||||
# TODO: make edge between start and end anti-aliased.
|
# TODO: make edge between start and end anti-aliased.
|
||||||
let gradientAngle = normalize(edge - center).angle().fixAngle()
|
let gradientAngle = normalize(edge - center).angle().fixAngle()
|
||||||
for y in 0 ..< image.height:
|
for y in 0 ..< image.height:
|
||||||
|
@ -221,7 +222,7 @@ proc fillGradientAngular(image: Image, paint: Paint) =
|
||||||
let
|
let
|
||||||
xy = vec2(x.float32, y.float32)
|
xy = vec2(x.float32, y.float32)
|
||||||
angle = normalize(xy - center).angle()
|
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))
|
image.setRgbaUnsafe(x, y, paint.gradientColor(t))
|
||||||
|
|
||||||
proc fillGradient*(image: Image, paint: Paint) {.raises: [PixieError].} =
|
proc fillGradient*(image: Image, paint: Paint) {.raises: [PixieError].} =
|
||||||
|
|
|
@ -25,3 +25,19 @@ timeIt "GradientLinear horizontal":
|
||||||
ColorStop(color: color(1, 0, 0, 0.15625), position: 1.0),
|
ColorStop(color: color(1, 0, 0, 0.15625), position: 1.0),
|
||||||
]
|
]
|
||||||
image.fillGradient(paint)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue