From 9234005d1a095a82b2d6eac2441a4f1cd9a971e8 Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 1 Jul 2021 18:14:49 +0300 Subject: [PATCH] Minor drawing optimization --- src/Classes/Drawers.gd | 11 +++-------- src/Classes/Project.gd | 9 +++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Classes/Drawers.gd b/src/Classes/Drawers.gd index 83da1c2e6..d7342c98c 100644 --- a/src/Classes/Drawers.gd +++ b/src/Classes/Drawers.gd @@ -73,15 +73,10 @@ func set_pixel(image: Image, position: Vector2, color: Color) -> void: # Handle Mirroring var mirror_x = project.x_symmetry_point - position.x var mirror_y = project.y_symmetry_point - position.y - var mirror_x_inside : bool - var mirror_y_inside : bool - mirror_x_inside = project.can_pixel_get_drawn(Vector2(mirror_x, position.y)) - mirror_y_inside = project.can_pixel_get_drawn(Vector2(position.x, mirror_y)) - - if horizontal_mirror and mirror_x_inside: + if horizontal_mirror and project.can_pixel_get_drawn(Vector2(mirror_x, position.y)): drawers[1].set_pixel(image, Vector2(mirror_x, position.y), color, color_op) - if vertical_mirror and mirror_y_inside: + if vertical_mirror and project.can_pixel_get_drawn(Vector2(position.x, mirror_y)): drawers[2].set_pixel(image, Vector2(mirror_x, mirror_y), color, color_op) - if vertical_mirror and mirror_y_inside: + if vertical_mirror and project.can_pixel_get_drawn(Vector2(position.x, mirror_y)): drawers[3].set_pixel(image, Vector2(position.x, mirror_y), color, color_op) diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 570c8640f..b91628cbb 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -620,11 +620,11 @@ func can_pixel_get_drawn(pixel : Vector2, bitmap : BitMap = selection_bitmap, se if pixel.x < 0 or pixel.y < 0 or pixel.x >= size.x or pixel.y >= size.y: return false - if selection_position.x < 0: - pixel.x -= selection_position.x - if selection_position.y < 0: - pixel.y -= selection_position.y if has_selection: + if selection_position.x < 0: + pixel.x -= selection_position.x + if selection_position.y < 0: + pixel.y -= selection_position.y return bitmap.get_bit(pixel) else: return true @@ -672,6 +672,7 @@ func bitmap_to_image(bitmap : BitMap, square := true) -> Image: return image +# Algorithm taken from Image.get_used_rect() - https://github.com/godotengine/godot/blob/master/core/io/image.cpp func get_selection_rectangle(bitmap : BitMap = selection_bitmap) -> Rect2: if bitmap.get_true_bit_count() == 0: return Rect2()