MCPcopy Create free account
hub / github.com/daft-dev/daft / get_frontier_coord

Method get_frontier_coord

daft.py:783–859  ·  view source on GitHub ↗

Get the coordinates of the point of intersection between the shape of the node and a line starting from the center of the node to an arbitrary point. Will throw a :class:`SameLocationError` if the nodes contain the same `x` and `y` coordinates. See the example of rec

(self, target_xy, ctx, edge)

Source from the content-addressed store, hash-verified

781 return el
782
783 def get_frontier_coord(self, target_xy, ctx, edge):
784 """
785 Get the coordinates of the point of intersection between the
786 shape of the node and a line starting from the center of the node to an
787 arbitrary point. Will throw a :class:`SameLocationError` if the nodes
788 contain the same `x` and `y` coordinates. See the example of rectangle
789 below:
790
791 .. code-block:: python
792
793 _____________
794 | | ____--X (target_node)
795 | __--X----
796 | X-- |(return coordinate of this point)
797 | |
798 |____________|
799
800 :target_xy: (x float, y float)
801 A tuple of coordinate of target node
802
803 """
804
805 # Scale the coordinates appropriately.
806 x1, y1 = ctx.convert(self.x, self.y)
807 x2, y2 = target_xy[0], target_xy[1]
808
809 # Aspect ratios.
810 if self.aspect is not None:
811 aspect = self.aspect
812 else:
813 aspect = ctx.aspect
814
815 if self.shape == "ellipse":
816 # Compute the distances.
817 dx, dy = x2 - x1, y2 - y1
818 if dx == 0.0 and dy == 0.0:
819 raise SameLocationError(edge)
820 dist1 = np.sqrt(dy * dy + dx * dx / float(aspect * aspect))
821
822 # Compute the fractional effect of the radii of the nodes.
823 alpha1 = 0.5 * ctx.node_unit * self.scale / dist1
824
825 # Get the coordinates of the starting position.
826 x0, y0 = x1 + alpha1 * dx, y1 + alpha1 * dy
827
828 return x0, y0
829
830 elif self.shape == "rectangle":
831
832 dx, dy = x2 - x1, y2 - y1
833
834 # theta = np.angle(complex(dx, dy))
835 # print(theta)
836 # left or right intersection
837 dxx1 = self.scale * aspect / 2.0 * (np.sign(dx) or 1.0)
838 dyy1 = (
839 self.scale
840 * aspect

Callers 1

_get_coordsMethod · 0.80

Calls 2

SameLocationErrorClass · 0.85
convertMethod · 0.80

Tested by

no test coverage detected