Coverage for tests/test_Circle.py : 20%

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#
23import pickle
25import math
26import unittest
28from lsst.sphgeom import (Angle, CONTAINS, Circle, DISJOINT, Region,
29 UnitVector3d)
32class CircleTestCase(unittest.TestCase):
34 def test_construction(self):
35 self.assertTrue(Circle.empty().isEmpty())
36 self.assertTrue(Circle().isEmpty())
37 self.assertTrue(Circle.full().isFull())
38 c = Circle(UnitVector3d.X())
39 self.assertEqual(c.getOpeningAngle(), Angle(0))
40 self.assertEqual(c.getSquaredChordLength(), 0)
41 c = Circle(UnitVector3d.Z(), 2.0)
42 self.assertTrue(c.contains(UnitVector3d.Z()))
43 c = Circle(UnitVector3d.Z(), Angle(math.pi))
44 self.assertTrue(c.isFull())
45 d = c.clone()
46 self.assertEqual(c, d)
47 self.assertNotEqual(id(c), id(d))
48 e = Circle(d)
49 self.assertEqual(d, e)
51 def test_comparison_operators(self):
52 c = Circle(UnitVector3d.X(), 4.0)
53 d = Circle(UnitVector3d.Y(), 4.0)
54 self.assertEqual(c, d)
55 self.assertTrue(c.isFull())
56 self.assertNotEqual(c, Circle(UnitVector3d.Z()))
58 def test_center_and_dimensions(self):
59 c = Circle(UnitVector3d.X(), 1)
60 self.assertEqual(c.getCenter(), UnitVector3d.X())
61 self.assertEqual(c.getSquaredChordLength(), 1)
62 self.assertAlmostEqual(c.getOpeningAngle().asRadians(), math.pi / 3)
64 def test_relationships(self):
65 c = Circle(UnitVector3d.X(), Angle.fromDegrees(0.1))
66 d = Circle(UnitVector3d(1, 1, 1), Angle(math.pi / 2))
67 e = Circle(-UnitVector3d.X())
68 self.assertTrue(c.contains(UnitVector3d.X()))
69 self.assertTrue(UnitVector3d.X() in c)
70 self.assertTrue(d.contains(c))
71 self.assertTrue(c.isWithin(d))
72 self.assertTrue(c.intersects(d))
73 self.assertTrue(c.intersects(UnitVector3d.X()))
74 self.assertTrue(e.isDisjointFrom(d))
75 self.assertEqual(d.relate(c), CONTAINS)
76 self.assertEqual(e.relate(d), DISJOINT)
78 def test_expanding_and_clipping(self):
79 a = Circle.empty()
80 b = (a.expandedTo(UnitVector3d.X())
81 .expandedTo(Circle(UnitVector3d.Y(), 1))
82 .clippedTo(Circle(UnitVector3d(1, 1, 0), 1))
83 .clippedTo(UnitVector3d.Y()))
84 a.expandTo(UnitVector3d.X())
85 a.expandTo(Circle(UnitVector3d.Y(), 1))
86 a.clipTo(Circle(UnitVector3d(1, 1, 0), 1))
87 a.clipTo(UnitVector3d.Y())
88 self.assertEqual(a, b)
89 self.assertEqual(a, Circle(UnitVector3d.Y()))
90 a.clipTo(UnitVector3d.Z())
91 self.assertTrue(a.isEmpty())
93 def test_dilation_and_erosion(self):
94 a = Angle(math.pi / 2)
95 c = Circle(UnitVector3d.X())
96 d = c.dilatedBy(a).erodedBy(a)
97 c.dilateBy(a).erodeBy(a)
98 self.assertEqual(c, d)
99 self.assertEqual(c, Circle(UnitVector3d.X()))
101 def test_complement(self):
102 c = Circle(UnitVector3d.X(), 2.0)
103 d = c.complemented()
104 c.complement()
105 self.assertEqual(c, d)
106 self.assertEqual(c.getCenter(), -UnitVector3d.X())
107 self.assertEqual(c.getSquaredChordLength(), 2.0)
109 def test_area(self):
110 c = Circle(UnitVector3d(1, 1, 1), 2.0)
111 self.assertAlmostEqual(c.getArea(), 2 * math.pi)
113 def test_codec(self):
114 c = Circle(UnitVector3d.Y(), 1.0)
115 s = c.encode()
116 self.assertEqual(Circle.decode(s), c)
117 self.assertEqual(Region.decode(s), c)
119 def test_string(self):
120 c = Circle(UnitVector3d.Z(), Angle(1.0))
121 self.assertEqual(str(c), 'Circle([0.0, 0.0, 1.0], 1.0)')
122 self.assertEqual(repr(c),
123 'Circle(UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))')
124 self.assertEqual(c, eval(repr(c), dict(
125 Angle=Angle, Circle=Circle, UnitVector3d=UnitVector3d)))
127 def test_pickle(self):
128 a = Circle(UnitVector3d(1, -1, 1), 1.0)
129 b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL))
130 self.assertEqual(a, b)
133if __name__ == '__main__': 133 ↛ 134line 133 didn't jump to line 134, because the condition on line 133 was never true
134 unittest.main()