def getNodeDimensions(self, node): try: nodeX = float(node.attrib["x"]) nodeY = float(node.attrib["y"]) nodeWidth = float(node.attrib["width"]) nodeHeight = float(node.attrib["height"]) except Exception: try: (nodeMinX, nodeMaxX, nodeMinY, nodeMaxY) = \ simpletransform.roughBBox(node.attrib["d"]) except Exception: (nodeMinX, nodeMaxX, nodeMinY, nodeMaxY) = \ simpletransform.roughBBox( cubicsuperpath.CubicSuperPath( simplepath.parsePath(node.attrib["d"]) ) ) nodeX = nodeMinX nodeY = nodeMinY nodeWidth = nodeMaxX - nodeMinX nodeHeight = nodeMaxY - nodeMinY return nodeX, nodeY, nodeWidth, nodeHeight
def morphPath( path, axes ): bounds = simpletransform.roughBBox( cubicsuperpath.CubicSuperPath(path) ) newPath = [] current = [ 0.0, 0.0 ] start = [ 0.0, 0.0 ] for cmd, params in path: segmentType = cmd points = params if segmentType == "M": start[0] = points[0] start[1] = points[1] segmentType = convertSegmentToCubic( current, segmentType, points, start ) percentages = [0.0]*len(points) morphed = [0.0]*len(points) numPts = getNumPts( segmentType ) normalizePoints( bounds, points, percentages, numPts ) mapPointsToMorph( axes, percentages, morphed, numPts ) addSegment( newPath, segmentType, morphed ) if len(points) >= 2: current[0] = points[ len(points)-2 ] current[1] = points[ len(points)-1 ] return newPath
def morphPath(path, axes): bounds = simpletransform.roughBBox(cubicsuperpath.CubicSuperPath(path)) newPath = [] current = [0.0, 0.0] start = [0.0, 0.0] for cmd, params in path: segmentType = cmd points = params if segmentType == "M": start[0] = points[0] start[1] = points[1] segmentType = convertSegmentToCubic(current, segmentType, points, start) percentages = [0.0] * len(points) morphed = [0.0] * len(points) numPts = getNumPts(segmentType) normalizePoints(bounds, points, percentages, numPts) mapPointsToMorph(axes, percentages, morphed, numPts) addSegment(newPath, segmentType, morphed) if len(points) >= 2: current[0] = points[len(points) - 2] current[1] = points[len(points) - 1] return newPath
def boundingBox(self): csp = cubicsuperpath.CubicSuperPath(self.data) self.bbox = list(simpletransform.roughBBox(csp)) return list(simpletransform.roughBBox(csp)) # [minx,maxx,miny,maxy]
def dxf_path_to_point(self,layer,p): bbox = simpletransform.roughBBox(p) x = (bbox[0] + bbox[1]) / 2 y = (bbox[2] + bbox[3]) / 2 self.dxf_point(layer,x,y)