mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-02 08:52:10 +00:00
Merge pull request #301 from mkaravel/fix/bounding_box_computation_in_get_rescale_policy
Fix: initialize the rescale policy only if the input geometries are non-empty
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <boost/geometry/algorithms/envelope.hpp>
|
||||
#include <boost/geometry/algorithms/expand.hpp>
|
||||
#include <boost/geometry/algorithms/is_empty.hpp>
|
||||
#include <boost/geometry/algorithms/detail/recalculate.hpp>
|
||||
#include <boost/geometry/algorithms/detail/get_max_size.hpp>
|
||||
#include <boost/geometry/policies/robustness/robust_type.hpp>
|
||||
@@ -87,6 +88,11 @@ static inline void init_rescale_policy(Geometry const& geometry,
|
||||
RobustPoint& min_robust_point,
|
||||
Factor& factor)
|
||||
{
|
||||
if (geometry::is_empty(geometry))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get bounding boxes
|
||||
model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry);
|
||||
|
||||
@@ -100,10 +106,36 @@ static inline void init_rescale_policy(Geometry1 const& geometry1,
|
||||
RobustPoint& min_robust_point,
|
||||
Factor& factor)
|
||||
{
|
||||
// Get bounding boxes
|
||||
model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry1);
|
||||
model::box<Point> env2 = geometry::return_envelope<model::box<Point> >(geometry2);
|
||||
geometry::expand(env, env2);
|
||||
// Get bounding boxes (when at least one of the geometries is not empty)
|
||||
bool const is_empty1 = geometry::is_empty(geometry1);
|
||||
bool const is_empty2 = geometry::is_empty(geometry2);
|
||||
if (is_empty1 && is_empty2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
model::box<Point> env;
|
||||
if (is_empty1)
|
||||
{
|
||||
geometry::envelope(geometry2, env);
|
||||
}
|
||||
else if (is_empty2)
|
||||
{
|
||||
geometry::envelope(geometry1, env);
|
||||
}
|
||||
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<Point> env2 = geometry::return_envelope
|
||||
<
|
||||
model::box<Point>
|
||||
>(geometry2);
|
||||
geometry::expand(env, env2);
|
||||
}
|
||||
|
||||
scale_box_to_integer_range(env, min_point, min_robust_point, factor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user