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

Optimize the lasso & polygon select tools by making them check fewer pixels

The time they take to complete now depends on the size of the selection, rather than checking all of the pixels of the entire canvas.
This commit is contained in:
Emmanouil Papadeas 2024-09-05 03:34:30 +03:00
parent 4a7f7cbde5
commit 1e9c8487ba
2 changed files with 12 additions and 12 deletions

View file

@ -111,11 +111,12 @@ func apply_selection(_position) -> void:
func lasso_selection( func lasso_selection(
selection_map: SelectionMap, previous_selection_map: SelectionMap, points: Array[Vector2i] selection_map: SelectionMap, previous_selection_map: SelectionMap, points: Array[Vector2i]
) -> void: ) -> void:
var project := Global.current_project
var selection_size := selection_map.get_size() var selection_size := selection_map.get_size()
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
for point in points: for point in points:
if point.x < 0 or point.y < 0 or point.x >= selection_size.x or point.y >= selection_size.y: if point.x < 0 or point.y < 0 or point.x >= selection_size.x or point.y >= selection_size.y:
continue continue
bounding_rect = bounding_rect.expand(point)
if _intersect: if _intersect:
if previous_selection_map.is_pixel_selected(point): if previous_selection_map.is_pixel_selected(point):
selection_map.select_pixel(point, true) selection_map.select_pixel(point, true)
@ -123,11 +124,10 @@ func lasso_selection(
selection_map.select_pixel(point, !_subtract) selection_map.select_pixel(point, !_subtract)
var v := Vector2i() var v := Vector2i()
var image_size := project.size for x in bounding_rect.size.x:
for x in image_size.x: v.x = x + bounding_rect.position.x
v.x = x for y in bounding_rect.size.y:
for y in image_size.y: v.y = y + bounding_rect.position.y
v.y = y
if Geometry2D.is_point_in_polygon(v, points): if Geometry2D.is_point_in_polygon(v, points):
if _intersect: if _intersect:
if previous_selection_map.is_pixel_selected(v): if previous_selection_map.is_pixel_selected(v):

View file

@ -154,11 +154,12 @@ func _clear() -> void:
func lasso_selection( func lasso_selection(
selection_map: SelectionMap, previous_selection_map: SelectionMap, points: Array[Vector2i] selection_map: SelectionMap, previous_selection_map: SelectionMap, points: Array[Vector2i]
) -> void: ) -> void:
var project := Global.current_project
var selection_size := selection_map.get_size() var selection_size := selection_map.get_size()
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
for point in points: for point in points:
if point.x < 0 or point.y < 0 or point.x >= selection_size.x or point.y >= selection_size.y: if point.x < 0 or point.y < 0 or point.x >= selection_size.x or point.y >= selection_size.y:
continue continue
bounding_rect = bounding_rect.expand(point)
if _intersect: if _intersect:
if previous_selection_map.is_pixel_selected(point): if previous_selection_map.is_pixel_selected(point):
selection_map.select_pixel(point, true) selection_map.select_pixel(point, true)
@ -166,11 +167,10 @@ func lasso_selection(
selection_map.select_pixel(point, !_subtract) selection_map.select_pixel(point, !_subtract)
var v := Vector2i() var v := Vector2i()
var image_size := project.size for x in bounding_rect.size.x:
for x in image_size.x: v.x = x + bounding_rect.position.x
v.x = x for y in bounding_rect.size.y:
for y in image_size.y: v.y = y + bounding_rect.position.y
v.y = y
if Geometry2D.is_point_in_polygon(v, points): if Geometry2D.is_point_in_polygon(v, points):
if _intersect: if _intersect:
if previous_selection_map.is_pixel_selected(v): if previous_selection_map.is_pixel_selected(v):