28 lines
710 B
GDScript
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
|