Fixed Point2 and Point3 to have similar behavior as in C++

- to also take vectors
- to be initialized to Nan
release/4.3a0
Frank dellaert 2020-08-20 14:47:55 -04:00
parent a2d5730c30
commit 3d477f3a38
3 changed files with 67 additions and 2 deletions

View File

@ -5,17 +5,24 @@ def _init():
"""This function is to add shims for the long-gone Point2 and Point3 types"""
import numpy as np
import math
global Point2 # export function
def Point2(x=0, y=0):
def Point2(x=math.nan, y=math.nan):
"""Shim for the deleted Point2 type."""
if isinstance(x, np.ndarray):
assert x.shape == (2,), "Point2 takes 2-vector"
return x # "copy constructor"
return np.array([x, y], dtype=float)
global Point3 # export function
def Point3(x=0, y=0, z=0):
def Point3(x=math.nan, y=math.nan, z=math.nan):
"""Shim for the deleted Point3 type."""
if isinstance(x, np.ndarray):
assert x.shape == (3,), "Point3 takes 3-vector"
return x # "copy constructor"
return np.array([x, y, z], dtype=float)
# for interactive debugging

View File

@ -0,0 +1,29 @@
"""
GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
Atlanta, Georgia 30332-0415
All Rights Reserved
See LICENSE for the license information
Point2 unit tests.
Author: Frank Dellaert & Fan Jiang
"""
import unittest
import gtsam
import numpy as np
from gtsam.utils.test_case import GtsamTestCase
class TestPoint2(GtsamTestCase):
"""Test selected Point2 methods."""
def test_constructors(self):
"""Test constructors from doubles and vectors."""
expected = gtsam.Point2(1, 2)
actual = gtsam.Point2(np.array([1, 2]))
np.testing.assert_array_equal(actual, expected)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,29 @@
"""
GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
Atlanta, Georgia 30332-0415
All Rights Reserved
See LICENSE for the license information
Point3 unit tests.
Author: Frank Dellaert & Fan Jiang
"""
import unittest
import gtsam
import numpy as np
from gtsam.utils.test_case import GtsamTestCase
class TestPoint3(GtsamTestCase):
"""Test selected Point3 methods."""
def test_constructors(self):
"""Test constructors from doubles and vectors."""
expected = gtsam.Point3(1, 2, 3)
actual = gtsam.Point3(np.array([1, 2, 3]))
np.testing.assert_array_equal(actual, expected)
if __name__ == "__main__":
unittest.main()