From e0886647eb9f8073c214878498c4d422b0aa31ab Mon Sep 17 00:00:00 2001 From: mdroe Date: Wed, 11 Jul 2012 17:27:46 +0000 Subject: Intersection with an empty polygon should return an empty polygon. git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/branches/sphere@17821 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 1db96e6bd2b7525c07e2a73832c142f74730a635 --- lib/polygon.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/polygon.py') diff --git a/lib/polygon.py b/lib/polygon.py index fd67042..0957279 100644 --- a/lib/polygon.py +++ b/lib/polygon.py @@ -367,7 +367,7 @@ class SphericalPolygon(object): `True` or `False`. """ self_n = len(self.points) - + if self_n != len(other.points): return False @@ -376,10 +376,10 @@ class SphericalPolygon(object): self_a = self.area() is_same_limit = thres * self_a - + if np.abs(self_a - other.area()) > is_same_limit: return False - + if do_sort: self_pts = self._sorted_points(preserve_order=False, unique=True) other_pts = other._sorted_points(preserve_order=False, unique=True) @@ -388,7 +388,7 @@ class SphericalPolygon(object): other_pts = other.points is_eq = True - + for self_p, other_p in zip(self_pts, other_pts): x_sum = 0.0 @@ -696,6 +696,9 @@ class SphericalPolygon(object): # return self.__class__([], [0, 0, 0]) from . import graph + if len(self._points) < 3 or len(other._points) < 3: + return self.__class__([], [0, 0, 0]) + g = graph.Graph([self, other]) polygon = g.intersection() -- cgit