| 422 | assert Vector(gppln.Axis().Direction()) == plane.zDir |
| 423 | |
| 424 | def testRect(self): |
| 425 | x = 10 |
| 426 | y = 11 |
| 427 | s = Workplane().rect(x, y) |
| 428 | # a rectangle has 4 sides |
| 429 | self.assertEqual(s.edges().size(), 4) |
| 430 | # assert that the lower left corner is in the correct spot for all |
| 431 | # possible values of centered |
| 432 | for centered_x, xval in zip([True, False], [-x / 2, 0]): |
| 433 | for centered_y, yval in zip([True, False], [-y / 2, 0]): |
| 434 | s = ( |
| 435 | Workplane() |
| 436 | .rect(x, y, centered=(centered_x, centered_y)) |
| 437 | .vertices("<X and <Y") |
| 438 | ) |
| 439 | self.assertEqual(s.size(), 1) |
| 440 | self.assertTupleAlmostEquals(s.val().toTuple(), (xval, yval, 0), 3) |
| 441 | # check that centered=True is the same as centered=(True, True) |
| 442 | for option0 in [True, False]: |
| 443 | v0 = ( |
| 444 | Workplane() |
| 445 | .rect(x, y, centered=option0) |
| 446 | .vertices(">X and >Y") |
| 447 | .val() |
| 448 | .toTuple() |
| 449 | ) |
| 450 | v1 = ( |
| 451 | Workplane() |
| 452 | .rect(x, y, centered=(option0, option0)) |
| 453 | .vertices(">X and >Y") |
| 454 | .val() |
| 455 | .toTuple() |
| 456 | ) |
| 457 | self.assertTupleAlmostEquals(v0, v1, 3) |
| 458 | |
| 459 | # test negative lengths |
| 460 | r0 = Workplane().rect(-x, -y, centered=False) |
| 461 | self.assertTupleAlmostEquals( |
| 462 | (0, 0, 0), r0.vertices(">X and >Y").val().toTuple(), 3 |
| 463 | ) |
| 464 | self.assertTupleAlmostEquals( |
| 465 | (-x, -y, 0), r0.vertices("<X and <Y").val().toTuple(), 3 |
| 466 | ) |
| 467 | # test move plus negative length |
| 468 | r1 = Workplane().move(x, y).rect(-x, -y, centered=False) |
| 469 | self.assertTupleAlmostEquals( |
| 470 | (x, y, 0), r1.vertices(">X and >Y").val().toTuple(), 3 |
| 471 | ) |
| 472 | self.assertTupleAlmostEquals( |
| 473 | (0, 0, 0), r1.vertices("<X and <Y").val().toTuple(), 3 |
| 474 | ) |
| 475 | # negative length should have no effect with centered=True |
| 476 | v2 = Workplane().rect(x, y).vertices(">X and >Y").val().toTuple() |
| 477 | v3 = Workplane().rect(-x, -y).vertices(">X and >Y").val().toTuple() |
| 478 | self.assertTupleAlmostEquals(v2, v3, 3) |
| 479 | |
| 480 | def testLoft(self): |
| 481 | """ |