mirror of
https://github.com/rm-code/Graphoon.git
synced 2024-11-16 18:24:22 +00:00
Update documentation
This commit is contained in:
parent
dba6a49587
commit
99850a423a
22
fd/Graph.lua
22
fd/Graph.lua
@ -68,9 +68,10 @@ function Graph.new()
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- Add a node to the graph.
|
-- Add a node to the graph.
|
||||||
-- @param node - The node to add to the graph.
|
-- @param id - The ID will be used to reference the Node inside of the graph.
|
||||||
-- @param x - The x-coordinate at which to place the new node.
|
-- @param x - The x coordinate the Node should be spawned at (optional).
|
||||||
-- @param y - The y-coordinate at which to place the new node.
|
-- @param y - The y coordinate the Node should be spawned at (optional).
|
||||||
|
-- @param anchor - Wether the node should be locked in place or not (optional).
|
||||||
--
|
--
|
||||||
function self:addNode( id, x, y, anchor )
|
function self:addNode( id, x, y, anchor )
|
||||||
assert( not nodes[id], "Node IDs must be unique." );
|
assert( not nodes[id], "Node IDs must be unique." );
|
||||||
@ -79,8 +80,8 @@ function Graph.new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Remove a node from the graph. This will also remove all edges pointing to
|
-- Remove a node from the graph.
|
||||||
-- or originating from this node.
|
-- This will also remove all edges pointing to or originating from this node.
|
||||||
-- @param node - The node to remove from the graph.
|
-- @param node - The node to remove from the graph.
|
||||||
--
|
--
|
||||||
function self:removeNode( node )
|
function self:removeNode( node )
|
||||||
@ -164,7 +165,8 @@ function Graph.new()
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- Returns the node the id is pointing to.
|
-- Returns the node the id is pointing to.
|
||||||
-- param id - The id to check for.
|
-- @param id - The id to check for.
|
||||||
|
--
|
||||||
function self:getNode( id )
|
function self:getNode( id )
|
||||||
return nodes[id];
|
return nodes[id];
|
||||||
end
|
end
|
||||||
@ -198,6 +200,14 @@ function Graph.new()
|
|||||||
return ( ( maxX - minX ) * 0.5 ) + minX, ( ( maxY - minY ) * 0.5 ) + minY;
|
return ( ( maxX - minX ) * 0.5 ) + minX, ( ( maxY - minY ) * 0.5 ) + minY;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Turn a node into an anchor.
|
||||||
|
-- Anchored nodes have fixed positions and can't be moved by the physical
|
||||||
|
-- forces.
|
||||||
|
-- @param id - The node's id.
|
||||||
|
-- @param x - The x coordinate to anchor the node to.
|
||||||
|
-- @param y - The x coordinate to anchor the node to.
|
||||||
|
--
|
||||||
function self:setAnchor( id, x, y )
|
function self:setAnchor( id, x, y )
|
||||||
nodes[id]:setPosition( x, y );
|
nodes[id]:setPosition( x, y );
|
||||||
nodes[id]:setAnchor( true );
|
nodes[id]:setAnchor( true );
|
||||||
|
15
fd/Node.lua
15
fd/Node.lua
@ -11,6 +11,9 @@ local DEFAULT_MASS = 0.05;
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param id - A unique id which will be used to reference this node.
|
-- @param id - A unique id which will be used to reference this node.
|
||||||
|
-- @param x - The x coordinate the Node should be spawned at (optional).
|
||||||
|
-- @param y - The y coordinate the Node should be spawned at (optional).
|
||||||
|
-- @param anchor - Wether the node should be locked in place or not (optional).
|
||||||
--
|
--
|
||||||
function Node.new( id, x, y, anchor )
|
function Node.new( id, x, y, anchor )
|
||||||
local self = {};
|
local self = {};
|
||||||
@ -40,6 +43,10 @@ function Node.new( id, x, y, anchor )
|
|||||||
ay = clamp( -FORCE_MAX, ay + fy, FORCE_MAX );
|
ay = clamp( -FORCE_MAX, ay + fy, FORCE_MAX );
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Attract this node to another node.
|
||||||
|
-- @param node - The node to use for force calculation.
|
||||||
|
--
|
||||||
function self:attractTo( node )
|
function self:attractTo( node )
|
||||||
local dx, dy = px - node:getX(), py - node:getY();
|
local dx, dy = px - node:getX(), py - node:getY();
|
||||||
local distance = math.sqrt(dx * dx + dy * dy);
|
local distance = math.sqrt(dx * dx + dy * dy);
|
||||||
@ -50,6 +57,10 @@ function Node.new( id, x, y, anchor )
|
|||||||
applyForce( dx * strength, dy * strength );
|
applyForce( dx * strength, dy * strength );
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Repel this node from another node.
|
||||||
|
-- @param node - The node to use for force calculation.
|
||||||
|
--
|
||||||
function self:repelFrom( node )
|
function self:repelFrom( node )
|
||||||
local dx, dy = px - node:getX(), py - node:getY();
|
local dx, dy = px - node:getX(), py - node:getY();
|
||||||
local distance = math.sqrt(dx * dx + dy * dy);
|
local distance = math.sqrt(dx * dx + dy * dy);
|
||||||
@ -63,6 +74,7 @@ function Node.new( id, x, y, anchor )
|
|||||||
---
|
---
|
||||||
-- Update the node's position based on the calculated velocity and
|
-- Update the node's position based on the calculated velocity and
|
||||||
-- acceleration.
|
-- acceleration.
|
||||||
|
-- @param dt - The delta time between frames.
|
||||||
--
|
--
|
||||||
function self:move( dt )
|
function self:move( dt )
|
||||||
vx = (vx + ax * dt * NODE_SPEED) * DAMPING_FACTOR;
|
vx = (vx + ax * dt * NODE_SPEED) * DAMPING_FACTOR;
|
||||||
@ -72,9 +84,6 @@ function Node.new( id, x, y, anchor )
|
|||||||
ax, ay = 0, 0;
|
ax, ay = 0, 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
|
||||||
-- Returns the node's unique identifier.
|
|
||||||
--
|
|
||||||
function self:getID()
|
function self:getID()
|
||||||
return id;
|
return id;
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user