def test_polygonf(): poly = gui.PolygonF() poly.add_points((0, 0), (2, 0), (2, 1), (0, 1)) poly2 = gui.PolygonF() poly2.add_points((1, 0), (3, 0), (3, 1), (1, 1)) with open("data.pkl", "wb") as jar: pickle.dump(poly, jar) with open("data.pkl", "rb") as jar: poly = pickle.load(jar) union = poly | poly2 intersect = poly & poly2 sub = union - intersect xor = poly ^ poly2 assert sub == xor polygon = poly.to_polygon() assert type(polygon) == gui.Polygon poly.add_points((0, 1), core.Point(2, 2)) bytes(poly)
def create_diamond(cls): points = [ core.PointF(0.4, 0.5), core.PointF(0.5, 0.4), core.PointF(0.6, 0.5), core.PointF(0.5, 0.6), core.PointF(0.4, 0.5), ] poly = gui.PolygonF() poly.add_points(*points) return poly
def add_polygon( self, polygon: QtGui.QPolygonF | QtGui.QPolygon, pen: QtGui.QPen | None = None, brush: QtGui.QBrush | None = None, ) -> widgets.GraphicsPolygonItem: if isinstance(polygon, QtGui.QPolygon): polygon = gui.PolygonF(polygon) g_item = widgets.GraphicsPolygonItem() g_item.setPolygon(polygon) if brush is not None: g_item.setBrush(brush) if pen is not None: g_item.setPen(pen) self.addItem(g_item) return g_item
def test_polygonf(): poly = gui.PolygonF() with open("data.pkl", "wb") as jar: pickle.dump(poly, jar) with open("data.pkl", "rb") as jar: poly = pickle.load(jar)
def get_polygon(self) -> gui.PolygonF: return gui.PolygonF(self.polygon())