| 1359 | self.assertEqual(6, r.faces().size()) |
| 1360 | |
| 1361 | def testRectArray(self): |
| 1362 | x_num = 3 |
| 1363 | y_num = 3 |
| 1364 | x_spacing = 8.0 |
| 1365 | y_spacing = 8.0 |
| 1366 | s = ( |
| 1367 | Workplane("XY") |
| 1368 | .box(40, 40, 5, centered=(True, True, True)) |
| 1369 | .faces(">Z") |
| 1370 | .workplane() |
| 1371 | .rarray(x_spacing, y_spacing, x_num, y_num, True) |
| 1372 | .circle(2.0) |
| 1373 | .extrude(2.0) |
| 1374 | ) |
| 1375 | self.saveModel(s) |
| 1376 | # 6 faces for the box, 2 faces for each cylinder |
| 1377 | self.assertEqual(6 + x_num * y_num * 2, s.faces().size()) |
| 1378 | |
| 1379 | with raises(ValueError): |
| 1380 | Workplane().rarray(0, 0, x_num, y_num, True) |
| 1381 | |
| 1382 | # check lower and upper corner points are correct for all combinations of centering |
| 1383 | for x_opt, x_min, x_max in zip( |
| 1384 | [True, False], [-x_spacing, 0.0], [x_spacing, x_spacing * 2] |
| 1385 | ): |
| 1386 | for y_opt, y_min, y_max in zip( |
| 1387 | [True, False], [-y_spacing, 0.0], [y_spacing, y_spacing * 2] |
| 1388 | ): |
| 1389 | s = Workplane().rarray( |
| 1390 | x_spacing, y_spacing, x_num, y_num, center=(x_opt, y_opt) |
| 1391 | ) |
| 1392 | lower = Vector(x_min, y_min, 0) |
| 1393 | upper = Vector(x_max, y_max, 0) |
| 1394 | self.assertTrue(lower in s.objects) |
| 1395 | self.assertTrue(upper in s.objects) |
| 1396 | |
| 1397 | # check centered=True is equivalent to centered=(True, True) |
| 1398 | for val in [True, False]: |
| 1399 | s0 = Workplane().rarray(x_spacing, y_spacing, x_num, y_num, center=val) |
| 1400 | s1 = Workplane().rarray( |
| 1401 | x_spacing, y_spacing, x_num, y_num, center=(val, val) |
| 1402 | ) |
| 1403 | # check all the points in s0 are present in s1 |
| 1404 | self.assertTrue(all(pnt in s1.objects for pnt in s0.objects)) |
| 1405 | self.assertEqual(s0.size(), s1.size()) |
| 1406 | |
| 1407 | def testPolarArray(self): |
| 1408 | radius = 10 |