Tests a plugin to make regular polygons around points on the stack Demonstrations using eachpoint to allow working in local coordinates to create geometry
(self)
| 199 | self.saveModel(s) |
| 200 | |
| 201 | def testPolygonPlugin(self): |
| 202 | """ |
| 203 | Tests a plugin to make regular polygons around points on the stack |
| 204 | |
| 205 | Demonstrations using eachpoint to allow working in local coordinates |
| 206 | to create geometry |
| 207 | """ |
| 208 | |
| 209 | def rPoly(self, nSides, diameter): |
| 210 | def _makePolygon(loc): |
| 211 | # pnt is a vector in local coordinates |
| 212 | angle = 2.0 * math.pi / nSides |
| 213 | pnts = [] |
| 214 | for i in range(nSides + 1): |
| 215 | pnts.append( |
| 216 | Vector( |
| 217 | (diameter / 2.0 * math.cos(angle * i)), |
| 218 | (diameter / 2.0 * math.sin(angle * i)), |
| 219 | 0, |
| 220 | ) |
| 221 | ) |
| 222 | return Wire.makePolygon(pnts).located(loc) |
| 223 | |
| 224 | return self.eachpoint(_makePolygon, True) |
| 225 | |
| 226 | Workplane.rPoly = rPoly |
| 227 | |
| 228 | s = ( |
| 229 | Workplane("XY") |
| 230 | .box(4.0, 4.0, 0.25) |
| 231 | .faces(">Z") |
| 232 | .workplane() |
| 233 | .rect(2.0, 2.0, forConstruction=True) |
| 234 | .vertices() |
| 235 | .rPoly(5, 0.5) |
| 236 | .cutThruAll() |
| 237 | ) |
| 238 | |
| 239 | # 6 base sides, 4 pentagons, 5 sides each = 26 |
| 240 | self.assertEqual(26, s.faces().size()) |
| 241 | self.saveModel(s) |
| 242 | |
| 243 | def testFluentMethodInheritance(self): |
| 244 | """ |