| 1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
| 2 | |
| 3 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. |
| 4 | // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. |
| 5 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. |
| 6 | |
| 7 | // This file was modified by Oracle on 2020. |
| 8 | // Modifications copyright (c) 2020, Oracle and/or its affiliates. |
| 9 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
| 10 | |
| 11 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
| 12 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. |
| 13 | |
| 14 | // Use, modification and distribution is subject to the Boost Software License, |
| 15 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 16 | // http://www.boost.org/LICENSE_1_0.txt) |
| 17 | |
| 18 | #ifndef BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
| 19 | #define BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
| 20 | |
| 21 | |
| 22 | #include <cstddef> |
| 23 | |
| 24 | #include <boost/geometry/core/point_type.hpp> |
| 25 | #include <boost/geometry/core/static_assert.hpp> |
| 26 | #include <boost/geometry/util/type_traits_std.hpp> |
| 27 | |
| 28 | namespace boost { namespace geometry |
| 29 | { |
| 30 | |
| 31 | namespace traits |
| 32 | { |
| 33 | |
| 34 | /*! |
| 35 | \brief Traits class indicating the number of dimensions of a point |
| 36 | \par Geometries: |
| 37 | - point |
| 38 | \par Specializations should provide: |
| 39 | - value (e.g. derived from std::integral_constant<std::size_t, D>) |
| 40 | \ingroup traits |
| 41 | */ |
| 42 | template <typename Point, typename Enable = void> |
| 43 | struct dimension |
| 44 | { |
| 45 | BOOST_GEOMETRY_STATIC_ASSERT_FALSE( |
| 46 | "Not implemented for this Point type." , |
| 47 | Point); |
| 48 | }; |
| 49 | |
| 50 | } // namespace traits |
| 51 | |
| 52 | #ifndef DOXYGEN_NO_DISPATCH |
| 53 | namespace core_dispatch |
| 54 | { |
| 55 | |
| 56 | // Base class derive from its own specialization of point-tag |
| 57 | template <typename T, typename G> |
| 58 | struct dimension |
| 59 | : dimension<point_tag, typename point_type<T, G>::type>::type |
| 60 | {}; |
| 61 | |
| 62 | template <typename P> |
| 63 | struct dimension<point_tag, P> |
| 64 | : std::integral_constant |
| 65 | < |
| 66 | std::size_t, |
| 67 | traits::dimension<util::remove_cptrref_t<P>>::value |
| 68 | > |
| 69 | { |
| 70 | BOOST_GEOMETRY_STATIC_ASSERT( |
| 71 | (traits::dimension<util::remove_cptrref_t<P>>::value > 0), |
| 72 | "Dimension has to be greater than 0." , |
| 73 | traits::dimension<util::remove_cptrref_t<P>> |
| 74 | ); |
| 75 | }; |
| 76 | |
| 77 | } // namespace core_dispatch |
| 78 | #endif |
| 79 | |
| 80 | /*! |
| 81 | \brief \brief_meta{value, number of coordinates (the number of axes of any geometry), \meta_point_type} |
| 82 | \tparam Geometry \tparam_geometry |
| 83 | \ingroup core |
| 84 | |
| 85 | \qbk{[include reference/core/coordinate_dimension.qbk]} |
| 86 | */ |
| 87 | template <typename Geometry> |
| 88 | struct dimension |
| 89 | : core_dispatch::dimension |
| 90 | < |
| 91 | typename tag<Geometry>::type, |
| 92 | typename util::remove_cptrref<Geometry>::type |
| 93 | > |
| 94 | {}; |
| 95 | |
| 96 | /*! |
| 97 | \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected |
| 98 | \ingroup utility |
| 99 | */ |
| 100 | template <typename Geometry, std::size_t Dimensions> |
| 101 | constexpr inline void assert_dimension() |
| 102 | { |
| 103 | BOOST_STATIC_ASSERT(( dimension<Geometry>::value == Dimensions )); |
| 104 | } |
| 105 | |
| 106 | /*! |
| 107 | \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected |
| 108 | \ingroup utility |
| 109 | */ |
| 110 | template <typename Geometry, std::size_t Dimensions> |
| 111 | constexpr inline void assert_dimension_less_equal() |
| 112 | { |
| 113 | BOOST_STATIC_ASSERT(( dimension<Geometry>::value <= Dimensions )); |
| 114 | } |
| 115 | |
| 116 | template <typename Geometry, std::size_t Dimensions> |
| 117 | constexpr inline void assert_dimension_greater_equal() |
| 118 | { |
| 119 | BOOST_STATIC_ASSERT(( dimension<Geometry>::value >= Dimensions )); |
| 120 | } |
| 121 | |
| 122 | /*! |
| 123 | \brief assert_dimension_equal, enables compile-time checking if coordinate dimensions of two geometries are equal |
| 124 | \ingroup utility |
| 125 | */ |
| 126 | template <typename G1, typename G2> |
| 127 | constexpr inline void assert_dimension_equal() |
| 128 | { |
| 129 | BOOST_STATIC_ASSERT(( dimension<G1>::value == dimension<G2>::value )); |
| 130 | } |
| 131 | |
| 132 | }} // namespace boost::geometry |
| 133 | |
| 134 | #endif // BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
| 135 | |