Allow anchor flag to be set when a Node is created

This commit is contained in:
Robert Machmer 2016-01-03 02:25:54 +01:00
parent f5931d5ce8
commit e6154ba5ea
2 changed files with 4 additions and 5 deletions

View File

@ -57,7 +57,7 @@ function Graph.new()
if type( node ) == 'string' then if type( node ) == 'string' then
self:addNode( node, nil, rx, ry ); self:addNode( node, nil, rx, ry );
elseif type( node ) == 'table' then elseif type( node ) == 'table' then
self:addNode( node.id, node.name, node.x or rx, node.y or ry ); self:addNode( node.id, node.name, node.x or rx, node.y or ry, node.anchor );
end end
end end
@ -72,9 +72,9 @@ function Graph.new()
-- @param x - The x-coordinate at which to place the new node. -- @param x - The x-coordinate at which to place the new node.
-- @param y - The y-coordinate at which to place the new node. -- @param y - The y-coordinate at which to place the new node.
-- --
function self:addNode( id, name, x, y ) function self:addNode( id, name, x, y, anchor )
assert( not nodes[id], "Node IDs must be unique." ); assert( not nodes[id], "Node IDs must be unique." );
nodes[id] = Node.new( id, name, x, y ); nodes[id] = Node.new( id, name, x, y, anchor );
return nodes[id]; return nodes[id];
end end

View File

@ -12,11 +12,10 @@ 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.
-- --
function Node.new( id, name, x, y ) function Node.new( id, name, x, y, anchor )
local self = {}; local self = {};
local name = name or id; local name = name or id;
local anchor = false;
local px, py = x or 0, y or 0; local px, py = x or 0, y or 0;
local ax, ay = 0, 0; local ax, ay = 0, 0;
local vx, vy = 0, 0; local vx, vy = 0, 0;