annotate DEPENDENCIES/generic/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@102 2
Chris@102 3 // Copyright (c) 2014-2015 Barend Gehrels, Amsterdam, the Netherlands.
Chris@102 4 // Copyright (c) 2014-2015 Bruno Lalande, Paris, France.
Chris@102 5 // Copyright (c) 2014-2015 Mateusz Loskot, London, UK.
Chris@102 6 // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
Chris@102 7
Chris@102 8 // This file was modified by Oracle on 2015.
Chris@102 9 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
Chris@102 10
Chris@102 11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
Chris@102 12
Chris@102 13 // Use, modification and distribution is subject to the Boost Software License,
Chris@102 14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 15 // http://www.boost.org/LICENSE_1_0.txt)
Chris@102 16
Chris@102 17 #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP
Chris@102 18 #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP
Chris@102 19
Chris@102 20
Chris@102 21 #include <cstddef>
Chris@102 22
Chris@102 23 #include <boost/type_traits.hpp>
Chris@102 24 #include <boost/mpl/assert.hpp>
Chris@102 25
Chris@102 26 #include <boost/geometry/core/tag_cast.hpp>
Chris@102 27
Chris@102 28 #include <boost/geometry/algorithms/envelope.hpp>
Chris@102 29 #include <boost/geometry/algorithms/expand.hpp>
Chris@102 30 #include <boost/geometry/algorithms/detail/recalculate.hpp>
Chris@102 31 #include <boost/geometry/algorithms/detail/get_max_size.hpp>
Chris@102 32 #include <boost/geometry/policies/robustness/robust_type.hpp>
Chris@102 33
Chris@102 34 #include <boost/geometry/geometries/point.hpp>
Chris@102 35 #include <boost/geometry/geometries/box.hpp>
Chris@102 36
Chris@102 37 #include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
Chris@102 38 #include <boost/geometry/policies/robustness/rescale_policy.hpp>
Chris@102 39
Chris@102 40 #include <boost/geometry/util/promote_floating_point.hpp>
Chris@102 41
Chris@102 42 namespace boost { namespace geometry
Chris@102 43 {
Chris@102 44
Chris@102 45 #ifndef DOXYGEN_NO_DETAIL
Chris@102 46 namespace detail { namespace get_rescale_policy
Chris@102 47 {
Chris@102 48
Chris@102 49 template
Chris@102 50 <
Chris@102 51 typename Box,
Chris@102 52 typename Point,
Chris@102 53 typename RobustPoint,
Chris@102 54 typename Factor
Chris@102 55 >
Chris@102 56 inline void scale_box_to_integer_range(Box const& box,
Chris@102 57 Point& min_point,
Chris@102 58 RobustPoint& min_robust_point,
Chris@102 59 Factor& factor)
Chris@102 60 {
Chris@102 61 // Scale box to integer-range
Chris@102 62 typedef typename promote_floating_point
Chris@102 63 <
Chris@102 64 typename geometry::coordinate_type<Point>::type
Chris@102 65 >::type num_type;
Chris@102 66 num_type const diff = boost::numeric_cast<num_type>(detail::get_max_size(box));
Chris@102 67 num_type const range = 10000000.0; // Define a large range to get precise integer coordinates
Chris@102 68 num_type const half = 0.5;
Chris@102 69 factor = math::equals(diff, num_type()) || diff >= range ? 1
Chris@102 70 : boost::numeric_cast<num_type>(
Chris@102 71 boost::numeric_cast<boost::long_long_type>(half + range / diff));
Chris@102 72
Chris@102 73 BOOST_ASSERT(factor >= 1);
Chris@102 74
Chris@102 75 // Assign input/output minimal points
Chris@102 76 detail::assign_point_from_index<0>(box, min_point);
Chris@102 77 num_type const two = 2;
Chris@102 78 boost::long_long_type const min_coordinate
Chris@102 79 = boost::numeric_cast<boost::long_long_type>(-range / two);
Chris@102 80 assign_values(min_robust_point, min_coordinate, min_coordinate);
Chris@102 81 }
Chris@102 82
Chris@102 83 template <typename Point, typename RobustPoint, typename Geometry, typename Factor>
Chris@102 84 static inline void init_rescale_policy(Geometry const& geometry,
Chris@102 85 Point& min_point,
Chris@102 86 RobustPoint& min_robust_point,
Chris@102 87 Factor& factor)
Chris@102 88 {
Chris@102 89 // Get bounding boxes
Chris@102 90 model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry);
Chris@102 91
Chris@102 92 scale_box_to_integer_range(env, min_point, min_robust_point, factor);
Chris@102 93 }
Chris@102 94
Chris@102 95 template <typename Point, typename RobustPoint, typename Geometry1, typename Geometry2, typename Factor>
Chris@102 96 static inline void init_rescale_policy(Geometry1 const& geometry1,
Chris@102 97 Geometry2 const& geometry2,
Chris@102 98 Point& min_point,
Chris@102 99 RobustPoint& min_robust_point,
Chris@102 100 Factor& factor)
Chris@102 101 {
Chris@102 102 // Get bounding boxes
Chris@102 103 model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry1);
Chris@102 104 model::box<Point> env2 = geometry::return_envelope<model::box<Point> >(geometry2);
Chris@102 105 geometry::expand(env, env2);
Chris@102 106
Chris@102 107 scale_box_to_integer_range(env, min_point, min_robust_point, factor);
Chris@102 108 }
Chris@102 109
Chris@102 110
Chris@102 111 template
Chris@102 112 <
Chris@102 113 typename Point,
Chris@102 114 bool IsFloatingPoint
Chris@102 115 >
Chris@102 116 struct rescale_policy_type
Chris@102 117 {
Chris@102 118 typedef no_rescale_policy type;
Chris@102 119 };
Chris@102 120
Chris@102 121 // We rescale only all FP types
Chris@102 122 template
Chris@102 123 <
Chris@102 124 typename Point
Chris@102 125 >
Chris@102 126 struct rescale_policy_type<Point, true>
Chris@102 127 {
Chris@102 128 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
Chris@102 129 typedef model::point
Chris@102 130 <
Chris@102 131 typename detail::robust_type<coordinate_type>::type,
Chris@102 132 geometry::dimension<Point>::value,
Chris@102 133 typename geometry::coordinate_system<Point>::type
Chris@102 134 > robust_point_type;
Chris@102 135 typedef typename promote_floating_point<coordinate_type>::type factor_type;
Chris@102 136 typedef detail::robust_policy<Point, robust_point_type, factor_type> type;
Chris@102 137 };
Chris@102 138
Chris@102 139 template <typename Policy>
Chris@102 140 struct get_rescale_policy
Chris@102 141 {
Chris@102 142 template <typename Geometry>
Chris@102 143 static inline Policy apply(Geometry const& geometry)
Chris@102 144 {
Chris@102 145 typedef typename point_type<Geometry>::type point_type;
Chris@102 146 typedef typename geometry::coordinate_type<Geometry>::type coordinate_type;
Chris@102 147 typedef typename promote_floating_point<coordinate_type>::type factor_type;
Chris@102 148 typedef model::point
Chris@102 149 <
Chris@102 150 typename detail::robust_type<coordinate_type>::type,
Chris@102 151 geometry::dimension<point_type>::value,
Chris@102 152 typename geometry::coordinate_system<point_type>::type
Chris@102 153 > robust_point_type;
Chris@102 154
Chris@102 155 point_type min_point;
Chris@102 156 robust_point_type min_robust_point;
Chris@102 157 factor_type factor;
Chris@102 158 init_rescale_policy(geometry, min_point, min_robust_point, factor);
Chris@102 159
Chris@102 160 return Policy(min_point, min_robust_point, factor);
Chris@102 161 }
Chris@102 162
Chris@102 163 template <typename Geometry1, typename Geometry2>
Chris@102 164 static inline Policy apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
Chris@102 165 {
Chris@102 166 typedef typename point_type<Geometry1>::type point_type;
Chris@102 167 typedef typename geometry::coordinate_type<Geometry1>::type coordinate_type;
Chris@102 168 typedef typename promote_floating_point<coordinate_type>::type factor_type;
Chris@102 169 typedef model::point
Chris@102 170 <
Chris@102 171 typename detail::robust_type<coordinate_type>::type,
Chris@102 172 geometry::dimension<point_type>::value,
Chris@102 173 typename geometry::coordinate_system<point_type>::type
Chris@102 174 > robust_point_type;
Chris@102 175
Chris@102 176 point_type min_point;
Chris@102 177 robust_point_type min_robust_point;
Chris@102 178 factor_type factor;
Chris@102 179 init_rescale_policy(geometry1, geometry2, min_point, min_robust_point, factor);
Chris@102 180
Chris@102 181 return Policy(min_point, min_robust_point, factor);
Chris@102 182 }
Chris@102 183 };
Chris@102 184
Chris@102 185 // Specialization for no-rescaling
Chris@102 186 template <>
Chris@102 187 struct get_rescale_policy<no_rescale_policy>
Chris@102 188 {
Chris@102 189 template <typename Geometry>
Chris@102 190 static inline no_rescale_policy apply(Geometry const& )
Chris@102 191 {
Chris@102 192 return no_rescale_policy();
Chris@102 193 }
Chris@102 194
Chris@102 195 template <typename Geometry1, typename Geometry2>
Chris@102 196 static inline no_rescale_policy apply(Geometry1 const& , Geometry2 const& )
Chris@102 197 {
Chris@102 198 return no_rescale_policy();
Chris@102 199 }
Chris@102 200 };
Chris@102 201
Chris@102 202
Chris@102 203 }} // namespace detail::get_rescale_policy
Chris@102 204 #endif // DOXYGEN_NO_DETAIL
Chris@102 205
Chris@102 206 template<typename Point>
Chris@102 207 struct rescale_policy_type
Chris@102 208 : public detail::get_rescale_policy::rescale_policy_type
Chris@102 209 <
Chris@102 210 Point,
Chris@102 211 #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
Chris@102 212 false
Chris@102 213 #else
Chris@102 214 boost::is_floating_point
Chris@102 215 <
Chris@102 216 typename geometry::coordinate_type<Point>::type
Chris@102 217 >::type::value
Chris@102 218 #endif
Chris@102 219 >
Chris@102 220 {
Chris@102 221 static const bool is_point
Chris@102 222 = boost::is_same
Chris@102 223 <
Chris@102 224 typename geometry::tag<Point>::type,
Chris@102 225 geometry::point_tag
Chris@102 226 >::type::value;
Chris@102 227
Chris@102 228 BOOST_MPL_ASSERT_MSG((is_point),
Chris@102 229 INVALID_INPUT_GEOMETRY,
Chris@102 230 (typename geometry::tag<Point>::type));
Chris@102 231 };
Chris@102 232
Chris@102 233
Chris@102 234 template
Chris@102 235 <
Chris@102 236 typename Geometry1,
Chris@102 237 typename Geometry2,
Chris@102 238 typename Tag1 = typename tag_cast
Chris@102 239 <
Chris@102 240 typename tag<Geometry1>::type,
Chris@102 241 box_tag,
Chris@102 242 pointlike_tag,
Chris@102 243 linear_tag,
Chris@102 244 areal_tag
Chris@102 245 >::type,
Chris@102 246 typename Tag2 = typename tag_cast
Chris@102 247 <
Chris@102 248 typename tag<Geometry2>::type,
Chris@102 249 box_tag,
Chris@102 250 pointlike_tag,
Chris@102 251 linear_tag,
Chris@102 252 areal_tag
Chris@102 253 >::type
Chris@102 254 >
Chris@102 255 struct rescale_overlay_policy_type
Chris@102 256 // Default: no rescaling
Chris@102 257 : public detail::get_rescale_policy::rescale_policy_type
Chris@102 258 <
Chris@102 259 typename geometry::point_type<Geometry1>::type,
Chris@102 260 false
Chris@102 261 >
Chris@102 262 {};
Chris@102 263
Chris@102 264 // Areal/areal: get rescale policy based on coordinate type
Chris@102 265 template
Chris@102 266 <
Chris@102 267 typename Geometry1,
Chris@102 268 typename Geometry2
Chris@102 269 >
Chris@102 270 struct rescale_overlay_policy_type<Geometry1, Geometry2, areal_tag, areal_tag>
Chris@102 271 : public rescale_policy_type
Chris@102 272 <
Chris@102 273 typename geometry::point_type<Geometry1>::type
Chris@102 274 >
Chris@102 275 {};
Chris@102 276
Chris@102 277
Chris@102 278 template <typename Policy, typename Geometry>
Chris@102 279 inline Policy get_rescale_policy(Geometry const& geometry)
Chris@102 280 {
Chris@102 281 return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry);
Chris@102 282 }
Chris@102 283
Chris@102 284 template <typename Policy, typename Geometry1, typename Geometry2>
Chris@102 285 inline Policy get_rescale_policy(Geometry1 const& geometry1, Geometry2 const& geometry2)
Chris@102 286 {
Chris@102 287 return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry1, geometry2);
Chris@102 288 }
Chris@102 289
Chris@102 290
Chris@102 291 }} // namespace boost::geometry
Chris@102 292
Chris@102 293
Chris@102 294 #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP