def test_extractRad(self): ex = pya.SimplePolygon().extract_rad() self.assertEqual(repr(ex), "[]") sp = pya.SimplePolygon.from_s("(0,0;0,200000;300000,200000;300000,100000;100000,100000;100000,0)") sp = sp.round_corners(10000, 5000, 200) ex = sp.extract_rad() self.assertEqual(ex, [pya.SimplePolygon.from_s("(0,0;0,200000;300000,200000;300000,100000;100000,100000;100000,0)"), 10000.0, 5000.0, 200]) ex = pya.Polygon().extract_rad() self.assertEqual(ex, []) sp = pya.Polygon.from_s("(0,0;0,300000;300000,300000;300000,0/100000,100000;200000,100000;200000,200000;100000,200000)") sp = sp.round_corners(10000, 5000, 200) ex = sp.extract_rad() self.assertEqual(ex, [pya.Polygon.from_s("(0,0;0,300000;300000,300000;300000,0/100000,100000;200000,100000;200000,200000;100000,200000)"), 10000.0, 5000.0, 200]) # double coords too ... ex = pya.DSimplePolygon().extract_rad() self.assertEqual(ex, []) sp = pya.DSimplePolygon.from_s("(0,0;0,200000;300000,200000;300000,100000;100000,100000;100000,0)") sp = sp.round_corners(10000, 5000, 200) ex = sp.extract_rad() # round to integers for better comparison ex[0] = pya.SimplePolygon(ex[0]) self.assertEqual(ex, [pya.SimplePolygon.from_s("(0,0;0,200000;300000,200000;300000,100000;100000,100000;100000,0)"), 10000.0, 5000.0, 200]) ex = pya.DPolygon().extract_rad() self.assertEqual(ex, []) sp = pya.DPolygon.from_s("(0,0;0,300000;300000,300000;300000,0/100000,100000;200000,100000;200000,200000;100000,200000)") sp = sp.round_corners(10000, 5000, 200) ex = sp.extract_rad() # round to integers for better comparison ex[0] = pya.Polygon(ex[0]) self.assertEqual(ex, [pya.Polygon.from_s("(0,0;0,300000;300000,300000;300000,0/100000,100000;200000,100000;200000,200000;100000,200000)"), 10000.0, 5000.0, 200])
def init_regions(self): self.connections = [DPoint(0, 0), self.dr] self.start = DPoint(0, 0) self.end = self.start + self.dr alpha = atan2(self.dr.y, self.dr.x) self.angle_connections = [alpha, alpha] alpha_trans = ICplxTrans().from_dtrans( DCplxTrans(1, alpha * 180 / pi, False, self.start)) metal_poly = DSimplePolygon([ DPoint(0, -self.width / 2), DPoint(self.dr.abs(), -self.width / 2), DPoint(self.dr.abs(), self.width / 2), DPoint(0, self.width / 2) ]) self.connection_edges = [3, 1] self.metal_region.insert(pya.SimplePolygon().from_dpoly(metal_poly)) if (self.gap != 0): self.empty_region.insert( pya.Box( Point().from_dpoint(DPoint(0, self.width / 2)), Point().from_dpoint( DPoint(self.dr.abs(), self.width / 2 + self.gap)))) self.empty_region.insert( pya.Box( Point().from_dpoint(DPoint(0, -self.width / 2 - self.gap)), Point().from_dpoint(DPoint(self.dr.abs(), -self.width / 2)))) self.metal_region.transform(alpha_trans) self.empty_region.transform(alpha_trans)
def test_touches(self): p1 = pya.Polygon(pya.Box(10, 20, 30, 40)) self.assertEqual(p1.touches(pya.Polygon(pya.Box(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.Polygon(pya.Box(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.Polygon(pya.Box(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.Box(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Box(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.Box(29, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Edge(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Edge(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.Edge(29, 20, 40, 50)), True) p1 = pya.SimplePolygon(pya.Box(10, 20, 30, 40)) self.assertEqual(p1.touches(pya.Polygon(pya.Box(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.Polygon(pya.Box(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.Polygon(pya.Box(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.SimplePolygon(pya.Box(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.Box(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Box(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.Box(29, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Edge(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.Edge(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.Edge(29, 20, 40, 50)), True) p1 = pya.DPolygon(pya.DBox(10, 20, 30, 40)) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DBox(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DBox(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.DBox(29, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DEdge(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DEdge(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.DEdge(29, 20, 40, 50)), True) p1 = pya.DSimplePolygon(pya.DBox(10, 20, 30, 40)) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.DPolygon(pya.DBox(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(30, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(31, 20, 40, 50))), False) self.assertEqual(p1.touches(pya.DSimplePolygon(pya.DBox(29, 20, 40, 50))), True) self.assertEqual(p1.touches(pya.DBox(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DBox(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.DBox(29, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DEdge(30, 20, 40, 50)), True) self.assertEqual(p1.touches(pya.DEdge(31, 20, 40, 50)), False) self.assertEqual(p1.touches(pya.DEdge(29, 20, 40, 50)), True)
def create(radius, npoints=32): """Create a circular-shaped region. radius: radius of the circular area npoints: the circular area is approximated by a polygon, hence the number of vertices """ angles = np.linspace(0, 2 * np.pi, num=npoints, endpoint=False) points = [] for i, ang in enumerate(angles): points.append(pya.Point(radius * np.cos(ang), radius * np.sin(ang))) circle = pya.Region() circle.insert(pya.SimplePolygon(points)) return circle
"Enter the initial spacing between the innermost two boxes", 0) spacing = inputd.ask_int( "Spacing", "Enter the amount by which spacing between subsequent boxes will increase", 0) # Fail if any of the inputed values are invalid (None or negative values are invalid) if ((iterations == None or iterations < 0) or (initial == None or initial < 0) or (spacing == None or spacing < 0)): pya.MessageBox.warning( "Invalid Input", "One or more values were not inputted or were negative. Exiting macro immediately.", pya.MessageBox.Ok) # Otherwise, continue: else: cell = ly.cell("test") rect_points = [] # Find the simple polygon box in the cell for shape in cell.shapes(ly.layer(1, 0)).each(): if (shape.is_simple_polygon()): print("Getting polygon") for point in shape.simple_polygon.each_point(): rect_points.append(((point.x * dbu), (point.y * dbu))) # Generate each box using the coordinates of the points for the original box for i in range(iterations): points = create_new_points(rect_points, initial, spacing, i, dbu) cell.shapes(ly.layer(1, 0)).insert(pya.SimplePolygon(points))