From 89ede54a9914e7074f86b4c9cbc4c8399874abe2 Mon Sep 17 00:00:00 2001 From: Yonggang Liu Date: Wed, 18 Apr 2018 15:25:38 -0400 Subject: [PATCH] CMR-4722: Bounding box constraint matching granules outside of bounding box. --- orbits-lib/resources/orbits/geometry_backtracking.rb | 5 +++++ orbits-lib/resources/orbits/orbit.rb | 7 ++++--- .../search/granule_orbit_search_test.clj | 11 +++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/orbits-lib/resources/orbits/geometry_backtracking.rb b/orbits-lib/resources/orbits/geometry_backtracking.rb index 84bab6c8f6..763fbdfbd0 100644 --- a/orbits-lib/resources/orbits/geometry_backtracking.rb +++ b/orbits-lib/resources/orbits/geometry_backtracking.rb @@ -96,6 +96,11 @@ def fast_bounding_rectangle_crossing_range(lat_range, north_deg, west_deg, south return [[lat_range, LongitudeCoverage.full]] end + # Shift north and south off start latitude a bit if there is an exact match, + # so that math could work. + north = start_lat_rad - EPSILON if north == start_lat_rad + south = start_lat_rad + EPSILON if south == start_lat_rad + # If the northern part of the bounding rectangle is above the orbit's starting latitude # and the southern part is below, split into two bounding rectangles, one entirely above # and one entirely below and backtrack each diff --git a/orbits-lib/resources/orbits/orbit.rb b/orbits-lib/resources/orbits/orbit.rb index 2815ba83a4..02c462e4b3 100644 --- a/orbits-lib/resources/orbits/orbit.rb +++ b/orbits-lib/resources/orbits/orbit.rb @@ -300,7 +300,8 @@ def horizontal_swath_edges(coord, ascending) # the swath width is measured perpendicular to the orbit, but the # Java code makes this assumption. This case should almost never # happen. When it does, the numbers are likely close enough. - if coord.phi == 0 + + if coord.phi.abs <= EPSILON return [Coordinate.phi_theta(0, coord.theta - swath_width_rad / 2), Coordinate.phi_theta(0, coord.theta + swath_width_rad / 2)] end @@ -415,7 +416,7 @@ def horizontal_swath_edges(coord, ascending) # We can't just compute constants for the line, because `b` could be near 0. # Let's deal with that special case first. - if b.abs < 0.000001 + if b.abs < EPSILON # If `b = 0`, then the plane's equation is: # @@ -429,7 +430,7 @@ def horizontal_swath_edges(coord, ascending) # case, we have an orbit that follows the equator. If coord lies within the # swath, then every orbit will cover the point, otherwise no orbits will. - if a.abs < 0.000001 + if a.abs < EPSILON if coord.phi.abs < swath_width_rad / 2 return [Coordinate.phi_theta(0, -PI), Coordinate.phi_theta(0, PI)] else diff --git a/system-int-test/test/cmr/system_int_test/search/granule_orbit_search_test.clj b/system-int-test/test/cmr/system_int_test/search/granule_orbit_search_test.clj index e2c77f80c7..d113bb8cb9 100644 --- a/system-int-test/test/cmr/system_int_test/search/granule_orbit_search_test.clj +++ b/system-int-test/test/cmr/system_int_test/search/granule_orbit_search_test.clj @@ -76,11 +76,10 @@ [granule] [150 70 170 60] "Rectangle not crossing the equator that should not find the granule" - [] [-128.32 53.602 -46.758 1.241])))) + [] [-128.32 53.602 -46.758 1.241] - ;; Test that needs to be fixed with CMR-4722 - ; "CMR-4722: Search crossing the equator should not erroneously find the granule" - ; [] [-128.32 53.602 -46.758 -1.241])))) + "CMR-4722: Search crossing the equator should not erroneously find the granule" + [] [-128.32 53.602 -46.758 -1.241])))) ;; This tests searching for bounding boxes or polygons that cross the start circular ;; latitude of the collection with fractional orbit granules. This was added to test @@ -223,9 +222,9 @@ matches?) "Orbits crossing a rectangle over the equator and anti-meridian" - [g2 g7 g9] [145 45 -145 -45] nil + [g2 g7] [145 45 -145 -45] nil "Orbits crossing a rectangle over the equator and meridian" - [g1 g3 g8 g9] [-45 45 45 -45] nil + [g1 g3 g8] [-45 45 45 -45] nil "Orbits crossing a rectangle in the western hemisphere near the north pole" [g5] [-90 89 -45 85] nil "Orbits crossing a rectangle in the southern hemisphere crossing the anti-meridian"