summaryrefslogtreecommitdiff
path: root/stsci
diff options
context:
space:
mode:
authormdroe <mdroe@stsci.edu>2014-06-05 21:23:22 -0400
committermdroe <mdroe@stsci.edu>2014-06-05 21:23:22 -0400
commit6ae25bb6cfc14a9b4f71db4c4ea7552194c2528e (patch)
treed502507a8d3a5df0ed85f6c4889761f7c39c2259 /stsci
parent6068d3056d787384074a43ae8840163deeefd3f8 (diff)
downloadstsci.sphere-6ae25bb6cfc14a9b4f71db4c4ea7552194c2528e.tar.gz
Fix union with empty polygon.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci.sphere/trunk@32433 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: ad718756b906e7254f8a899a8683e641e8396c17
Diffstat (limited to 'stsci')
-rw-r--r--stsci/sphere/polygon.py8
-rw-r--r--stsci/sphere/test/test_intersection.py12
-rw-r--r--stsci/sphere/test/test_union.py12
3 files changed, 32 insertions, 0 deletions
diff --git a/stsci/sphere/polygon.py b/stsci/sphere/polygon.py
index 2d67ff2..0406402 100644
--- a/stsci/sphere/polygon.py
+++ b/stsci/sphere/polygon.py
@@ -104,6 +104,9 @@ class SphericalPolygon(object):
return '%s(%r, %r)' % (self.__class__.__name__,
self.points, self.inside)
+ def copy(self):
+ return self.__class__(self._points.copy(), self._inside.copy())
+
@property
def points(self):
"""
@@ -604,6 +607,11 @@ class SphericalPolygon(object):
module.
"""
from . import graph
+ if len(self._points) < 3:
+ return other.copy()
+ elif len(other._points) < 3:
+ return self.copy()
+
g = graph.Graph([self, other])
polygon = g.union()
diff --git a/stsci/sphere/test/test_intersection.py b/stsci/sphere/test/test_intersection.py
index 3576cc1..08ed258 100644
--- a/stsci/sphere/test/test_intersection.py
+++ b/stsci/sphere/test/test_intersection.py
@@ -176,6 +176,18 @@ def test6():
return [poly1, poly2]
+def test_union_empty():
+ p = polygon.SphericalPolygon.from_cone(
+ random.randrange(-180, 180),
+ random.randrange(20, 90),
+ random.randrange(5, 16),
+ steps=16)
+
+ p2 = p.intersection(polygon.SphericalPolygon([]))
+
+ assert_array_almost_equal(p2._points, p._points)
+
+
if __name__ == '__main__':
if '--profile' not in sys.argv:
GRAPH_MODE = True
diff --git a/stsci/sphere/test/test_union.py b/stsci/sphere/test/test_union.py
index b106907..24de9e6 100644
--- a/stsci/sphere/test/test_union.py
+++ b/stsci/sphere/test/test_union.py
@@ -214,3 +214,15 @@ if __name__ == '__main__':
functions.sort()
for k, v in functions:
v()
+
+
+def test_union_empty():
+ p = polygon.SphericalPolygon.from_cone(
+ random.randrange(-180, 180),
+ random.randrange(20, 90),
+ random.randrange(5, 16),
+ steps=16)
+
+ p2 = p.union(polygon.SphericalPolygon([]))
+
+ assert_array_almost_equal(p2._points, p._points)