Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Builtin: Add vector.floor helper function
  • Loading branch information
rubenwardy authored and nerzhul committed Oct 17, 2016
1 parent a291cd6 commit 0d740c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion builtin/common/vector.lua
Expand Up @@ -31,6 +31,14 @@ function vector.normalize(v)
end
end

function vector.floor(v)
return {
x = math.floor(v.x),
y = math.floor(v.y),
z = math.floor(v.z)
}
end

function vector.round(v)
return {
x = math.floor(v.x + 0.5),
Expand Down Expand Up @@ -130,4 +138,3 @@ function vector.divide(a, b)
z = a.z / b}
end
end

3 changes: 2 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -1812,7 +1812,8 @@ Spatial Vectors
* `vector.distance(p1, p2)`: returns a number
* `vector.length(v)`: returns a number
* `vector.normalize(v)`: returns a vector
* `vector.round(v)`: returns a vector, each dimension rounded to floor
* `vector.floor(v)`: returns a vector, each dimension rounded down
* `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

Expand Down

0 comments on commit 0d740c5

Please sign in to comment.