def overpadsBounds(self, pads=None): bb = BoundingBox() if pads == None: pads = self.pads for pad in pads: pos = pad['pos'] px = pos['x'] py = pos['y'] # Pad outer dimensions sx = pad['size']['x'] sy = pad['size']['y'] angle = pad['pos']['orientation'] # Add each "corner" of the pad (even for oval shapes) p1 = _rotatePoint({'x': -sx / 2, 'y': -sy / 2}, angle) p2 = _rotatePoint({'x': -sx / 2, 'y': +sy / 2}, angle) p3 = _rotatePoint({'x': +sx / 2, 'y': +sy / 2}, angle) p4 = _rotatePoint({'x': +sx / 2, 'y': -sy / 2}, angle) points = [p1, p2, p3, p4] for p in points: x = px + p['x'] y = py + p['y'] bb.addPoint(x, y) return bb
def overpadsBounds(self, pads=None): bb = BoundingBox() if pads == None: pads = self.pads for pad in pads: pos = pad['pos'] px = pos['x'] py = pos['y'] # Pad outer dimensions sx = pad['size']['x'] sy = pad['size']['y'] angle = pad['pos']['orientation'] # Add each "corner" of the pad (even for oval shapes) p1 = _rotatePoint({'x': -sx/2, 'y': -sy/2}, angle) p2 = _rotatePoint({'x': -sx/2, 'y': +sy/2}, angle) p3 = _rotatePoint({'x': +sx/2, 'y': +sy/2}, angle) p4 = _rotatePoint({'x': +sx/2, 'y': -sy/2}, angle) points = [p1, p2, p3, p4] for p in points: x = px + p['x'] y = py + p['y'] bb.addPoint(x,y) return bb
def geometricBoundingBox(self, layer): bb = BoundingBox() # Add all lines lines = self.filterLines(layer) for l in lines: bb.addPoint(l['start']['x'], l['start']['y']) bb.addPoint(l['end']['x'], l['end']['y']) # Add all circles circles=self.filterCircles(layer) for c in circles: cx = c['center']['x'] cy = c['center']['y'] ex = c['end']['x'] ey = c['end']['y'] dx = ex - cx dy = ey - cy r = math.sqrt(dx*dx + dy*dy) bb.addPoint(cx, cy, radius=r) # Add all arcs arcs=self.filterArcs(layer) for c in arcs: cx = c['start']['x'] cy = c['start']['y'] ex = c['end']['x'] ey = c['end']['y'] dx = ex - cx dy = ey - cy r = math.sqrt(dx*dx + dy*dy) dalpha=1 alphaend=c['angle'] if math.fabs(alphaend)<1: dalpha=math.fabs(alphaend)/5 if alphaend<0: dalpha=-dalpha if math.fabs(alphaend)>0: a=0 c0=[ ex - cx, ey - cy ] #print("c0 = ",c0) while (alphaend>0 and a<=alphaend) or (alphaend<0 and a>=alphaend): c1=[0,0] c1[0]=math.cos(a/180*3.1415)*c0[0]-math.sin(a/180*3.1415)*c0[1] c1[1]=math.sin(a/180*3.1415)*c0[0]+math.cos(a/180*3.1415)*c0[1] bb.addPoint(cx + c1[0], cy + c1[1]) a=a+dalpha bb.addPoint(ex, None) return bb
def padsBounds(self, pads=None): bb = BoundingBox() if pads == None: pads = self.pads for pad in pads: pos = pad['pos'] bb.addPoint(pos['x'], pos['y']) return bb
def padsBounds(self, pads: Optional[List[Dict[str, Any]]] = None) -> BoundingBox: bb = BoundingBox() if pads is None: pads = self.pads for pad in pads: pos = pad["pos"] bb.addPoint(pos["x"], pos["y"]) return bb
def boundingBox(self): """Return the bounding box of the control polygon. """ bb = BoundingBox() for i, p in enumerate(self.pnts): bb.addPoint(p) bb.addPoint(p + self.intangents[i]) bb.addPoint(p + self.outtangents[i]) return bb
def boundingBox(self): """Return the bounding box of the control polygon. """ bb = BoundingBox() for i,p in enumerate(self.pnts): bb.addPoint(p) bb.addPoint(p+self.intangents[i]) bb.addPoint(p+self.outtangents[i]) return bb
def overpadsBounds(self, pads=None): bb = BoundingBox() if pads == None: pads = self.pads for pad in pads: pos = pad['pos'] px = pos['x'] py = pos['y'] # Pad outer dimensions sx = pad['size']['x'] sy = pad['size']['y'] angle = -pad['pos']['orientation'] # Add each "corner" of the pad (even for oval shapes) p1 = _rotatePoint({'x': -sx / 2, 'y': -sy / 2}, angle) p2 = _rotatePoint({'x': -sx / 2, 'y': +sy / 2}, angle) p3 = _rotatePoint({'x': +sx / 2, 'y': +sy / 2}, angle) p4 = _rotatePoint({'x': +sx / 2, 'y': -sy / 2}, angle) points = [p1, p2, p3, p4] # Add more points for custom pad shapes if pad['shape'] == 'custom': for p in pad['primitives']: if p['type'] == 'gr_poly': # Add polygon points for point in p['pts']: points.append(_rotatePoint(point, angle)) elif p['type'] == 'gr_line': # Add line points s = _rotatePoint(p['start'], angle) e = _rotatePoint(p['end'], angle) w = p['width'] points.append(_movePoint(s, { 'x': -w / 2, 'y': -w / 2 })) points.append(_movePoint(s, { 'x': -w / 2, 'y': +w / 2 })) points.append(_movePoint(s, { 'x': +w / 2, 'y': +w / 2 })) points.append(_movePoint(s, { 'x': +w / 2, 'y': -w / 2 })) points.append(_movePoint(e, { 'x': -w / 2, 'y': -w / 2 })) points.append(_movePoint(e, { 'x': -w / 2, 'y': +w / 2 })) points.append(_movePoint(e, { 'x': +w / 2, 'y': +w / 2 })) points.append(_movePoint(e, { 'x': +w / 2, 'y': -w / 2 })) elif p['type'] == 'gr_arc': # Add arc points # TODO pass elif p['type'] == 'gr_circle': # Add circle points c = _rotatePoint(p['center'], angle) e = _rotatePoint(p['end'], angle) r = math.sqrt((e['x'] - c['x'])**2 + (e['y'] - c['y'])**2) w = p['width'] points.append(_movePoint(c, {'x': -r - w / 2, 'y': 0})) points.append(_movePoint(c, {'x': +r + w / 2, 'y': 0})) points.append(_movePoint(c, {'x': 0, 'y': -r - w / 2})) points.append(_movePoint(c, {'x': 0, 'y': +r + w / 2})) for p in points: x = px + p['x'] y = py + p['y'] bb.addPoint(x, y) return bb
def overpadsBounds(self, pads=None): bb = BoundingBox() if pads == None: pads = self.pads for pad in pads: pos = pad['pos'] px = pos['x'] py = pos['y'] # Pad outer dimensions sx = pad['size']['x'] sy = pad['size']['y'] angle = -pad['pos']['orientation'] # Add each "corner" of the pad (even for oval shapes) p1 = _rotatePoint({'x': -sx/2, 'y': -sy/2}, angle) p2 = _rotatePoint({'x': -sx/2, 'y': +sy/2}, angle) p3 = _rotatePoint({'x': +sx/2, 'y': +sy/2}, angle) p4 = _rotatePoint({'x': +sx/2, 'y': -sy/2}, angle) points = [p1, p2, p3, p4] # Add more points for custom pad shapes if pad['shape'] == 'custom': for p in pad['primitives']: if p['type'] == 'gr_poly': # Add polygon points for point in p['pts']: points.append(_rotatePoint(point, angle)) elif p['type'] == 'gr_line': # Add line points s = _rotatePoint(p['start'], angle) e = _rotatePoint(p['end'], angle) w = p['width'] points.append(_movePoint(s, {'x': -w/2, 'y': -w/2})) points.append(_movePoint(s, {'x': -w/2, 'y': +w/2})) points.append(_movePoint(s, {'x': +w/2, 'y': +w/2})) points.append(_movePoint(s, {'x': +w/2, 'y': -w/2})) points.append(_movePoint(e, {'x': -w/2, 'y': -w/2})) points.append(_movePoint(e, {'x': -w/2, 'y': +w/2})) points.append(_movePoint(e, {'x': +w/2, 'y': +w/2})) points.append(_movePoint(e, {'x': +w/2, 'y': -w/2})) elif p['type'] == 'gr_arc': # Add arc points # TODO pass elif p['type'] == 'gr_circle': # Add circle points c = _rotatePoint(p['center'], angle) e = _rotatePoint(p['end'], angle) r = math.sqrt((e['x']-c['x'])**2 + (e['y']-c['y'])**2) w = p['width'] points.append(_movePoint(c, {'x': -r-w/2, 'y': 0})) points.append(_movePoint(c, {'x': +r+w/2, 'y': 0})) points.append(_movePoint(c, {'x': 0, 'y': -r-w/2})) points.append(_movePoint(c, {'x': 0, 'y': +r+w/2})) for p in points: x = px + p['x'] y = py + p['y'] bb.addPoint(x,y) return bb
def overpadsBounds(self, pads: Optional[List[Dict[str, Any]]] = None) -> BoundingBox: bb = BoundingBox() if pads is None: pads = self.pads for pad in pads: pos = pad["pos"] px = pos["x"] py = pos["y"] # Pad outer dimensions sx = pad["size"]["x"] sy = pad["size"]["y"] angle = -pad["pos"]["orientation"] # Add each "corner" of the pad (even for oval shapes) p1 = _rotatePoint({"x": -sx / 2, "y": -sy / 2}, angle) p2 = _rotatePoint({"x": -sx / 2, "y": +sy / 2}, angle) p3 = _rotatePoint({"x": +sx / 2, "y": +sy / 2}, angle) p4 = _rotatePoint({"x": +sx / 2, "y": -sy / 2}, angle) points = [p1, p2, p3, p4] # Add more points for custom pad shapes if pad["shape"] == "custom": for p in pad["primitives"]: if p["type"] == "gr_poly": # Add polygon points for point in p["pts"]: points.append(_rotatePoint(point, angle)) elif p["type"] == "gr_line": # Add line points s = _rotatePoint(p["start"], angle) e = _rotatePoint(p["end"], angle) w = p["width"] points.append(_movePoint(s, { "x": -w / 2, "y": -w / 2 })) points.append(_movePoint(s, { "x": -w / 2, "y": +w / 2 })) points.append(_movePoint(s, { "x": +w / 2, "y": +w / 2 })) points.append(_movePoint(s, { "x": +w / 2, "y": -w / 2 })) points.append(_movePoint(e, { "x": -w / 2, "y": -w / 2 })) points.append(_movePoint(e, { "x": -w / 2, "y": +w / 2 })) points.append(_movePoint(e, { "x": +w / 2, "y": +w / 2 })) points.append(_movePoint(e, { "x": +w / 2, "y": -w / 2 })) elif p["type"] == "gr_arc": # Add arc points # TODO pass elif p["type"] == "gr_circle": # Add circle points c = _rotatePoint(p["center"], angle) e = _rotatePoint(p["end"], angle) r = math.sqrt((e["x"] - c["x"])**2 + (e["y"] - c["y"])**2) w = p["width"] points.append(_movePoint(c, {"x": -r - w / 2, "y": 0})) points.append(_movePoint(c, {"x": +r + w / 2, "y": 0})) points.append(_movePoint(c, {"x": 0, "y": -r - w / 2})) points.append(_movePoint(c, {"x": 0, "y": +r + w / 2})) for p in points: x = px + p["x"] y = py + p["y"] bb.addPoint(x, y) return bb
def geometricBoundingBox(self, layer: str) -> BoundingBox: bb = BoundingBox() # Add all lines lines = self.filterLines(layer) for line in lines: bb.addPoint(line["start"]["x"], line["start"]["y"]) bb.addPoint(line["end"]["x"], line["end"]["y"]) # Add all rects rects = self.filterRects(layer) for r in rects: bb.addPoint(r["start"]["x"], r["start"]["y"]) bb.addPoint(r["end"]["x"], r["end"]["y"]) # Add all circles circles = self.filterCircles(layer) for c in circles: cx = c["center"]["x"] cy = c["center"]["y"] ex = c["end"]["x"] ey = c["end"]["y"] dx = ex - cx dy = ey - cy r = math.sqrt(dx * dx + dy * dy) bb.addPoint(cx, cy, radius=r) polys = self.filterPolys(layer) for p in polys: for pt in p["points"]: bb.addPoint(pt["x"], pt["y"]) # Add all arcs arcs = self.filterArcs(layer) for c in arcs: cx = c["start"]["x"] cy = c["start"]["y"] ex = c["end"]["x"] ey = c["end"]["y"] dx = ex - cx dy = ey - cy r = math.sqrt(dx * dx + dy * dy) dalpha = 1 alphaend = c["angle"] if math.fabs(alphaend) < 1: dalpha = math.fabs(alphaend) / 5 if alphaend < 0: dalpha = -dalpha if math.fabs(alphaend) > 0: a = 0 c0 = [ex - cx, ey - cy] # print("c0 = ",c0) while (alphaend > 0 and a <= alphaend) or (alphaend < 0 and a >= alphaend): c1 = [0, 0] c1[0] = (math.cos(a / 180 * 3.1415) * c0[0] - math.sin(a / 180 * 3.1415) * c0[1]) c1[1] = (math.sin(a / 180 * 3.1415) * c0[0] + math.cos(a / 180 * 3.1415) * c0[1]) bb.addPoint(cx + c1[0], cy + c1[1]) a = a + dalpha bb.addPoint(ex, None) return bb