88Pose2 unit tests.
99Author: Frank Dellaert & Duy Nguyen Ta & John Lambert
1010"""
11+ import math
1112import unittest
1213
13- import numpy as np
14-
1514import gtsam
15+ import numpy as np
1616from gtsam import Point2 , Point2Pairs , Pose2
1717from gtsam .utils .test_case import GtsamTestCase
1818
@@ -26,6 +26,34 @@ def test_adjoint(self) -> None:
2626 actual = Pose2 .adjoint_ (xi , xi )
2727 np .testing .assert_array_equal (actual , expected )
2828
29+ def test_transformTo (self ):
30+ """Test transformTo method."""
31+ pose = Pose2 (2 , 4 , - math .pi / 2 )
32+ actual = pose .transformTo (Point2 (3 , 2 ))
33+ expected = Point2 (2 , 1 )
34+ self .gtsamAssertEquals (actual , expected , 1e-6 )
35+
36+ # multi-point version
37+ points = np .stack ([Point2 (3 , 2 ), Point2 (3 , 2 )]).T
38+ actual_array = pose .transformTo (points )
39+ self .assertEqual (actual_array .shape , (2 , 2 ))
40+ expected_array = np .stack ([expected , expected ]).T
41+ np .testing .assert_allclose (actual_array , expected_array , atol = 1e-6 )
42+
43+ def test_transformFrom (self ):
44+ """Test transformFrom method."""
45+ pose = Pose2 (2 , 4 , - math .pi / 2 )
46+ actual = pose .transformFrom (Point2 (2 , 1 ))
47+ expected = Point2 (3 , 2 )
48+ self .gtsamAssertEquals (actual , expected , 1e-6 )
49+
50+ # multi-point version
51+ points = np .stack ([Point2 (2 , 1 ), Point2 (2 , 1 )]).T
52+ actual_array = pose .transformFrom (points )
53+ self .assertEqual (actual_array .shape , (2 , 2 ))
54+ expected_array = np .stack ([expected , expected ]).T
55+ np .testing .assert_allclose (actual_array , expected_array , atol = 1e-6 )
56+
2957 def test_align (self ) -> None :
3058 """Ensure estimation of the Pose2 element to align two 2d point clouds succeeds.
3159
0 commit comments