def inscribedRegPolygon(cls, sides, position, radius, starting_rad, qpoly=False): pos_x, pos_y = PrimitiveShape.pos_to_tuple(position) lkList = ['--'] * sides ptsList = [] for ang in numpy.linspace(starting_rad, starting_rad + math.tau, sides, endpoint=False): ptsList.append((pos_x + radius * math.cos(ang), pos_y + radius * math.sin(ang))) if qpoly: ptsList.append((pos_x + radius * math.cos(starting_rad), pos_y + radius * math.sin(starting_rad))) qpoints = [QtCore.QPointF(x, y) for (x, y) in ptsList] return QtGui.QPolygonF(qpoints) else: ptsList.append('cycle') newPoly = xasy2asy.asyPath() newPoly.initFromNodeList(ptsList, lkList) return newPoly
def circle(cls, position, radius): pos_x, pos_y = PrimitiveShape.pos_to_tuple(position) newCircle = x2a.asyPath() ptsList = [(pos_x + radius, pos_y), (pos_x, pos_y + radius), (pos_x - radius, pos_y), (pos_x, pos_y - radius), 'cycle'] # cycle doesn't work for now. lkList = ['..', '..', '..', '..'] newCircle.initFromNodeList(ptsList, lkList) return newCircle
def updateBasePathPreview(self): self.basePathPreview = x2a.asyPath(asyengine=self.asyengine, forceCurve=self.useBezierBase) newNode = [(x, y) for x, y, _ in self.pointsList ] + [(self.currentPoint.x(), self.currentPoint.y())] newLink = [lnk for *args, lnk in self.pointsList[1:] ] + [self._getLinkType()] if self.closedPath: newNode.append('cycle') newLink.append(self._getLinkType()) self.basePathPreview.initFromNodeList(newNode, newLink) if self.useBezierBase: self.basePathPreview.computeControls()