summaryrefslogtreecommitdiff
path: root/boost/geometry/geometries/point.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/geometry/geometries/point.hpp')
-rw-r--r--boost/geometry/geometries/point.hpp81
1 files changed, 71 insertions, 10 deletions
diff --git a/boost/geometry/geometries/point.hpp b/boost/geometry/geometries/point.hpp
index a25340c463..056c7d5d02 100644
--- a/boost/geometry/geometries/point.hpp
+++ b/boost/geometry/geometries/point.hpp
@@ -1,8 +1,14 @@
// 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) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
+// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
+// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
+
+// This file was modified by Oracle on 2014.
+// Modifications copyright (c) 2014, Oracle and/or its affiliates.
+
+// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@@ -23,7 +29,6 @@
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/coordinate_system.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
-#include <boost/geometry/util/math.hpp>
namespace boost { namespace geometry
{
@@ -38,6 +43,37 @@ namespace boost { namespace geometry
namespace model
{
+namespace detail
+{
+
+template <std::size_t DimensionCount, std::size_t Index>
+struct array_assign
+{
+ template <typename T>
+ static inline void apply(T values[], T const& value)
+ {
+ values[Index] = value;
+ }
+};
+
+// Specialization avoiding assigning element [2] for only 2 dimensions
+template <> struct array_assign<2, 2>
+{
+ template <typename T> static inline void apply(T [], T const& ) {}
+};
+
+// Specialization avoiding assigning elements for (rarely used) points in 1 dim
+template <> struct array_assign<1, 1>
+{
+ template <typename T> static inline void apply(T [], T const& ) {}
+};
+
+template <> struct array_assign<1, 2>
+{
+ template <typename T> static inline void apply(T [], T const& ) {}
+};
+
+}
/*!
\brief Basic point class, having coordinates defined in a neutral way
\details Defines a neutral point class, fulfilling the Point Concept.
@@ -64,18 +100,43 @@ template
>
class point
{
+private:
+ // The following enum is used to fully instantiate the
+ // CoordinateSystem class and check the correctness of the units
+ // passed for non-Cartesian coordinate systems.
+ enum { cs_check = sizeof(CoordinateSystem) };
+
public:
/// @brief Default constructor, no initialization
inline point()
- {}
+ {
+ BOOST_STATIC_ASSERT(DimensionCount >= 1);
+ }
+
+ /// @brief Constructor to set one value
+ explicit inline point(CoordinateType const& v0)
+ {
+ detail::array_assign<DimensionCount, 0>::apply(m_values, v0);
+ detail::array_assign<DimensionCount, 1>::apply(m_values, CoordinateType());
+ detail::array_assign<DimensionCount, 2>::apply(m_values, CoordinateType());
+ }
+
+ /// @brief Constructor to set two values
+ inline point(CoordinateType const& v0, CoordinateType const& v1)
+ {
+ detail::array_assign<DimensionCount, 0>::apply(m_values, v0);
+ detail::array_assign<DimensionCount, 1>::apply(m_values, v1);
+ detail::array_assign<DimensionCount, 2>::apply(m_values, CoordinateType());
+ }
- /// @brief Constructor to set one, two or three values
- explicit inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0)
+ /// @brief Constructor to set three values
+ inline point(CoordinateType const& v0, CoordinateType const& v1,
+ CoordinateType const& v2)
{
- if (DimensionCount >= 1) m_values[0] = v0;
- if (DimensionCount >= 2) m_values[1] = v1;
- if (DimensionCount >= 3) m_values[2] = v2;
+ detail::array_assign<DimensionCount, 0>::apply(m_values, v0);
+ detail::array_assign<DimensionCount, 1>::apply(m_values, v1);
+ detail::array_assign<DimensionCount, 2>::apply(m_values, v2);
}
/// @brief Get a coordinate