From 849b81556281a4fc8753ca5f50a523653f045f45 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 21 Nov 2024 02:21:11 +0200 Subject: [PATCH] Further simplify mirror_array() --- src/Tools/BaseShapeDrawer.gd | 2 +- src/Tools/BaseTool.gd | 12 +++++------- src/Tools/DesignTools/CurveTool.gd | 2 +- src/Tools/DesignTools/LineTool.gd | 2 +- src/Tools/SelectionTools/EllipseSelect.gd | 2 +- src/Tools/SelectionTools/Lasso.gd | 4 ++-- src/Tools/SelectionTools/PaintSelect.gd | 4 ++-- src/Tools/SelectionTools/PolygonSelect.gd | 6 ++---- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/Tools/BaseShapeDrawer.gd b/src/Tools/BaseShapeDrawer.gd index 9d8faa993..4af1a156f 100644 --- a/src/Tools/BaseShapeDrawer.gd +++ b/src/Tools/BaseShapeDrawer.gd @@ -168,7 +168,7 @@ func draw_preview() -> void: if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]): image.set_pixelv(points[i], Color.WHITE) # Handle mirroring - for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(points): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) diff --git a/src/Tools/BaseTool.gd b/src/Tools/BaseTool.gd index 4a8397477..b9541ac69 100644 --- a/src/Tools/BaseTool.gd +++ b/src/Tools/BaseTool.gd @@ -205,14 +205,12 @@ func snap_position(pos: Vector2) -> Vector2: return pos -## Returns an array that mirrors each point of the [param array], based on [param h] and [param v]. +## Returns an array that mirrors each point of the [param array]. ## An optional [param callable] can be passed, which gets called for each type of symmetry. -func mirror_array( - array: Array[Vector2i], h: bool, v: bool, callable := func(_array): pass -) -> Array[Vector2i]: +func mirror_array(array: Array[Vector2i], callable := func(_array): pass) -> Array[Vector2i]: var new_array: Array[Vector2i] = [] var project := Global.current_project - if h and v: + if Tools.horizontal_mirror and Tools.vertical_mirror: var hv_array: Array[Vector2i] = [] for point in array: hv_array.append( @@ -221,14 +219,14 @@ func mirror_array( if callable.is_valid(): callable.call(hv_array) new_array += hv_array - if h: + if Tools.horizontal_mirror: var h_array: Array[Vector2i] = [] for point in array: h_array.append(Vector2i(project.x_symmetry_point - point.x, point.y)) if callable.is_valid(): callable.call(h_array) new_array += h_array - if v: + if Tools.vertical_mirror: var v_array: Array[Vector2i] = [] for point in array: v_array.append(Vector2i(point.x, project.y_symmetry_point - point.y)) diff --git a/src/Tools/DesignTools/CurveTool.gd b/src/Tools/DesignTools/CurveTool.gd index 0c6634db1..c326d5b43 100644 --- a/src/Tools/DesignTools/CurveTool.gd +++ b/src/Tools/DesignTools/CurveTool.gd @@ -141,7 +141,7 @@ func draw_preview() -> void: image.set_pixelv(points[i], Color.WHITE) # Handle mirroring - for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(points): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) diff --git a/src/Tools/DesignTools/LineTool.gd b/src/Tools/DesignTools/LineTool.gd index 163984905..3f2f858b2 100644 --- a/src/Tools/DesignTools/LineTool.gd +++ b/src/Tools/DesignTools/LineTool.gd @@ -157,7 +157,7 @@ func draw_preview() -> void: if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) # Handle mirroring - for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(points): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) diff --git a/src/Tools/SelectionTools/EllipseSelect.gd b/src/Tools/SelectionTools/EllipseSelect.gd index 797e5cfe2..80539a797 100644 --- a/src/Tools/SelectionTools/EllipseSelect.gd +++ b/src/Tools/SelectionTools/EllipseSelect.gd @@ -63,7 +63,7 @@ func draw_preview() -> void: if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]): image.set_pixelv(points[i], Color.WHITE) # Handle mirroring - for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(points): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) diff --git a/src/Tools/SelectionTools/Lasso.gd b/src/Tools/SelectionTools/Lasso.gd index bcf2b88ac..1f73eb9b1 100644 --- a/src/Tools/SelectionTools/Lasso.gd +++ b/src/Tools/SelectionTools/Lasso.gd @@ -46,7 +46,7 @@ func draw_preview() -> void: image.set_pixelv(draw_point, Color.WHITE) # Handle mirroring - for point in mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(_draw_points): var draw_point := point if Global.mirror_view: # This fixes previewing in mirror mode draw_point.x = image.get_width() - draw_point.x - 1 @@ -73,7 +73,7 @@ func apply_selection(_position) -> void: lasso_selection(_draw_points, project.selection_map, previous_selection_map) # Handle mirroring var callable := lasso_selection.bind(project.selection_map, previous_selection_map) - mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror, callable) + mirror_array(_draw_points, callable) Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() else: if !cleared: diff --git a/src/Tools/SelectionTools/PaintSelect.gd b/src/Tools/SelectionTools/PaintSelect.gd index cb7787334..ddee4e5a7 100644 --- a/src/Tools/SelectionTools/PaintSelect.gd +++ b/src/Tools/SelectionTools/PaintSelect.gd @@ -74,7 +74,7 @@ func draw_preview() -> void: image.set_pixelv(draw_point, Color.WHITE) # Handle mirroring - for point in mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror): + for point in mirror_array(_draw_points): var draw_point := point if Global.mirror_view: # This fixes previewing in mirror mode draw_point.x = image.get_width() - draw_point.x - 1 @@ -101,7 +101,7 @@ func apply_selection(pos: Vector2i) -> void: project.selection_map.clear() paint_selection(project.selection_map, previous_selection_map, _draw_points) # Handle mirroring - var mirror := mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror) + var mirror := mirror_array(_draw_points) paint_selection(project.selection_map, previous_selection_map, mirror) Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() else: diff --git a/src/Tools/SelectionTools/PolygonSelect.gd b/src/Tools/SelectionTools/PolygonSelect.gd index 9758d16e9..3c8776a75 100644 --- a/src/Tools/SelectionTools/PolygonSelect.gd +++ b/src/Tools/SelectionTools/PolygonSelect.gd @@ -81,9 +81,7 @@ func draw_preview() -> void: ) # Handle mirroring - for point in mirror_array( - preview_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror - ): + for point in mirror_array(preview_draw_points): var draw_point := point if Global.mirror_view: # This fixes previewing in mirror mode draw_point.x = image.get_width() - draw_point.x - 1 @@ -112,7 +110,7 @@ func apply_selection(pos: Vector2i) -> void: lasso_selection(_draw_points, project.selection_map, previous_selection_map) # Handle mirroring var callable := lasso_selection.bind(project.selection_map, previous_selection_map) - mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror, callable) + mirror_array(_draw_points, callable) Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() else: if !cleared: