From 4a404b2883425bb7b5362405dcae531d99226c85 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Fri, 1 Mar 2024 20:25:37 +0200 Subject: [PATCH] Use Image.rotate_90() and Image.rotate_180() on CPU rotation algorithms when the angle is 90, 180 or 270 degrees --- src/Autoload/DrawingAlgos.gd | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 233a18226..5f043a9bc 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -216,9 +216,16 @@ func scale_3x(sprite: Image, tol := 50.0) -> Image: func rotxel(sprite: Image, angle: float, pivot: Vector2) -> void: - # If angle is simple, then nn rotation is the best - if angle == 0 || angle == PI / 2 || angle == PI || angle == 3.0 * PI / 2.0 || angle == TAU: - nn_rotate(sprite, angle, pivot) + if is_zero_approx(angle) or is_equal_approx(angle, TAU): + return + if is_equal_approx(angle, PI / 2.0): + sprite.rotate_90(CLOCKWISE) + return + if is_equal_approx(angle, 3.0 * PI / 2.0): + sprite.rotate_90(COUNTERCLOCKWISE) + return + if is_equal_approx(angle, PI): + sprite.rotate_180() return var aux := Image.new() @@ -399,6 +406,17 @@ func rotxel(sprite: Image, angle: float, pivot: Vector2) -> void: func fake_rotsprite(sprite: Image, angle: float, pivot: Vector2) -> void: + if is_zero_approx(angle) or is_equal_approx(angle, TAU): + return + if is_equal_approx(angle, PI / 2.0): + sprite.rotate_90(CLOCKWISE) + return + if is_equal_approx(angle, 3.0 * PI / 2.0): + sprite.rotate_90(COUNTERCLOCKWISE) + return + if is_equal_approx(angle, PI): + sprite.rotate_180() + return var selected_sprite := scale_3x(sprite) nn_rotate(selected_sprite, angle, pivot * 3) selected_sprite.resize( @@ -408,7 +426,16 @@ func fake_rotsprite(sprite: Image, angle: float, pivot: Vector2) -> void: func nn_rotate(sprite: Image, angle: float, pivot: Vector2) -> void: - if is_zero_approx(angle): + if is_zero_approx(angle) or is_equal_approx(angle, TAU): + return + if is_equal_approx(angle, PI / 2.0): + sprite.rotate_90(CLOCKWISE) + return + if is_equal_approx(angle, 3.0 * PI / 2.0): + sprite.rotate_90(COUNTERCLOCKWISE) + return + if is_equal_approx(angle, PI): + sprite.rotate_180() return var aux := Image.new() aux.copy_from(sprite)