Graph
This graph chain stores one to one relationships, with methods to iterate
the chain in two directions. This allows use to grab the standard A -> B -> C,
and C -> B -> A.
// some points
const head = new Point()
const points = new PointList(head, ...others)
// setup connections
const g = new GraphConnections;
g.connect(0, 1, 2, 3, 4)
g.connect(2, 5)
g.connect(5, 6, 7, 8)
Iterate one-to-one relationships (a depth of 1):
let ps = points
g.forPair((_a, _b)=>{
followPoint( ps.getById(_a), ps.getById(_b), 50)
}, this.reverse)
Provide a forward function, walking thourhg the chain start from the chosen head:
let head = this.g.head.uuid
let ps = points
let f = (key,fromKey,a)=>{
followPoint( ps.getById(fromKey), ps.getById(key), 50)
}
g.getForward(head, f)
Manual iteration:
let ps = points
let forwardGraph = g.forward
for(let k in forwardGraph) {
let v = forwardGraph[k]
for(let i of v) {
followPoint(ps[parseInt(k)], ps[parseInt(i)], 50)
}
}
Capture re-visits for deeper chains.
const graphChain = function(head, ps) {
let visits = {}
let pairCallback = (key, fromKey, allTargets)=>{
constraints.distance(ps[fromKey], ps[key], 50)
if(visits[fromKey] == undefined) { visits[fromKey] = 0 }
if(visits[key] == undefined) { visits[key] = 0 }
visits[fromKey] += 1
visits[key] += 1
}
g.walkForward(head, pairCallback)
}
graphChain(head, points)
The graph can resolve a "star based" configuration:
A C
\ /
B
|
D
|
E
Each connection is given in a pair, from an origin node (the head)
head = B
B -> C
B -> D [ -> E ]
D -> E
B -> A
Where it's used
The followPoint method allows a point to follow another point, at a distance.
This is a lot like constraints but with a one to one relationship in a single
direction.
Meta Data
| title | Graph |
| dependencies | () |
| unused_keys | () |
| unknown_keys | () |
| filepath_exists | True |
| path | graph-connections |
| filepath | graph-connections.js |
| clean_files | () |