From 3a522f11f66e056a88d855c19fa164341d6a307e Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Wed, 5 Aug 2015 00:59:44 +0200 Subject: [PATCH] [extensions][nsphere][within][strategies] For NSphere/Box and Point/Nsphere take into account machine epsilon. --- .../extensions/nsphere/algorithms/within.hpp | 12 +++++----- .../strategies/cartesian/nsphere_in_box.hpp | 15 ++++++++----- .../strategies/cartesian/point_in_nsphere.hpp | 22 ++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/include/boost/geometry/extensions/nsphere/algorithms/within.hpp b/include/boost/geometry/extensions/nsphere/algorithms/within.hpp index 72119ec43..7056a5aed 100644 --- a/include/boost/geometry/extensions/nsphere/algorithms/within.hpp +++ b/include/boost/geometry/extensions/nsphere/algorithms/within.hpp @@ -1,9 +1,9 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -28,6 +28,8 @@ #include #include +#include + namespace boost { namespace geometry { @@ -66,7 +68,7 @@ inline bool point_in_circle(P const& p, C const& c) strategy_type, P, point_type >::apply(strategy, get_radius<0>(c)); - return r < rad; + return math::smaller(r, rad); } /// 2D version template diff --git a/include/boost/geometry/extensions/nsphere/strategies/cartesian/nsphere_in_box.hpp b/include/boost/geometry/extensions/nsphere/strategies/cartesian/nsphere_in_box.hpp index 1086126f8..c43b68b50 100644 --- a/include/boost/geometry/extensions/nsphere/strategies/cartesian/nsphere_in_box.hpp +++ b/include/boost/geometry/extensions/nsphere/strategies/cartesian/nsphere_in_box.hpp @@ -1,9 +1,9 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, London, UK. +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2015 Adam Wulkiewicz, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -20,6 +20,7 @@ #include #include #include +#include namespace boost { namespace geometry { namespace strategy @@ -36,7 +37,8 @@ struct nsphere_within_range , ContainingValue const& ing_min , ContainingValue const& ing_max) { - return ing_min < ed_min && ed_max < ing_max; + return math::smaller(ing_min, ed_min) + && math::smaller(ed_max, ing_max); } }; @@ -49,7 +51,8 @@ struct nsphere_covered_by_range , ContainingValue const& ing_min , ContainingValue const& ing_max) { - return ing_min <= ed_min && ed_max <= ing_max; + return math::smaller_or_equals(ing_min, ed_min) + && math::smaller_or_equals(ed_max, ing_max); } }; diff --git a/include/boost/geometry/extensions/nsphere/strategies/cartesian/point_in_nsphere.hpp b/include/boost/geometry/extensions/nsphere/strategies/cartesian/point_in_nsphere.hpp index 3ebed5ab0..76cc6637f 100644 --- a/include/boost/geometry/extensions/nsphere/strategies/cartesian/point_in_nsphere.hpp +++ b/include/boost/geometry/extensions/nsphere/strategies/cartesian/point_in_nsphere.hpp @@ -1,9 +1,9 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, London, UK. +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2015 Adam Wulkiewicz, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -23,6 +23,8 @@ #include +#include + namespace boost { namespace geometry { namespace strategy { @@ -32,10 +34,10 @@ namespace within struct point_nsphere_within_comparable_distance { template - static inline bool apply(ComparableDistance const& ed_comp_dist - , Radius const& ing_radius) + static inline bool apply(ComparableDistance const& ed_comp_dist, + Radius const& ing_radius) { - return ed_comp_dist < ing_radius * ing_radius; + return math::smaller(ed_comp_dist, ing_radius * ing_radius); } }; @@ -43,10 +45,10 @@ struct point_nsphere_within_comparable_distance struct point_nsphere_covered_by_comparable_distance { template - static inline bool apply(ComparableDistance const& ed_comp_dist - , Radius const& ing_radius) + static inline bool apply(ComparableDistance const& ed_comp_dist, + Radius const& ing_radius) { - return ed_comp_dist <= ing_radius * ing_radius; + return math::smaller_or_equals(ed_comp_dist, ing_radius * ing_radius); } };