From 2ecf2d393af173b997f4b60d7ffd27f0e9b18746 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 1 Jun 2015 13:10:45 +0300 Subject: [PATCH 1/4] [policies][rescale policy] initialize the rescale policy only if the input geometries are non-empty; this fixes unit test failures (union, intersection, difference) when BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING is enabled; --- .../robustness/get_rescale_policy.hpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp index 52570995f..0a1d7e355 100644 --- a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -86,6 +87,11 @@ static inline void init_rescale_policy(Geometry const& geometry, RobustPoint& min_robust_point, Factor& factor) { + if (geometry::num_points(geometry) == 0) + { + return; + } + // Get bounding boxes model::box env = geometry::return_envelope >(geometry); @@ -99,10 +105,30 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, RobustPoint& min_robust_point, Factor& factor) { - // Get bounding boxes - model::box env = geometry::return_envelope >(geometry1); - model::box env2 = geometry::return_envelope >(geometry2); - geometry::expand(env, env2); + // Get bounding boxes (when at least one of the geometries is not empty) + model::box env; + if (geometry::num_points(geometry1) == 0 + && geometry::num_points(geometry2) == 0) + { + return; + } + else if (geometry::num_points(geometry1) == 0) + { + geometry::envelope(geometry2, env); + } + else if (geometry::num_points(geometry2) == 0) + { + geometry::envelope(geometry1, env); + } + else + { + geometry::envelope(geometry1, env); + model::box env2 = geometry::return_envelope + < + model::box + >(geometry2); + geometry::expand(env, env2); + } scale_box_to_integer_range(env, min_point, min_robust_point, factor); } From 87052dcebaf0c005e2b41ac02a799f508469ee2a Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 1 Jun 2015 16:21:27 +0300 Subject: [PATCH 2/4] [policies][rescale policy] compute number of points of each geometry only once --- .../geometry/policies/robustness/get_rescale_policy.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp index 0a1d7e355..1268d4cdb 100644 --- a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @@ -107,16 +107,17 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, { // Get bounding boxes (when at least one of the geometries is not empty) model::box env; - if (geometry::num_points(geometry1) == 0 - && geometry::num_points(geometry2) == 0) + bool is_empty1 = (geometry::num_points(geometry1) == 0); + bool is_empty2 = (geometry::num_points(geometry2) == 0); + if (is_empty1 == 0 && is_empty2) { return; } - else if (geometry::num_points(geometry1) == 0) + else if (is_empty1) { geometry::envelope(geometry2, env); } - else if (geometry::num_points(geometry2) == 0) + else if (is_empty2) { geometry::envelope(geometry1, env); } From da9b4c99392226e8e8fa0af256d2a632dd32273e Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 1 Jun 2015 23:45:52 +0300 Subject: [PATCH 3/4] [policies][rescale policy] apply coding rules; polish code; fix conditional expression; add comment regarding the computation of the bounding box when the geometries are in the spherical equatorial or geographic coordinate system; --- .../policies/robustness/get_rescale_policy.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp index 1268d4cdb..f985cf3bf 100644 --- a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @@ -106,14 +106,15 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, Factor& factor) { // Get bounding boxes (when at least one of the geometries is not empty) - model::box env; - bool is_empty1 = (geometry::num_points(geometry1) == 0); - bool is_empty2 = (geometry::num_points(geometry2) == 0); - if (is_empty1 == 0 && is_empty2) + bool const is_empty1 = geometry::num_points(geometry1) == 0; + bool const is_empty2 = geometry::num_points(geometry2) == 0; + if (is_empty1 && is_empty2) { return; } - else if (is_empty1) + + model::box env; + if (is_empty1) { geometry::envelope(geometry2, env); } @@ -123,6 +124,10 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, } else { + // The following approach (envelope + expand) may not give the + // optimal MBR when then two geometries are in the spherical + // equatorial or geographic coordinate systems. + // TODO: implement envelope for two (or possibly more geometries) geometry::envelope(geometry1, env); model::box env2 = geometry::return_envelope < From 32cf69186084c0fe7a7edf8025580c3f9af2085c Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 3 Jun 2015 17:31:45 +0300 Subject: [PATCH 4/4] [policies][get_rescale_policy] replace use of num_points() by is_empty() --- .../geometry/policies/robustness/get_rescale_policy.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp index f985cf3bf..e48fd28d6 100644 --- a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ static inline void init_rescale_policy(Geometry const& geometry, RobustPoint& min_robust_point, Factor& factor) { - if (geometry::num_points(geometry) == 0) + if (geometry::is_empty(geometry)) { return; } @@ -106,8 +106,8 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, Factor& factor) { // Get bounding boxes (when at least one of the geometries is not empty) - bool const is_empty1 = geometry::num_points(geometry1) == 0; - bool const is_empty2 = geometry::num_points(geometry2) == 0; + bool const is_empty1 = geometry::is_empty(geometry1); + bool const is_empty2 = geometry::is_empty(geometry2); if (is_empty1 && is_empty2) { return;