Skip to content

Commit

Permalink
test_direct_api.py -> compare orientation vectors using quaternions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegenstein authored Jan 15, 2024
1 parent a433707 commit 8c0a950
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,41 @@ def assertVectorAlmostEquals(
self.assertAlmostEqual(first.Y, second_vector.Y, places, msg=msg)
self.assertAlmostEqual(first.Z, second_vector.Z, places, msg=msg)

def assertOrientationVectorAlmostEquals(
self, first: Vector, second: VectorLike, places: int, msg: Optional[str] = None
):
""" uses quaternions internally to compare orientation vector of both inputs """

firstq = gp_Quaternion()
firstq.SetEulerAngles(
gp_EulerSequence.gp_Intrinsic_XYZ,
first.X,
first.Y,
first.Z,
)
firste = gp_Trsf()
firste.SetTransformation(firstq)
firstrot = firste.GetRotation()
first_vector = Vector(math.degrees(a) for a in firstrot.GetEulerAngles(gp_EulerSequence.gp_Intrinsic_XYZ))

second_vec_in = Vector(second)

secondq = gp_Quaternion()
secondq.SetEulerAngles(
gp_EulerSequence.gp_Intrinsic_XYZ,
second_vec_in.X,
second_vec_in.Y,
second_vec_in.Z,
)
seconde = gp_Trsf()
seconde.SetTransformation(secondq)
secondrot = seconde.GetRotation()
second_vector = Vector(math.degrees(a) for a in secondrot.GetEulerAngles(gp_EulerSequence.gp_Intrinsic_XYZ))


self.assertAlmostEqual(first_vector.X, second_vector.X, places, msg=msg)
self.assertAlmostEqual(first_vector.Y, second_vector.Y, places, msg=msg)
self.assertAlmostEqual(first_vector.Z, second_vector.Z, places, msg=msg)

class TestAssembly(unittest.TestCase):
@staticmethod
Expand Down Expand Up @@ -1592,7 +1627,7 @@ def test_neg(self):
loc = Location((1, 2, 3), (0, 35, 127))
n_loc = -loc
self.assertVectorAlmostEquals(n_loc.position, (1, 2, 3), 5)
self.assertVectorAlmostEquals(n_loc.orientation, (180, -35, -127), 5)
self.assertOrientationVectorAlmostEquals(n_loc.orientation, (180, -35, -127), 5)

def test_mult_iterable(self):
locs = Location((1, 2, 0)) * GridLocations(4, 4, 2, 1)
Expand Down

0 comments on commit 8c0a950

Please sign in to comment.