Пример #1
0
 def render(self, r: Renderer) -> None:
     c = self.get_center_point()
     a = GeometryUtil.distance_from_point(c, self.get_right_point())
     b = GeometryUtil.distance_from_point(c, self.get_bottom_point())
     points = []
     n_points = 72
     for x in range(n_points + 1):
         points.append(
             Point(c.x + a * math.cos(x * 2 * math.pi / n_points), c.y + b * math.sin(x * 2 * math.pi / n_points)))
     r.fill_polygon(points)
Пример #2
0
    def selection_distance(self, mouse_point: Point) -> float:
        c = self.get_center_point()
        a = GeometryUtil.distance_from_point(c, self.get_right_point())
        b = GeometryUtil.distance_from_point(c, self.get_bottom_point())
        if (mouse_point.x - c.x) ** 2 / a ** 2 + (mouse_point.y - c.y) ** 2 / b ** 2 <= 1:
            return 0

        min_distance = -1
        n_points = 72
        for x in range(n_points):
            p_x = Point(c.x + a * math.cos(x * 2 * math.pi / n_points), c.y + b * math.sin(x * 2 * math.pi / n_points))
            distance = GeometryUtil.distance_from_point(p_x, mouse_point)
            if min_distance == -1 or min_distance > distance:
                min_distance = distance

        return min_distance
Пример #3
0
    def get_bounding_box(self) -> Rectangle:
        points = []
        for child in self._children:
            bbox = child.get_bounding_box()
            points.append(Point(bbox.x, bbox.y))
            points.append(Point(bbox.x + bbox.width, bbox.y + bbox.height))

        return GeometryUtil.bounding_box_from_points(points)
Пример #4
0
    def mouse_dragged(self, mouse_point: Point) -> None:
        if GeometryUtil.distance_from_point(mouse_point,
                                            self._last_point_added) > 10:
            interpolated = Point(
                (self._last_point_added.x + mouse_point.x) / 2,
                (self._last_point_added.y + mouse_point.y) / 2)
            self.mouse_dragged(interpolated)
            self.mouse_dragged(mouse_point)
            return

        if mouse_point not in self._points:
            self._points.add(mouse_point)
            self._canvas.draw_line(self._last_point_added, mouse_point)
            self._last_point_added = mouse_point
            self._objects.extend([
                go for go in self._dm.get_objects() if go not in self._objects
                and go.selection_distance(mouse_point) < 5
            ])
Пример #5
0
 def get_hot_point_distance(self, index: int, mouse_point: Point) -> float:
     return GeometryUtil.distance_from_point(self.hot_points[index],
                                             mouse_point)
Пример #6
0
 def after_draw_done(self, r: Renderer):
     selected_objects = self._dm.get_selected_objects()
     if len(selected_objects) == 1:
         GeometryUtil.render_hot_points(r, selected_objects[0])
Пример #7
0
 def after_draw(self, r: Renderer, go: GraphicalObject):
     if go.is_selected():
         GeometryUtil.render_rectangle(r, go.get_bounding_box())
Пример #8
0
 def selection_distance(self, mouse_point: Point) -> float:
     return GeometryUtil.distance_from_line_segment(self.get_start(),
                                                    self.get_end(),
                                                    mouse_point)
Пример #9
0
 def get_bounding_box(self) -> Rectangle:
     return GeometryUtil.bounding_box_from_points(self.hot_points)
Пример #10
0
 def get_bounding_box(self) -> Rectangle:
     c = self.get_center_point()
     right_to_center = c.difference(self.get_right_point())
     bottom_to_center = c.difference(self.get_bottom_point())
     top_left_corner = c.translate(right_to_center).translate(bottom_to_center)
     return GeometryUtil.bounding_box_from_points([self.get_bottom_point(), self.get_right_point(), top_left_corner])