mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Use Image.rotate_90() and Image.rotate_180() on CPU rotation algorithms when the angle is 90, 180 or 270 degrees
This commit is contained in:
parent
57856ed327
commit
4a404b2883
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue