Files
godot-demo-holes/demo/assets/scripts/environment/destructable/util.gd
Collin Campbell c208d069bb Implemented R-Tree
Would like to switch the identifer of the hole to a random string.
2025-11-23 18:22:00 -05:00

28 lines
710 B
GDScript

extends Object
class_name UTIL
# chunks array into 'chunk_size' pieces
static func chunk_array(arr: Array, chunk_size: int) -> Array:
var result_chunks = []
var i = 0
while i < arr.size():
var chunk = arr.slice(i, i + chunk_size)
result_chunks.append(chunk)
i += chunk_size
return result_chunks
static func vector2_to_vector3(v: Vector2) -> Vector3:
return Vector3(v.x, v.y, 0)
static func get_bounding_rect(vectors: PackedVector2Array) -> Rect2:
if vectors.is_empty():
return Rect2()
var rect := Rect2(vectors[0], Vector2.ZERO) # Initialize with the first point
for point in vectors:
rect = rect.expand(point)
# The 'position' of the Rect2 will be the minimum corner
return rect