Add optional name parameter for Nodes

This parameter can be accessed via the getName getter. If no value is
passed to the constructor the name variable will default to the id.
This commit is contained in:
Robert Machmer 2015-12-24 16:56:32 +01:00
parent 35868a4360
commit 59a055da99
2 changed files with 8 additions and 3 deletions

View File

@ -70,9 +70,9 @@ function Graph.new()
-- @param x - The x-coordinate at which to place the new node.
-- @param y - The y-coordinate at which to place the new node.
--
function self:addNode( id, x, y )
function self:addNode( id, name, x, y )
assert( not nodes[id], "Node IDs must be unique." );
nodes[id] = Node.new( id, x, y );
nodes[id] = Node.new( id, name, x, y );
end
---

View File

@ -12,9 +12,10 @@ local DEFAULT_MASS = 0.05;
---
-- @param id - A unique id which will be used to reference this node.
--
function Node.new( id, x, y )
function Node.new( id, name, x, y )
local self = {};
local name = name or id;
local px, py = x or 0, y or 0;
local ax, ay = 0, 0;
local vx, vy = 0, 0;
@ -79,6 +80,10 @@ function Node.new( id, x, y )
return id;
end
function self:getName()
return name;
end
function self:getX()
return px;
end