Add Center Function on Holes

Calculates the center of the hole.
This commit is contained in:
2025-11-24 20:03:52 -05:00
parent 703285f555
commit 0a3919ce4c
2 changed files with 14 additions and 6 deletions

View File

@@ -149,18 +149,18 @@ func hit(position: Vector3):
# translate the cutter # translate the cutter
var hole_vectors = Transform2D(0, hole_vector2_offset) * cutter var hole_vectors = Transform2D(0, hole_vector2_offset) * cutter
var rtree_search = [] var draw = _add_hole(hole_vectors)
for hv in hole_vectors:
rtree_search.append_array(inner_rtree.query(hv))
var draw = _add_hole(hole_vectors, rtree_search)
if draw: if draw:
_re_draw() _re_draw()
func _add_hole(new_hole: PackedVector2Array, holes_id: PackedInt32Array) -> bool: func _add_hole(new_hole: PackedVector2Array) -> bool:
var ids_to_remove = [] var ids_to_remove = []
var holes_id = []
for vector in new_hole:
holes_id.append_array(inner_rtree.query(vector))
# validate that the hole is valid # validate that the hole is valid
var boundary_polygon = Geometry2D.offset_polygon(outer_polygon, -edge_non_fracture) var boundary_polygon = Geometry2D.offset_polygon(outer_polygon, -edge_non_fracture)

View File

@@ -8,3 +8,11 @@ var vectors: PackedVector2Array
func _init(hole_id: int, vectors: PackedVector2Array): func _init(hole_id: int, vectors: PackedVector2Array):
self.hole_id = hole_id self.hole_id = hole_id
self.vectors = vectors self.vectors = vectors
func center():
var avg_vert = Vector2.ZERO
for v in vectors:
avg_vert += v
return avg_vert / len(vectors)