Coverage for tests/test_ConvexPolygon.py : 24%

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