MCPcopy Index your code
hub / github.com/clips/pattern / _attract

Method _attract

pattern/graph/__init__.py:647–657  ·  view source on GitHub ↗
(self, node1, node2, weight=0, length=1.0)

Source from the content-addressed store, hash-verified

645 node1.force.y -= f * dy
646
647 def _attract(self, node1, node2, weight=0, length=1.0):
648 # Updates Node.force with the attractive edge force.
649 dx, dy, d, d2 = self._distance(node1, node2)
650 d = min(d, self.repulsion)
651 f = (d2 - self.k**2) / self.k * length
652 f *= weight * 0.5 + 1
653 f /= d
654 node2.force.x -= f * dx
655 node2.force.y -= f * dy
656 node1.force.x += f * dx
657 node1.force.y += f * dy
658
659 def update(self, weight=10.0, limit=0.5):
660 """ Updates the position of nodes in the graph.

Callers 2

updateMethod · 0.95
graph.jsFile · 0.80

Calls 1

_distanceMethod · 0.95

Tested by

no test coverage detected