MCPcopy Index your code
hub / github.com/CadQuery/cadquery / testLocation

Method testLocation

tests/test_cad_objects.py:617–695  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

615 self.assertTupleAlmostEquals(target_point, mirror_box_vertices[i], 7)
616
617 def testLocation(self):
618
619 # empty
620 loc = Location()
621
622 T = loc.wrapped.Transformation().TranslationPart()
623 self.assertTupleAlmostEquals((T.X(), T.Y(), T.Z()), (0, 0, 0), 6)
624
625 # Tuple
626 loc0 = Location((0, 0, 1))
627
628 T = loc0.wrapped.Transformation().TranslationPart()
629 self.assertTupleAlmostEquals((T.X(), T.Y(), T.Z()), (0, 0, 1), 6)
630
631 # Vector
632 loc1 = Location(Vector(0, 0, 1))
633
634 T = loc1.wrapped.Transformation().TranslationPart()
635 self.assertTupleAlmostEquals((T.X(), T.Y(), T.Z()), (0, 0, 1), 6)
636
637 # rotation + translation
638 loc2 = Location(Vector(0, 0, 1), Vector(0, 0, 1), 45)
639
640 angle = loc2.wrapped.Transformation().GetRotation().GetRotationAngle() * RAD2DEG
641 self.assertAlmostEqual(45, angle)
642
643 # gp_Trsf
644 T = gp_Trsf()
645 T.SetTranslation(gp_Vec(0, 0, 1))
646 loc3 = Location(T)
647
648 assert (
649 loc1.wrapped.Transformation().TranslationPart().Z()
650 == loc3.wrapped.Transformation().TranslationPart().Z()
651 )
652
653 # Test creation from the OCP.gp.gp_Trsf object
654 loc4 = Location(gp_Trsf())
655 self.assertTupleAlmostEquals(loc4.toTuple()[0], (0, 0, 0), 7)
656 self.assertTupleAlmostEquals(loc4.toTuple()[1], (0, 0, 0), 7)
657
658 # Test composition
659 loc4 = Location((0, 0, 0), Vector(0, 0, 1), 15)
660
661 loc5 = loc1 * loc4
662 loc6 = loc4 * loc4
663 loc7 = loc4 ** 2
664
665 T = loc5.wrapped.Transformation().TranslationPart()
666 self.assertTupleAlmostEquals((T.X(), T.Y(), T.Z()), (0, 0, 1), 6)
667
668 angle5 = (
669 loc5.wrapped.Transformation().GetRotation().GetRotationAngle() * RAD2DEG
670 )
671 self.assertAlmostEqual(15, angle5)
672
673 angle6 = (
674 loc6.wrapped.Transformation().GetRotation().GetRotationAngle() * RAD2DEG

Callers

nothing calls this directly

Calls 4

toTupleMethod · 0.95
LocationClass · 0.85
VectorClass · 0.85

Tested by

no test coverage detected