Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-code committed Jan 12, 2016
1 parent 5fb3706 commit 138578e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
37 changes: 25 additions & 12 deletions Graphoon/Graph.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
local current = (...):gsub('%.[^%.]+$', '');

-- ------------------------------------------------
-- Required Modules
-- ------------------------------------------------

local Node = require(current .. '.Node');
local Edge = require(current .. '.Edge');

-- ------------------------------------------------
-- Module
-- ------------------------------------------------

local Graph = {};

function Graph.new()
local self = {};

local nodes = {};
local edges = {};
local edgeIDs = 0;
local nodes = {}; -- Contains all nodes in the graph.
local edges = {}; -- Contains all edges in the graph.
local edgeIDs = 0; -- Used to create a unique ID for new edges.

local minX, maxX, minY, maxY;
local minX, maxX, minY, maxY; -- The boundaries of the graph.

-- ------------------------------------------------
-- Local Functions
-- ------------------------------------------------

---
-- Sets the graph's boundaries to nil.
-- (Re-)Sets the graph's boundaries to nil.
--
local function resetBoundaries()
minX, maxX, minY, maxY = nil, nil, nil, nil;
end

---
-- Updates the boundaries of the graph.
-- This represents the rectangular area in which all nodes are contained.
-- @param minX - The current minimum x position.
-- @param maxX - The current maximum y position.
-- @param minY - The current minimum x position.
Expand Down Expand Up @@ -58,11 +69,12 @@ function Graph.new()
-- ------------------------------------------------

---
-- Add a node to the graph.
-- Adds a node to the graph.
-- @param id - The ID will be used to reference the Node inside of the graph.
-- @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).
-- @param ... - Additional parameters (useful when a custom Node class is used).
--
function self:addNode( id, x, y, anchor, ... )
assert( not nodes[id], "Node IDs must be unique." );
Expand All @@ -71,8 +83,9 @@ function Graph.new()
end

---
-- Remove a node from the graph.
-- This will also remove all edges pointing to or originating from this node.
-- Removes a node from the graph.
-- This will also remove all edges pointing to, or originating from this
-- node.
-- @param node - The node to remove from the graph.
--
function self:removeNode( node )
Expand Down Expand Up @@ -102,7 +115,7 @@ function Graph.new()
end

---
-- Removes all edges leading to or originating from a node.
-- Removes all edges leading to, or originating from a node.
-- @param node - The node to remove all edges from.
--
function self:removeEdges( node )
Expand All @@ -116,8 +129,8 @@ function Graph.new()
---
-- Updates the graph.
-- @param dt - The delta time between frames.
-- @param nodeCallback - A callback called on every node.
-- @param edgeCallback - A callback called on every edge.
-- @param nodeCallback - A callback called on every node (optional).
-- @param edgeCallback - A callback called on every edge (optional).
--
function self:update( dt, nodeCallback, edgeCallback )
for _, edge in pairs( edges ) do
Expand Down Expand Up @@ -220,7 +233,7 @@ function Graph.new()
-- 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.
-- @param y - The y coordinate to anchor the node to.
--
function self:setAnchor( id, x, y )
nodes[id]:setPosition( x, y );
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ Or by using the ```setAnchor``` function:

```lua
-- Invert anchor status
node:setAnchor( not node:isAnchor() )
node:setAnchor( not node:isAnchor(), mouseX, mouseY )
```

0 comments on commit 138578e

Please sign in to comment.