123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- #ifndef BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
- #define BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
- #include <cstddef>
- #include <type_traits>
- #include <boost/static_assert.hpp>
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/core/coordinate_system.hpp>
- #include <boost/geometry/core/coordinate_dimension.hpp>
- #include <boost/geometry/core/make.hpp>
- #include <boost/geometry/core/tag.hpp>
- #include <boost/geometry/core/tags.hpp>
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- #include <algorithm>
- #include <boost/geometry/core/assert.hpp>
- #endif
- namespace boost { namespace geometry
- {
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4127)
- #endif
- namespace detail
- {
- template <typename Dummy, std::size_t N, std::size_t DimensionCount>
- struct is_coordinates_number_leq
- {
- static const bool value = (N <= DimensionCount);
- };
- template <typename Dummy, std::size_t N, std::size_t DimensionCount>
- struct is_coordinates_number_eq
- {
- static const bool value = (N == DimensionCount);
- };
- }
- namespace model
- {
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- class point
- {
- BOOST_STATIC_ASSERT(DimensionCount > 0);
-
-
-
- enum { cs_check = sizeof(CoordinateSystem) };
- public:
-
-
-
- #if !defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
-
- constexpr point()
- #if defined(_MSC_VER) && (_MSC_VER < 1910)
- : m_values{} {}
- #else
- = default;
- #endif
- #else
- point()
- {
- m_created = 1;
- std::fill_n(m_values_initialized, DimensionCount, 0);
- }
- ~point()
- {
- m_created = 0;
- std::fill_n(m_values_initialized, DimensionCount, 0);
- }
- #endif
-
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_leq<C, 1, DimensionCount>::value, int> = 0
- >
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- explicit point(CoordinateType const& v0)
- : m_values{v0}
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- m_created = 1;
- std::fill_n(m_values_initialized, DimensionCount, 1);
- #endif
- }
-
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_leq<C, 2, DimensionCount>::value, int> = 0
- >
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- point(CoordinateType const& v0, CoordinateType const& v1)
- : m_values{ v0, v1 }
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- m_created = 1;
- std::fill_n(m_values_initialized, DimensionCount, 1);
- #endif
- }
-
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_leq<C, 3, DimensionCount>::value, int> = 0
- >
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- point(CoordinateType const& v0, CoordinateType const& v1, CoordinateType const& v2)
- : m_values{ v0, v1, v2 }
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- m_created = 1;
- std::fill_n(m_values_initialized, DimensionCount, 1);
- #endif
- }
-
-
-
- template <std::size_t K>
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- CoordinateType const& get() const
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- BOOST_GEOMETRY_ASSERT(m_values_initialized[K] == 1);
- #endif
- BOOST_STATIC_ASSERT(K < DimensionCount);
- return m_values[K];
- }
-
-
-
- template <std::size_t K>
- void set(CoordinateType const& value)
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- m_values_initialized[K] = 1;
- #endif
- BOOST_STATIC_ASSERT(K < DimensionCount);
- m_values[K] = value;
- }
- private:
- CoordinateType m_values[DimensionCount];
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- int m_created;
- int m_values_initialized[DimensionCount];
- #endif
- };
- }
- #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
- namespace traits
- {
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- struct tag<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
- {
- typedef point_tag type;
- };
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- struct coordinate_type<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
- {
- typedef CoordinateType type;
- };
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- struct coordinate_system<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
- {
- typedef CoordinateSystem type;
- };
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- struct dimension<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
- : std::integral_constant<std::size_t, DimensionCount>
- {};
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem,
- std::size_t Dimension
- >
- struct access<model::point<CoordinateType, DimensionCount, CoordinateSystem>, Dimension>
- {
- static constexpr CoordinateType get(
- model::point<CoordinateType, DimensionCount, CoordinateSystem> const& p)
- {
- return p.template get<Dimension>();
- }
- static void set(
- model::point<CoordinateType, DimensionCount, CoordinateSystem>& p,
- CoordinateType const& value)
- {
- p.template set<Dimension>(value);
- }
- };
- template
- <
- typename CoordinateType,
- std::size_t DimensionCount,
- typename CoordinateSystem
- >
- struct make<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
- {
- typedef model::point<CoordinateType, DimensionCount, CoordinateSystem> point_type;
- static const bool is_specialized = true;
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_eq<C, 1, DimensionCount>::value, int> = 0
- >
- static constexpr point_type apply(CoordinateType const& v0)
- {
- return point_type(v0);
- }
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_eq<C, 2, DimensionCount>::value, int> = 0
- >
- static constexpr point_type apply(CoordinateType const& v0,
- CoordinateType const& v1)
- {
- return point_type(v0, v1);
- }
- template
- <
- typename C = CoordinateType,
- std::enable_if_t<geometry::detail::is_coordinates_number_eq<C, 3, DimensionCount>::value, int> = 0
- >
- static constexpr point_type apply(CoordinateType const& v0,
- CoordinateType const& v1,
- CoordinateType const& v2)
- {
- return point_type(v0, v1, v2);
- }
- };
- }
- #endif
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
- }}
- #endif
|