Esempio n. 1
0
 def point(self, pos):
     """Given a point (x, y) return the distance to the canvas item."""
     d0 = super().point(pos)
     ds = [
         distance_rectangle_point(shape, pos) for shape in (
             self._shape_head_rect,
             self._shape_middle_rect,
             self._shape_tail_rect,
         ) if shape
     ]
     return min(d0, *ds) if ds else d0
Esempio n. 2
0
    def point(self, x: float, y: float) -> float:
        """Distance from the point (x, y) to the item.

        >>> e = Element()
        >>> e.point(20, 10)
        10.0
        """
        h = self._handles
        x0, y0 = h[NW].pos
        x1, y1 = h[SE].pos
        return distance_rectangle_point((x0, y0, x1 - x0, y1 - y0), (x, y))
Esempio n. 3
0
    def point(self, pos):
        """
        Distance from the point (x, y) to the item.

        >>> e = Element()
        >>> e.point((20, 10))
        10.0
        """
        h = self._handles
        pnw, pse = h[NW].pos, h[SE].pos
        return distance_rectangle_point(
            list(map(float, (pnw.x, pnw.y, pse.x, pse.y))), pos)
Esempio n. 4
0
 def get_handle_at_point(self, pos, distance=None):
     if not distance:
         distance = 0
     for handle in self.item.handles():
         port_v = self.item.get_port_for_handle(handle)
         if port_v:  # Either a data port or a logical port
             port_area = port_v.get_port_area(self.view)
             if distance_rectangle_point(port_area, pos) <= distance:
                 return self.item, handle
         else:
             item, handle = self._check_for_resize_handle(
                 handle, pos, distance)
             if item:
                 return item, handle
     return None, None
Esempio n. 5
0
 def distances():
     yield 10000.0
     for txt in self._texts:
         if txt.is_visible() and txt.editable:
             yield distance_rectangle_point(txt.bounds, pos)
Esempio n. 6
0
 def distances():
     yield 10000.0
     for txt in self._texts:
         if txt.is_visible() and txt.editable:
             yield distance_rectangle_point(txt.bounds, pos)
Esempio n. 7
0
 def point(self, pos):
     return distance_rectangle_point(self.dimensions(), pos)
Esempio n. 8
0
def test_distance_rectangle_point():
    assert distance_rectangle_point((2, 0, 2, 2), (0, 0)) == 2
Esempio n. 9
0
def test_distance_with_negative_numbers_in_rectangle():
    assert distance_rectangle_point((-50, -100, 100, 100), (-17, -65)) == 0
Esempio n. 10
0
def test_distance_point_in_rectangle():
    assert distance_rectangle_point((0, 0, 2, 2), (1, 1)) == 0
Esempio n. 11
0
 def point(self, x, y):
     return distance_rectangle_point(self.dimensions(), (x, y))