mirror of
https://github.com/kepler155c/opus
synced 2025-11-12 13:33:54 +00:00
refactor + cleanup
This commit is contained in:
@@ -7,59 +7,26 @@
|
||||
-- made with regards of their `f` cost. From a given node being examined, the `pathfinder` will expand the search
|
||||
-- to the next neighbouring node having the lowest `f` cost. See `core.bheap` for more details.
|
||||
--
|
||||
|
||||
if (...) then
|
||||
|
||||
--- The `Node` class.<br/>
|
||||
-- This class is callable.
|
||||
-- Therefore,_ <code>Node(...)</code> _acts as a shortcut to_ <code>Node:new(...)</code>.
|
||||
-- @type Node
|
||||
local Node = {}
|
||||
Node.__index = Node
|
||||
|
||||
--- Inits a new `node`
|
||||
-- @class function
|
||||
-- @tparam int x the x-coordinate of the node on the collision map
|
||||
-- @tparam int y the y-coordinate of the node on the collision map
|
||||
-- @treturn node a new `node`
|
||||
-- @usage local node = Node(3,4)
|
||||
function Node:new(x,y,z)
|
||||
return setmetatable({_x = x, _y = y, _z = z }, Node)
|
||||
return setmetatable({x = x, y = y, z = z }, Node)
|
||||
end
|
||||
|
||||
-- Enables the use of operator '<' to compare nodes.
|
||||
-- Will be used to sort a collection of nodes in a binary heap on the basis of their F-cost
|
||||
function Node.__lt(A,B) return (A._f < B._f) end
|
||||
|
||||
--- Returns x-coordinate of a `node`
|
||||
-- @class function
|
||||
-- @treturn number the x-coordinate of the `node`
|
||||
-- @usage local x = node:getX()
|
||||
function Node:getX() return self._x end
|
||||
|
||||
--- Returns y-coordinate of a `node`
|
||||
-- @class function
|
||||
-- @treturn number the y-coordinate of the `node`
|
||||
-- @usage local y = node:getY()
|
||||
function Node:getY() return self._y end
|
||||
|
||||
function Node:getZ() return self._z end
|
||||
|
||||
--- Returns x and y coordinates of a `node`
|
||||
-- @class function
|
||||
-- @treturn number the x-coordinate of the `node`
|
||||
-- @treturn number the y-coordinate of the `node`
|
||||
-- @usage local x, y = node:getPos()
|
||||
function Node:getPos() return self._x, self._y, self._z end
|
||||
function Node:getX() return self.x end
|
||||
function Node:getY() return self.y end
|
||||
function Node:getZ() return self.z end
|
||||
|
||||
--- Clears temporary cached attributes of a `node`.
|
||||
-- Deletes the attributes cached within a given node after a pathfinding call.
|
||||
-- This function is internally used by the search algorithms, so you should not use it explicitely.
|
||||
-- @class function
|
||||
-- @treturn node self (the calling `node` itself, can be chained)
|
||||
-- @usage
|
||||
-- local thisNode = Node(1,2)
|
||||
-- thisNode:reset()
|
||||
function Node:reset()
|
||||
self._g, self._h, self._f = nil, nil, nil
|
||||
self._opened, self._closed, self._parent = nil, nil, nil
|
||||
|
||||
Reference in New Issue
Block a user