transform_units.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_TRANSFORM_UNITS_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_TRANSFORM_UNITS_HPP
  9. #include <cstddef>
  10. #include <boost/geometry/core/tag.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/strategies/strategy_transform.hpp>
  13. #include <boost/geometry/views/detail/indexed_point_view.hpp>
  14. #include <boost/geometry/views/detail/two_dimensional_view.hpp>
  15. #include <boost/geometry/algorithms/not_implemented.hpp>
  16. #include <boost/geometry/algorithms/transform.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail { namespace envelope
  21. {
  22. template
  23. <
  24. typename GeometryIn,
  25. typename GeometryOut,
  26. typename TagIn = typename tag<GeometryIn>::type,
  27. typename TagOut = typename tag<GeometryOut>::type
  28. >
  29. struct transform_units_impl
  30. : not_implemented<TagIn, TagOut>
  31. {};
  32. template <typename PointIn, typename PointOut>
  33. struct transform_units_impl<PointIn, PointOut, point_tag, point_tag>
  34. {
  35. static inline void apply(PointIn const& point_in, PointOut& point_out)
  36. {
  37. detail::two_dimensional_view<PointIn const> view_in(point_in);
  38. detail::two_dimensional_view<PointOut> view_out(point_out);
  39. geometry::transform(view_in, view_out);
  40. }
  41. };
  42. template <typename BoxIn, typename BoxOut>
  43. struct transform_units_impl<BoxIn, BoxOut, box_tag, box_tag>
  44. {
  45. template <std::size_t Index>
  46. static inline void apply(BoxIn const& box_in, BoxOut& box_out)
  47. {
  48. typedef detail::indexed_point_view<BoxIn const, Index> view_in_type;
  49. typedef detail::indexed_point_view<BoxOut, Index> view_out_type;
  50. view_in_type view_in(box_in);
  51. view_out_type view_out(box_out);
  52. transform_units_impl
  53. <
  54. view_in_type, view_out_type
  55. >::apply(view_in, view_out);
  56. }
  57. static inline void apply(BoxIn const& box_in, BoxOut& box_out)
  58. {
  59. apply<min_corner>(box_in, box_out);
  60. apply<max_corner>(box_in, box_out);
  61. }
  62. };
  63. // Short utility to transform the units of the first two coordinates of
  64. // geometry_in to the units of geometry_out
  65. template <typename GeometryIn, typename GeometryOut>
  66. inline void transform_units(GeometryIn const& geometry_in,
  67. GeometryOut& geometry_out)
  68. {
  69. transform_units_impl
  70. <
  71. GeometryIn, GeometryOut
  72. >::apply(geometry_in, geometry_out);
  73. }
  74. }} // namespace detail::envelope
  75. #endif // DOXYGEN_NO_DETAIL
  76. }} // namespace boost:geometry
  77. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_TRANSFORM_UNITS_HPP