mirror of
https://github.com/rm-code/Graphoon.git
synced 2024-11-16 18:24:22 +00:00
Throw error if added edges are invalid
This is the case if both the origin and the target of the edge point to the same node or if an edge already exists between two nodes.
This commit is contained in:
parent
805278d67a
commit
89b6c16974
@ -31,6 +31,13 @@ function Graph.new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function self:addEdge( origin, target )
|
function self:addEdge( origin, target )
|
||||||
|
for _, edge in pairs(edges) do
|
||||||
|
if edge.origin == origin and edge.target == target then
|
||||||
|
error "Trying to connect nodes which are already connected.";
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(origin ~= target, "Tried to connect a node with itself.");
|
||||||
edges[edgeIDs] = Edge.new( edgeIDs, origin, target );
|
edges[edgeIDs] = Edge.new( edgeIDs, origin, target );
|
||||||
edgeIDs = edgeIDs + 1;
|
edgeIDs = edgeIDs + 1;
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user