Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# 

2# LSST Data Management System 

3# See COPYRIGHT file at the top of the source tree. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <https://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23import pickle 

24 

25import math 

26import unittest 

27 

28from lsst.sphgeom import (Angle, CONTAINS, Circle, Ellipse, Region, 

29 UnitVector3d, WITHIN) 

30 

31 

32class EllipseTestCase(unittest.TestCase): 

33 

34 def test_construction(self): 

35 self.assertTrue(Ellipse.empty().isEmpty()) 

36 self.assertTrue(Ellipse().isEmpty()) 

37 self.assertTrue(Ellipse.full().isFull()) 

38 e = Ellipse(Circle(UnitVector3d.X(), Angle(math.pi / 2))) 

39 f = Ellipse(UnitVector3d.X(), Angle(math.pi / 2)) 

40 self.assertEqual(e, f) 

41 self.assertEqual(e.getAlpha(), e.getBeta()) 

42 self.assertTrue(e.isCircle()) 

43 self.assertTrue(e.isGreatCircle()) 

44 g = Ellipse(e) 

45 h = e.clone() 

46 self.assertEqual(e, g) 

47 self.assertEqual(g, h) 

48 self.assertNotEqual(id(e), id(g)) 

49 self.assertNotEqual(id(g), id(h)) 

50 

51 def test_comparison_operators(self): 

52 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) 

53 f = Ellipse(UnitVector3d.X(), 

54 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) 

55 self.assertEqual(e, e) 

56 self.assertNotEqual(e, f) 

57 

58 def test_center_and_dimensions(self): 

59 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) 

60 self.assertAlmostEqual(e.getF1().dot(UnitVector3d.X()), 1.0) 

61 self.assertAlmostEqual(e.getF2().dot(UnitVector3d.Y()), 1.0) 

62 self.assertAlmostEqual(e.getAlpha(), Angle(2 * math.pi / 3)) 

63 f = Ellipse(UnitVector3d.X(), 

64 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) 

65 self.assertEqual(f.getCenter(), UnitVector3d.X()) 

66 

67 def test_relationships(self): 

68 e = Ellipse(UnitVector3d.X(), 

69 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) 

70 self.assertTrue(e.contains(UnitVector3d.X())) 

71 self.assertTrue(UnitVector3d.X() in e) 

72 c = Circle(UnitVector3d.X(), Angle(math.pi / 2)) 

73 self.assertEqual(c.relate(e), CONTAINS) 

74 self.assertEqual(e.relate(c), WITHIN) 

75 

76 def test_complement(self): 

77 e = Ellipse(UnitVector3d.X(), 

78 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) 

79 f = e.complemented().complement() 

80 self.assertEqual(e, f) 

81 

82 def test_codec(self): 

83 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) 

84 s = e.encode() 

85 self.assertEqual(Ellipse.decode(s), e) 

86 self.assertEqual(Region.decode(s), e) 

87 

88 def test_string(self): 

89 c = Ellipse(UnitVector3d.Z(), Angle(1.0)) 

90 self.assertEqual(str(c), 

91 'Ellipse([0.0, 0.0, 1.0], [0.0, 0.0, 1.0], 1.0)') 

92 self.assertEqual(repr(c), 

93 'Ellipse(UnitVector3d(0.0, 0.0, 1.0), ' 

94 'UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))') 

95 self.assertEqual(c, eval(repr(c), dict( 

96 Angle=Angle, Ellipse=Ellipse, UnitVector3d=UnitVector3d))) 

97 

98 def test_pickle(self): 

99 a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) 

100 b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL)) 

101 self.assertEqual(a, b) 

102 

103 

104if __name__ == '__main__': 104 ↛ 105line 104 didn't jump to line 105, because the condition on line 104 was never true

105 unittest.main()