示例#1
0
    def test_compose(self):
        expected_quat = [[+2],
                         [-1],
                         [-3],
                         [+0]]
        r_ident_d = Rotation(ctypes.c_double)
        r_ident_f = Rotation(ctypes.c_float)
        r_other_d = Rotation.from_quaternion(expected_quat, ctypes.c_double)
        r_other_f = Rotation.from_quaternion(expected_quat, ctypes.c_float)

        r_res_d = r_ident_d.compose(r_other_d)
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_f)
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        # Should also work with multiply operator
        r_res_d = r_ident_d * r_other_d
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_f
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        # Rotation of non-congruent types should be converted automatically
        r_res_d = r_ident_d.compose(r_other_f)
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_equal(r_res_d.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_d)
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        r_res_d = r_ident_d * r_other_f
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_equal(r_res_d.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_d
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)
示例#2
0
    def test_compose(self):
        expected_quat = [[+2], [-1], [-3], [+0]]
        r_ident_d = Rotation(ctypes.c_double)
        r_ident_f = Rotation(ctypes.c_float)
        r_other_d = Rotation.from_quaternion(expected_quat, ctypes.c_double)
        r_other_f = Rotation.from_quaternion(expected_quat, ctypes.c_float)

        r_res_d = r_ident_d.compose(r_other_d)
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_f)
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        # Should also work with multiply operator
        r_res_d = r_ident_d * r_other_d
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_f
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        # Rotation of non-congruent types should be converted automatically
        r_res_d = r_ident_d.compose(r_other_f)
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_equal(r_res_d.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_d)
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)

        r_res_d = r_ident_d * r_other_f
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_equal(r_res_d.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_d
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_equal(r_res_f.quaternion(), expected_quat)
示例#3
0
    def test_compose(self):
        # Normalize quaternaion vector.
        expected_quat = array_normalize([+2., -1., -3., +0.])

        r_ident_d = Rotation('d')
        r_ident_f = Rotation('f')
        r_other_d = Rotation.from_quaternion(expected_quat, 'd')
        r_other_f = Rotation.from_quaternion(expected_quat, 'f')

        r_res_d = r_ident_d.compose(r_other_d)
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_f)
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Should also work with multiply operator
        r_res_d = r_ident_d * r_other_d
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_f
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Rotation of non-congruent types should be converted automatically
        r_res_d = r_ident_d.compose(r_other_f)
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_allclose(r_res_d.quaternion(),
                                      r_other_f.quaternion(), 1e-7)
        numpy.testing.assert_allclose(r_res_d.quaternion(), expected_quat,
                                      1e-7)

        r_res_f = r_ident_f.compose(r_other_d)
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(),
                                      r_other_f.quaternion(), 1e-7)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Equality check between types should pass due to integrety resolution
        # inside function.
        r_res_d = r_ident_d * r_other_f
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_allclose(r_res_d.quaternion(),
                                      r_other_f.quaternion(), 1e-7)
        numpy.testing.assert_allclose(r_res_d.quaternion(), expected_quat,
                                      1e-7)

        r_res_f = r_ident_f * r_other_d
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)
示例#4
0
    def test_compose(self):
        # Normalize quaternaion vector.
        expected_quat = array_normalize([+2., -1., -3., +0.])

        r_ident_d = Rotation('d')
        r_ident_f = Rotation('f')
        r_other_d = Rotation.from_quaternion(expected_quat, 'd')
        r_other_f = Rotation.from_quaternion(expected_quat, 'f')

        r_res_d = r_ident_d.compose(r_other_d)
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f.compose(r_other_f)
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Should also work with multiply operator
        r_res_d = r_ident_d * r_other_d
        nose.tools.assert_is_not(r_other_d, r_res_d)
        numpy.testing.assert_equal(r_res_d, r_other_d)
        numpy.testing.assert_equal(r_res_d.quaternion(), expected_quat)

        r_res_f = r_ident_f * r_other_f
        nose.tools.assert_is_not(r_other_f, r_res_f)
        numpy.testing.assert_equal(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Rotation of non-congruent types should be converted automatically
        r_res_d = r_ident_d.compose(r_other_f)
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_allclose(r_res_d.quaternion(),
                                      r_other_f.quaternion(),
                                      1e-7)
        numpy.testing.assert_allclose(r_res_d.quaternion(), expected_quat,
                                      1e-7)

        r_res_f = r_ident_f.compose(r_other_d)
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_allclose(r_res_f.quaternion(),
                                      r_other_f.quaternion(),
                                      1e-7)
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)

        # Equality check between types should pass due to integrety resolution
        # inside function.
        r_res_d = r_ident_d * r_other_f
        nose.tools.assert_is_not(r_res_d, r_other_f)
        numpy.testing.assert_allclose(r_res_d.quaternion(),
                                      r_other_f.quaternion(),
                                      1e-7)
        numpy.testing.assert_allclose(r_res_d.quaternion(), expected_quat,
                                      1e-7)

        r_res_f = r_ident_f * r_other_d
        nose.tools.assert_is_not(r_res_f, r_other_f)
        numpy.testing.assert_equal(r_res_f.quaternion(),
                                   r_other_f.quaternion())
        numpy.testing.assert_allclose(r_res_f.quaternion(), expected_quat,
                                      1e-7)