From a4641a0eb2bcc72112bea4074e7091678536daa1 Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 16 Feb 2021 01:49:13 +0200 Subject: [PATCH] Split polygon into two with selection subtracting --- src/Tools/SelectionShape.gd | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Tools/SelectionShape.gd b/src/Tools/SelectionShape.gd index cc9790c..7cad872 100644 --- a/src/Tools/SelectionShape.gd +++ b/src/Tools/SelectionShape.gd @@ -228,14 +228,20 @@ func merge_multiple_selections(merge := true) -> void: self.local_selected_pixels = selected_pixels_copy else: var arr = Geometry.clip_polygons_2d(selection.polygon, polygon) +# print(arr.size()) if arr.size() == 0: # if the new selection completely overlaps the current selection.queue_free() - elif arr.size() == 1: # if the selections intersect + else: # if the selections intersect selection.set_polygon(arr[0]) var selected_pixels_copy = selection.local_selected_pixels.duplicate() for pixel in local_selected_pixels: selected_pixels_copy.erase(pixel) selection.local_selected_pixels = selected_pixels_copy + for i in range(1, arr.size()): + var selection_shape = load("res://src/Tools/SelectionShape.tscn").instance() + Global.current_project.selections.append(selection_shape) + Global.canvas.add_child(selection_shape) + selection_shape.set_polygon(arr[i]) func move_start(move_pixel : bool) -> void: