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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

# 

# LSST Data Management System 

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

# 

# This product includes software developed by the 

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

# 

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

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

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

# (at your option) any later version. 

# 

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

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

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

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

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

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

# 

from __future__ import absolute_import, division, print_function 

 

try: 

import cPickle as pickle # Use cPickle on Python 2.7 

except ImportError: 

import pickle 

 

import math 

import unittest 

 

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

UnitVector3d, WITHIN) 

 

 

class EllipseTestCase(unittest.TestCase): 

 

def test_construction(self): 

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

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

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

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

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

self.assertEqual(e, f) 

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

self.assertTrue(e.isCircle()) 

self.assertTrue(e.isGreatCircle()) 

g = Ellipse(e) 

h = e.clone() 

self.assertEqual(e, g) 

self.assertEqual(g, h) 

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

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

 

def test_comparison_operators(self): 

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

f = Ellipse(UnitVector3d.X(), 

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

self.assertEqual(e, e) 

self.assertNotEqual(e, f) 

 

def test_center_and_dimensions(self): 

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

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

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

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

f = Ellipse(UnitVector3d.X(), 

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

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

 

def test_relationships(self): 

e = Ellipse(UnitVector3d.X(), 

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

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

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

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

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

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

 

def test_complement(self): 

e = Ellipse(UnitVector3d.X(), 

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

f = e.complemented().complement() 

self.assertEqual(e, f) 

 

def test_codec(self): 

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

s = e.encode() 

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

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

 

def test_string(self): 

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

self.assertEqual(str(c), 

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

self.assertEqual(repr(c), 

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

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

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

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

 

def test_pickle(self): 

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

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

self.assertEqual(a, b) 

 

 

108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never trueif __name__ == '__main__': 

unittest.main()