Class: Edge

Edge()

The edge class defines edges used by our graph diagram class. Note that this is mostly geometric as our node class itself recursively stores the nodes connected as inputs/outputs. The edge class is used mainly for actual drawing of edges and occasionally collisions info.

Constructor

new Edge()

Construct an edge object.
Source:

Members

collisionRadius

Used for determining the radius at which collisions can occr.
Source:

from

The coord this edge starts from.
Source:

polyLineList

Polyline list of segments connecting the from/to coords of this edge.
Source:

to

The coord this edge ends to.
Source:

Methods

addSegment(n)

Add a segment to the end of our polyline. In other words extend the edge by adding a segment to it.
Parameters:
Name Type Description
n object The coord point to add to the edge.
Source:

arrow_helper(ctx, from, to)

Helper to draw arrows on segments to show edge directions.
Parameters:
Name Type Description
ctx object The canvas context to be drawn to.
from object Point for from direction of arrow.
to object Point for to direction of arrow.
Source:

collision(pt)

Detect if the input point collides with this edge.
Parameters:
Name Type Description
pt object The point to test edge collision against.
Source:
Returns:
True if input point collides with this edge and false otherwise.

draw(ctx)

Draw this edge to the supplied canvas context.
Parameters:
Name Type Description
ctx object The canvas context to be drawn to.
Source:

empty()

Return true if this edge has an empty polyline. This occurs only if no points have been added to the current edge for connection.
Source:
Returns:
true if empty polyline list else false.

getFrom()

Get the from coord of this edge.
Source:

getTo()

Get the to coord of this edge.
Source:
Returns:
The to coord of this edge.

intersectSegment(A, B, C, radius)

Returns true if line segment thru AB intercepts the circle of given radius at C or false otherwise.
Parameters:
Name Type Description
A object The starting point of the segment to detect collision on.
B object The ending point of the segment to detect collision on.
C object The point to test segment collision with.
radius number The radius in which collisions may occur.
Source:
Returns:
True if line segment thru AB intercepts the circle centered at C of the given radius else false.

reconfigure(file)

Set up the state of the widget based on the input file.
Parameters:
Name Type Description
file object The file as an array of strings to load the edge from.
Source:

reverse()

Reverse the direction of this edge.
Source:

setFrom(n)

Set the from coord of this edge.
Parameters:
Name Type Description
n object The coord point to set from with.
Source:

setTo(n)

Set the to coord of this edge.
Parameters:
Name Type Description
n object The coord point to set to with.
Source:

toText()

Converts the given edge to a textual representation.
Source:
Returns:
JSON representation of the edge in a string.