I am looking for a way to get the maximum (the most positive) and the minimum (the most negative) Vector2 coordinates from a given array "_bufferTileList". Say we have:
[(-1, 0), (-1, 1), (0, 0), (0, 1), (1, 0), (1, 1)]
In this scenario, the most positive would be (1, 1), or the furthest away from (0, 0) that is in the 1st quadrant, and the most negative would be (-1, 0), or the furthest away from (0, 0) that is in the 3rd quadrant.
The coordinates inside "_bufferTileList" will always have a rectangular layout.
Originally I expected it to be really easy, something like:
func _getMinVector2FromArray(_arr:PoolVector2Array) -> Vector2:
var min_val:Vector2 = _arr
for i in range(_arr.size()):
if min_val > _arr[i]:
min_val = _arr[i]
This quite literally compares if a vector (it's length) is smaller than the first one, which would only work if we're working in one quadrant (e.g. 1st quadrant).
My next approach was to split all the coordinates from their quadrants and from there get the coordinate with the maximum distance from (0, 0). However the contents of the array could all be located in the same quadrant. I then thought that i would have to transpose the x/y axis to the center of the selection, but it would not work with arrays in which width or height is even.
I am pretty sure there is a more simpler, easier approach to all of it.
Is there any built-in method to do this?
Is there a better approach?