Add __eq metamethod and equals method to the vector api. (#800)

This commit is contained in:
Matthew Wilbern 2021-05-31 06:58:46 -06:00 committed by GitHub
parent 38335ca187
commit 7fc55aa9a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -151,6 +151,15 @@ local vector = {
tostring = function(self)
return self.x .. "," .. self.y .. "," .. self.z
end,
--- Check for equality between two vectors.
--
-- @tparam Vector self The first vector to compare.
-- @tparam Vector other The second vector to compare to.
-- @treturn boolean Whether or not the vectors are equal.
equals = function(self, other)
return self.x == other.x and self.y == other.y and self.z == other.z
end,
}
local vmetatable = {
@ -161,6 +170,7 @@ local vmetatable = {
__div = vector.div,
__unm = vector.unm,
__tostring = vector.tostring,
__eq = vector.equals,
}
--- Construct a new @{Vector} with the given coordinates.