Nearest Available Port for a Node from Stored Array

Hi @walter,

  1. Consider an array of ports, I have a start node, using which I need to find the port that is nearest in the stored array of ports.

  2. Consider an array of ports, I have a port from a node. I need to find a port that is nearest to the port of the start node in the stored array of ports.

Can you provide an example for these scenarios…

Is the only difference between the two questions whether you want to find the port that is (1) closest to a node or (2) closest to a port of a node?

Use the GraphObject.findDocumentPoint method to get a Point in document coordinates for any GraphObject in a Diagram.

I would just iterate to find the distances between each port and the start node/port and find out which one is closest. Note that you don’t need to call Math.sqrt, because you can compare the squares of the distances. For example, in the Seating Chart sample, Seating Chart, look at the findClosestUnoccupiedSeat function, which has the basic idea.