Ravenous
Ravenous

Reputation: 1160

Cytoscape.js - Obtain a valid position for programmatically spawned node

Given that all nodes are locked and the layout doesn't matter.

Is there any existing solution that would be able to obtain a pool of valid positions for a programmatically spawned node (no coordinates available) that guarantees no overlapping with the locked nodes?

Upvotes: 0

Views: 110

Answers (1)

Nuclearman
Nuclearman

Reputation: 5314

Not really familiar with cytoscape, but a quick look suggests that you could triangulate the points and then you have two insertion options within the convex hull of the locked points (if you are actually doing with a rectangular region, you could add the 4 corners as additional virtual points):

  • A node can be placed if there is enough space for it on any edge of the triangulation (half node 1 radius + half node 2 radius + insert node radius + some padding distance).
  • You can also consider insertion at the center point of any triangle within the triangulation, if there is room. Those are your two main options for insertion within the convex hull of the locked points.

Those are the two easiest to calculate kinds of potential valid positions.

Upvotes: 2

Related Questions