Coverage for tests/test_ConvexPolygon.py : 25%

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
24import yaml
26import unittest
28from lsst.sphgeom import CONTAINS, ConvexPolygon, Circle, Region, UnitVector3d
31class ConvexPolygonTestCase(unittest.TestCase):
33 def testConstruction(self):
34 points = [UnitVector3d.Z(), UnitVector3d.X(), UnitVector3d.Y()]
35 p1 = ConvexPolygon(points)
36 self.assertEqual(points, p1.getVertices())
37 p2 = p1.clone()
38 self.assertEqual(p1, p2)
39 p3 = ConvexPolygon([-UnitVector3d.Z(),
40 UnitVector3d.X(),
41 UnitVector3d.Y()])
42 self.assertNotEqual(p1, p3)
43 p4 = ConvexPolygon.convexHull([UnitVector3d.Y(),
44 UnitVector3d.X(),
45 UnitVector3d(1, 1, 1),
46 UnitVector3d.Z()])
47 self.assertEqual(p1, p4)
49 def testCodec(self):
50 p = ConvexPolygon([UnitVector3d.Z(),
51 UnitVector3d.X(),
52 UnitVector3d.Y()])
53 s = p.encode()
54 self.assertEqual(ConvexPolygon.decode(s), p)
55 self.assertEqual(Region.decode(s), p)
57 def testRelationships(self):
58 p = ConvexPolygon([UnitVector3d.Z(),
59 UnitVector3d.X(),
60 UnitVector3d.Y()])
61 self.assertTrue(p.contains(p.getCentroid()))
62 boundingCircle = p.getBoundingCircle()
63 self.assertEqual(boundingCircle.relate(p), CONTAINS)
64 self.assertTrue(p.isWithin(boundingCircle))
65 self.assertTrue(p.intersects(boundingCircle))
66 self.assertFalse(p.isDisjointFrom(boundingCircle))
67 self.assertFalse(p.contains(boundingCircle))
68 tinyCircle = Circle(boundingCircle.getCenter())
69 self.assertFalse(p.isWithin(tinyCircle))
70 self.assertTrue(p.intersects(tinyCircle))
71 self.assertFalse(p.isDisjointFrom(tinyCircle))
72 self.assertTrue(p.contains(tinyCircle))
74 def testString(self):
75 p = ConvexPolygon([UnitVector3d.Z(),
76 UnitVector3d.X(),
77 UnitVector3d.Y()])
78 self.assertEqual(str(p), repr(p))
79 self.assertEqual(repr(p),
80 'ConvexPolygon([UnitVector3d(0.0, 0.0, 1.0), '
81 'UnitVector3d(1.0, 0.0, 0.0), '
82 'UnitVector3d(0.0, 1.0, 0.0)])')
83 self.assertEqual(
84 p, eval(repr(p), dict(ConvexPolygon=ConvexPolygon,
85 UnitVector3d=UnitVector3d)))
87 def testPickle(self):
88 a = ConvexPolygon([UnitVector3d.Z(),
89 UnitVector3d.X(),
90 UnitVector3d.Y()])
91 b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL))
92 self.assertEqual(a, b)
94 def testYaml(self):
95 a = ConvexPolygon([UnitVector3d.Z(),
96 UnitVector3d.X(),
97 UnitVector3d.Y()])
98 b = yaml.safe_load(yaml.dump(a))
99 self.assertEqual(a, b)
102if __name__ == '__main__': 102 ↛ 103line 102 didn't jump to line 103, because the condition on line 102 was never true
103 unittest.main()