Skip to content

Commit

Permalink
Vector: Add vector.sort(a, b): return box edges
Browse files Browse the repository at this point in the history
This function returns the box corners of the smallest box
that includes the two given coordinates.
  • Loading branch information
sofar authored and paramat committed Jan 23, 2017
1 parent d04d8ab commit 2d7a6f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/common/vector.lua
Expand Up @@ -138,3 +138,8 @@ function vector.divide(a, b)
z = a.z / b}
end
end

function vector.sort(a, b)
return {x = math.min(a.x, b.x), y = math.min(a.y, b.y), z = math.min(a.z, b.z)},
{x = math.max(a.x, b.x), y = math.max(a.y, b.y), z = math.max(a.z, b.z)}
end
1 change: 1 addition & 0 deletions doc/lua_api.txt
Expand Up @@ -1850,6 +1850,7 @@ Spatial Vectors
* `vector.round(v)`: returns a vector, each dimension rounded to nearest int
* `vector.apply(v, func)`: returns a vector
* `vector.equals(v1, v2)`: returns a boolean
* `vector.sort(v1, v2)`: returns minp, maxp vectors of the cuboid defined by v1 and v2

For the following functions `x` can be either a vector or a number:

Expand Down

0 comments on commit 2d7a6f2

Please sign in to comment.