31 lines
550 B
Lua
31 lines
550 B
Lua
-- Represents 2D point
|
|
---@class Point
|
|
Point = { x = 1, y = 1 }
|
|
|
|
-- Point factory
|
|
---@param x number
|
|
---@param y number
|
|
---@return any
|
|
function Point:new( x, y )
|
|
local point = {
|
|
x = x or x,
|
|
y = y or y
|
|
}
|
|
|
|
setmetatable( point, { __index = self } )
|
|
|
|
return point
|
|
end
|
|
|
|
-- Comparing function
|
|
---@param point self
|
|
---@return boolean
|
|
function Point:equals( point )
|
|
return self.x == point.x and self.y == point.y
|
|
end
|
|
|
|
-- Get self coordinates
|
|
---@return number, number
|
|
function Point:coords()
|
|
return self.x, self.y
|
|
end
|