1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Further simplify mirror_array()

This commit is contained in:
Emmanouil Papadeas 2024-11-21 02:21:11 +02:00
parent 3615ce087c
commit 849b815562
8 changed files with 15 additions and 19 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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:

View file

@ -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:

View file

@ -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: