diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim index c619299..9b9bbaa 100644 --- a/src/pixie/paints.nim +++ b/src/pixie/paints.nim @@ -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].} = diff --git a/tests/benchmark_paints.nim b/tests/benchmark_paints.nim index f07da26..24e7d93 100644 --- a/tests/benchmark_paints.nim +++ b/tests/benchmark_paints.nim @@ -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)