Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84549 - in trunk/boost/geometry/extensions/algebra: . algorithms core geometries geometries/concepts
From: adam.wulkiewicz_at_[hidden]
Date: 2013-05-29 19:18:09


Author: awulkiew
Date: 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
New Revision: 84549
URL: http://svn.boost.org/trac/boost/changeset/84549

Log:
geometry extensions: Added rotation_quaternion, rotation(), transform_geometrically(), etc.
Added:
   trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp (contents, props changed)
   trunk/boost/geometry/extensions/algebra/algorithms/transform.hpp (contents, props changed)
   trunk/boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp (contents, props changed)
   trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp (contents, props changed)
Text files modified:
   trunk/boost/geometry/extensions/algebra/algebra.hpp | 5 ++++-
   trunk/boost/geometry/extensions/algebra/core/access.hpp | 25 +++++++++++++++++++++++++
   trunk/boost/geometry/extensions/algebra/core/coordinate_dimension.hpp | 5 +++++
   trunk/boost/geometry/extensions/algebra/core/coordinate_system.hpp | 15 +++++++++++----
   trunk/boost/geometry/extensions/algebra/core/coordinate_type.hpp | 15 +++++++++++----
   trunk/boost/geometry/extensions/algebra/core/tags.hpp | 2 +-
   trunk/boost/geometry/extensions/algebra/core/topological_dimension.hpp | 8 +++++---
   trunk/boost/geometry/extensions/algebra/geometries/concepts/check.hpp | 10 ++++++++++
   8 files changed, 72 insertions(+), 13 deletions(-)

Modified: trunk/boost/geometry/extensions/algebra/algebra.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algebra.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/algebra.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -23,15 +23,18 @@
 #include <boost/geometry/extensions/algebra/core/topological_dimension.hpp>
 
 #include <boost/geometry/extensions/algebra/geometries/concepts/vector_concept.hpp>
+#include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
 #include <boost/geometry/extensions/algebra/geometries/concepts/check.hpp>
 
 #include <boost/geometry/extensions/algebra/geometries/vector.hpp>
+#include <boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp>
 
 #include <boost/geometry/extensions/algebra/algorithms/assign.hpp>
 #include <boost/geometry/extensions/algebra/algorithms/clear.hpp>
 #include <boost/geometry/extensions/algebra/algorithms/num_points.hpp>
 
 #include <boost/geometry/extensions/algebra/algorithms/translation.hpp>
-#include <boost/geometry/extensions/algebra/algorithms/translate.hpp>
+#include <boost/geometry/extensions/algebra/algorithms/rotation.hpp>
+#include <boost/geometry/extensions/algebra/algorithms/transform.hpp>
 
 #endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGEBRA_HPP

Added: trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -0,0 +1,146 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+
+// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_ROTATION_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_ROTATION_HPP
+
+#include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
+
+namespace boost { namespace geometry
+{
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch {
+
+template <typename V1, typename V2, typename Rotation,
+ typename Tag = typename tag<V1>::type,
+ typename RTag = typename tag<Rotation>::type
+>
+struct rotation
+{
+ BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THOSE_TAGS, (Tag, Rotation));
+};
+
+template <typename V1, typename V2, typename Rotation>
+struct rotation<V1, V2, Rotation, vector_tag, rotation_quaternion_tag>
+{
+ static const bool cs_check =
+ ::boost::is_same<typename traits::coordinate_system<V1>::type, cs::cartesian>::value &&
+ ::boost::is_same<typename traits::coordinate_system<V2>::type, cs::cartesian>::value;
+
+ BOOST_MPL_ASSERT_MSG(cs_check, NOT_IMPLEMENTED_FOR_THOSE_SYSTEMS, (V1, V2));
+
+ typedef typename select_most_precise<
+ typename traits::coordinate_type<V1>::type,
+ typename traits::coordinate_type<V2>::type
+ >::type cv_type;
+
+ typedef typename select_most_precise<
+ cv_type,
+ typename traits::coordinate_type<Rotation>::type
+ >::type cr_type;
+
+ typedef model::vector<cv_type, 3> vector_type;
+
+ inline static void apply(V1 const& v1, V2 const& v2, Rotation & r)
+ {
+ // TODO - should store coordinates in more precise variables before the normalization?
+
+ // half angle
+ cv_type d = dot(v1, v2);
+ cv_type w = ::sqrt(dot(v1, v1) * dot(v2, v2)) + d;
+
+ // rotation angle 0 or pi
+ if ( -std::numeric_limits<cv_type>::epsilon() <= w && w <= std::numeric_limits<cv_type>::epsilon() )
+ {
+ // rotation angle == 0
+ if ( 0 <= d )
+ {
+ set<0>(r, 1); set<0>(r, 0); set<0>(r, 0); set<0>(r, 0);
+ }
+ // rotation angle == pi
+ else
+ {
+ set<0>(r, 0);
+ // find arbitrary rotation axis perpendicular to v1
+ assign_cross(vector_type(1, 0, 0), v1, r);
+ if ( length_sqr(r) < std::numeric_limits<cr_type>::epsilon() )
+ assign_cross(vector_type(0, 1, 0), v1, r);
+
+ // normalize axis
+ cr_type lsqr = length_sqr(r);
+ if ( std::numeric_limits<cr_type>::epsilon() < lsqr )
+ scale(r, 1.0f / ::sqrt(lsqr));
+ }
+ }
+ else
+ {
+ set<0>(r, w);
+ // rotation axis
+ assign_cross(v1, v2, r);
+
+ // normalize
+ cr_type lsqr = length_sqr(r);
+ if ( std::numeric_limits<cr_type>::epsilon() < lsqr )
+ scale(r, 1.0f / ::sqrt(lsqr));
+ }
+ }
+
+ // TODO - should return more precise type?
+ template <typename V1, typename V2>
+ inline static cv_type dot(V1 const& v1, V2 const& v2)
+ {
+ return get<0>(v1)*get<0>(v2) + get<1>(v1)*get<1>(v2) + get<2>(v1)*get<2>(v2);
+ }
+
+ // TODO - should return more precise type?
+ inline static cr_type length_sqr(Rotation const& r)
+ {
+ return get<0>(r)*get<0>(r) + get<1>(r)*get<1>(r) + get<2>(r)*get<2>(r) + get<3>(r)*get<3>(r);
+ }
+
+ inline static void assign_cross(V1 const& v1, V2 const& v2, Rotation & r)
+ {
+ set<1>(r, get<1>(v1)*get<2>(v2) - get<2>(v1)*get<1>(v2));
+ set<2>(r, get<2>(v1)*get<0>(v2) - get<0>(v1)*get<2>(v2));
+ set<3>(r, get<0>(v1)*get<1>(v2) - get<1>(v1)*get<0>(v2));
+ }
+
+ inline static void scale(Rotation & r, cr_type const& v)
+ {
+ set<0>(r, get<0>(r) * v);
+ set<1>(r, get<1>(r) * v);
+ set<2>(r, get<2>(r) * v);
+ set<3>(r, get<3>(r) * v);
+ }
+};
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+template <typename V1, typename V2, typename Rotation>
+inline void rotation(V1 const& v1, V2 const& v2, Rotation & r)
+{
+ concept::check_concepts_and_equal_dimensions<V1 const, V2 const>();
+ // TODO - replace the following by check_equal_dimensions
+ concept::check_concepts_and_equal_dimensions<V1 const, Rotation>();
+
+ dispatch::rotation<V1, V2, Rotation>::apply(v1, v2, r);
+}
+
+template <typename Rotation, typename V1, typename V2>
+inline Rotation return_rotation(V1 const& v1, V2 const& v2)
+{
+ Rotation r;
+ translation(v1, v2, r);
+ return r;
+}
+
+}} // namespace boost::geometry
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_ROTATION_HPP

Added: trunk/boost/geometry/extensions/algebra/algorithms/transform.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/algorithms/transform.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -0,0 +1,174 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+
+// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_TRANSFORM_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_TRANSFORM_HPP
+
+#include <boost/geometry/extensions/algebra/geometries/concepts/vector_concept.hpp>
+#include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
+#include <boost/geometry/arithmetic/arithmetic.hpp>
+
+namespace boost { namespace geometry {
+
+namespace detail { namespace transform_geometrically {
+
+template <typename Box, typename Vector, std::size_t Dimension>
+struct box_vector_cartesian
+{
+ BOOST_MPL_ASSERT_MSG((0 < Dimension), INVALID_DIMENSION, (Box));
+
+ static inline void apply(Box & box, Vector const& vector)
+ {
+ box_vector_cartesian<Box, Vector, Dimension-1>::apply(box, vector);
+ set<min_corner, Dimension-1>(box, get<min_corner, Dimension-1>(box) + get<Dimension-1>(vector));
+ set<max_corner, Dimension-1>(box, get<max_corner, Dimension-1>(box) + get<Dimension-1>(vector));
+ }
+};
+
+template <typename Box, typename Vector>
+struct box_vector_cartesian<Box, Vector, 1>
+{
+ static inline void apply(Box & box, Vector const& vector)
+ {
+ set<min_corner, 0>(box, get<min_corner, 0>(box) + get<0>(vector));
+ set<max_corner, 0>(box, get<max_corner, 0>(box) + get<0>(vector));
+ }
+};
+
+}} // namespace detail::transform
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch {
+
+template <typename Geometry, typename Transform,
+ typename GTag = typename tag<Geometry>::type,
+ typename TTag = typename tag<Transform>::type>
+struct transform_geometrically
+{
+ BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THOSE_TAGS, (GTag, TTag));
+};
+
+// Point translation by Vector
+template <typename Point, typename Vector>
+struct transform_geometrically<Point, Vector, point_tag, vector_tag>
+{
+ BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
+ BOOST_CONCEPT_ASSERT( (concept::Vector<Vector>) );
+
+ static inline void apply(Point & point, Vector const& vector)
+ {
+ typedef boost::mpl::bool_<
+ boost::is_same<
+ typename traits::coordinate_system<Point>::type,
+ cs::cartesian
+ >::value
+ > is_cartesian;
+ apply(point, vector, is_cartesian());
+ }
+
+ static inline void apply(Point & point, Vector const& vector, boost::mpl::bool_<true> /*is_cartesian*/)
+ {
+ for_each_coordinate(point, detail::point_operation<Vector, std::plus>(vector));
+ }
+
+ static inline void apply(Point & point, Vector const& vector, boost::mpl::bool_<false> /*is_cartesian*/)
+ {
+ typedef typename traits::coordinate_system<Point>::type cs;
+ BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_CS, (cs));
+ }
+};
+
+// Box translation by Vector
+template <typename Box, typename Vector>
+struct transform_geometrically<Box, Vector, box_tag, vector_tag>
+{
+ typedef typename traits::point_type<Box>::type point_type;
+
+ BOOST_CONCEPT_ASSERT( (concept::Point<point_type>) );
+ BOOST_CONCEPT_ASSERT( (concept::Vector<Vector>) );
+
+ static inline void apply(Box & box, Vector const& vector)
+ {
+ typedef boost::mpl::bool_<
+ boost::is_same<
+ typename traits::coordinate_system<point_type>::type,
+ cs::cartesian
+ >::value
+ > is_cartesian;
+ apply(box, vector, is_cartesian());
+ }
+
+ static inline void apply(Box & box, Vector const& vector, boost::mpl::bool_<true> /*is_cartesian*/)
+ {
+ geometry::detail::transform_geometrically::box_vector_cartesian<
+ Box, Vector, traits::dimension<point_type>::value
+ >::apply(box, vector);
+ }
+
+ static inline void apply(Box & box, Vector const& vector, boost::mpl::bool_<false> /*is_cartesian*/)
+ {
+ typedef typename traits::coordinate_system<point_type>::type cs;
+ BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_CS, (cs));
+ }
+};
+
+// Vector rotation by Quaternion
+template <typename Vector, typename RotationQuaternion>
+struct transform_geometrically<Vector, RotationQuaternion, vector_tag, rotation_quaternion_tag>
+{
+ static inline void apply(Vector & v, RotationQuaternion const& r)
+ {
+ concept::check_concepts_and_equal_dimensions<Vector, RotationQuaternion const>();
+
+ // TODO - choose more precise type?
+
+ typedef typename select_most_precise<
+ typename traits::coordinate_type<Vector>::type,
+ typename traits::coordinate_type<RotationQuaternion>::type
+ >::type T;
+
+ T a = /*get<0>(r) * 0 */- get<1>(r) * get<0>(v) - get<2>(r) * get<1>(v) - get<3>(r) * get<2>(v);
+ T b = get<0>(r) * get<0>(v)/* + get<1>(r) * 0*/ + get<2>(r) * get<2>(v) - get<3>(r) * get<1>(v);
+ T c = get<0>(r) * get<1>(v) - get<1>(r) * get<2>(v)/* + get<2>(r) * 0*/ + get<3>(r) * get<0>(v);
+ T d = get<0>(r) * get<2>(v) + get<1>(r) * get<1>(v) - get<2>(r) * get<0>(v)/* + get<3>(r) * 0*/;
+
+ set<0>(v, - a * get<1>(r) + b * get<0>(r) - c * get<3>(r) + d * get<2>(r));
+ set<1>(v, - a * get<2>(r) + b * get<3>(r) + c * get<0>(r) - d * get<1>(r));
+ set<2>(v, - a * get<3>(r) - b * get<2>(r) + c * get<1>(r) + d * get<0>(r));
+ }
+};
+
+// TODO - other geometries and transformations
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+template <typename Geometry, typename Transformation>
+inline void transform_geometrically(Geometry & g, Transformation const& t)
+{
+ dispatch::transform_geometrically<Geometry, Transformation>::apply(g, t);
+}
+
+template <typename GeometrySrc, typename Transformation, typename GeometryDst>
+inline void transformed_geometrically(GeometrySrc const& gsrc, Transformation const& t, GeometryDst & gdst)
+{
+ geometry::convert(gsrc, gdst);
+ geometry::transform_geometrically(gdst, t);
+}
+
+template <typename GeometryDst, typename GeometrySrc, typename Transformation>
+inline GeometryDst return_transformed_geometrically(GeometrySrc const& gsrc, Transformation const& t)
+{
+ GeometryDst res;
+ transformed_geometrically(gsrc, t, res);
+ return res;
+}
+
+}} // namespace boost::geometry
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_TRANSFORM_HPP

Modified: trunk/boost/geometry/extensions/algebra/core/access.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/access.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/access.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -55,6 +55,31 @@
     }
 };
 
+template <typename Q, typename CoordinateType, std::size_t Dimension>
+struct access<rotation_quaternion_tag, Q, CoordinateType, Dimension, boost::false_type>
+{
+ static inline CoordinateType get(Q const& v)
+ {
+ return traits::access<Q, Dimension>::get(v);
+ }
+ static inline void set(Q& v, CoordinateType const& value)
+ {
+ traits::access<Q, Dimension>::set(v, value);
+ }
+};
+
+template <typename Q, typename CoordinateType, std::size_t Dimension>
+struct access<rotation_quaternion_tag, Q, CoordinateType, Dimension, boost::true_type>
+{
+ static inline CoordinateType get(Q const* v)
+ {
+ return traits::access<typename boost::remove_pointer<Q>::type, Dimension>::get(*v);
+ }
+ static inline void set(Q* v, CoordinateType const& value)
+ {
+ traits::access<typename boost::remove_pointer<Q>::type, Dimension>::set(*v, value);
+ }
+};
 
 } // namespace core_dispatch
 #endif // DOXYGEN_NO_DISPATCH

Modified: trunk/boost/geometry/extensions/algebra/core/coordinate_dimension.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/coordinate_dimension.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/coordinate_dimension.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -29,6 +29,11 @@
     : traits::dimension<typename geometry::util::bare_type<V>::type>
 {};
 
+template <typename G>
+struct dimension<rotation_quaternion_tag, G>
+ : traits::dimension<typename geometry::util::bare_type<G>::type>
+{};
+
 } // namespace core_dispatch
 #endif // DOXYGEN_NO_DISPATCH
 

Modified: trunk/boost/geometry/extensions/algebra/core/coordinate_system.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/coordinate_system.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/coordinate_system.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -27,10 +27,17 @@
 template <typename Vector>
 struct coordinate_system<vector_tag, Vector>
 {
- typedef typename traits::coordinate_system
- <
- typename geometry::util::bare_type<Vector>::type
- >::type type;
+ typedef typename traits::coordinate_system<
+ typename geometry::util::bare_type<Vector>::type
+ >::type type;
+};
+
+template <typename G>
+struct coordinate_system<rotation_quaternion_tag, G>
+{
+ typedef typename traits::coordinate_system<
+ typename geometry::util::bare_type<G>::type
+ >::type type;
 };
 
 } // namespace core_dispatch

Modified: trunk/boost/geometry/extensions/algebra/core/coordinate_type.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/coordinate_type.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/coordinate_type.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -27,10 +27,17 @@
 template <typename Vector>
 struct coordinate_type<vector_tag, Vector>
 {
- typedef typename traits::coordinate_type
- <
- typename geometry::util::bare_type<Vector>::type
- >::type type;
+ typedef typename traits::coordinate_type<
+ typename geometry::util::bare_type<Vector>::type
+ >::type type;
+};
+
+template <typename G>
+struct coordinate_type<rotation_quaternion_tag, G>
+{
+ typedef typename traits::coordinate_type<
+ typename geometry::util::bare_type<G>::type
+ >::type type;
 };
 
 } // namespace core_dispatch

Modified: trunk/boost/geometry/extensions/algebra/core/tags.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/tags.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/tags.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -21,7 +21,7 @@
 
 
 struct vector_tag {};
-
+struct rotation_quaternion_tag {};
 
 
 }} // namespace boost::geometry

Modified: trunk/boost/geometry/extensions/algebra/core/topological_dimension.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/core/topological_dimension.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/core/topological_dimension.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -30,9 +30,11 @@
 {
 
 
-template <>
-struct top_dim<vector_tag> : boost::mpl::int_<0> {};
-
+//template <>
+//struct top_dim<vector_tag> : boost::mpl::int_<0> {};
+//
+//template <>
+//struct top_dim<rotation_quaternion_tag> : boost::mpl::int_<0> {};
 
 } // namespace core_dispatch
 #endif

Modified: trunk/boost/geometry/extensions/algebra/geometries/concepts/check.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/geometries/concepts/check.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/geometries/concepts/check.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -38,6 +38,16 @@
     : detail::concept_check::check<concept::Vector<Geometry> >
 {};
 
+template <typename Geometry>
+struct check<Geometry, rotation_quaternion_tag, true>
+ : detail::concept_check::check<concept::ConstRotationQuaternion<Geometry> >
+{};
+
+template <typename Geometry>
+struct check<Geometry, rotation_quaternion_tag, false>
+ : detail::concept_check::check<concept::RotationQuaternion<Geometry> >
+{};
+
 } // namespace dispatch
 #endif
 

Added: trunk/boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -0,0 +1,111 @@
+// 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) 2013 Adam Wulkiewicz, Lodz, Poland.
+
+// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
+// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_CONCEPTS_ROTATION_QUATERNION_CONCEPT_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_CONCEPTS_ROTATION_QUATERNION_CONCEPT_HPP
+
+#include <boost/concept_check.hpp>
+
+#include <boost/geometry/core/coordinate_dimension.hpp>
+#include <boost/geometry/core/access.hpp>
+
+namespace boost { namespace geometry { namespace concept {
+
+template <typename Geometry>
+class RotationQuaternion
+{
+#ifndef DOXYGEN_NO_CONCEPT_MEMBERS
+
+ typedef typename coordinate_type<Geometry>::type ctype;
+ typedef typename coordinate_system<Geometry>::type csystem;
+
+ template <typename G, std::size_t I, std::size_t N>
+ struct dimension_checker
+ {
+ static void apply()
+ {
+ G* g = 0;
+ geometry::set<I>(*g, geometry::get<I>(*g));
+ dimension_checker<G, I+1, N>::apply();
+ }
+ };
+
+
+ template <typename G, std::size_t N>
+ struct dimension_checker<G, N, N>
+ {
+ static void apply() {}
+ };
+
+public:
+
+ /// BCCL macro to apply the Vector concept
+ BOOST_CONCEPT_USAGE(RotationQuaternion)
+ {
+ static const bool dim_check = dimension<Geometry>::value == 3;
+ BOOST_MPL_ASSERT_MSG(dim_check, INVALID_DIMENSION, (RotationQuaternion));
+ static const bool cs_check = ::boost::is_same<csystem, cs::cartesian>::value;
+ BOOST_MPL_ASSERT_MSG(cs_check, NOT_IMPLEMENTED_FOR_THIS_CS, (csystem));
+
+ dimension_checker<Geometry, 0, 4>::apply();
+ }
+#endif
+};
+
+
+template <typename Geometry>
+class ConstRotationQuaternion
+{
+#ifndef DOXYGEN_NO_CONCEPT_MEMBERS
+
+ typedef typename coordinate_type<Geometry>::type ctype;
+ typedef typename coordinate_system<Geometry>::type csystem;
+
+ template <typename G, std::size_t I, std::size_t N>
+ struct dimension_checker
+ {
+ static void apply()
+ {
+ const G* g = 0;
+ ctype coord(geometry::get<I>(*g));
+ boost::ignore_unused_variable_warning(coord);
+ dimension_checker<G, I+1, N>::apply();
+ }
+ };
+
+
+ template <typename G, std::size_t N>
+ struct dimension_checker<G, N, N>
+ {
+ static void apply() {}
+ };
+
+public:
+
+ /// BCCL macro to apply the ConstVector concept
+ BOOST_CONCEPT_USAGE(ConstRotationQuaternion)
+ {
+ static const bool dim_check = dimension<Geometry>::value == 3;
+ BOOST_MPL_ASSERT_MSG(dim_check, INVALID_DIMENSION, (ConstRotationQuaternion));
+ static const bool cs_check = ::boost::is_same<csystem, cs::cartesian>::value;
+ BOOST_MPL_ASSERT_MSG(cs_check, NOT_IMPLEMENTED_FOR_THIS_CS, (csystem));
+
+ dimension_checker<Geometry, 0, 4>::apply();
+ }
+#endif
+};
+
+}}} // namespace boost::geometry::concept
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_CONCEPTS_ROTATION_QUATERNION_CONCEPT_HPP

Added: trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp 2013-05-29 19:18:08 EDT (Wed, 29 May 2013)
@@ -0,0 +1,130 @@
+// 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) 2013 Adam Wulkiewicz, Lodz, Poland.
+
+// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
+// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_ROTATION_QUATERNION_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_ROTATION_QUATERNION_HPP
+
+#include <cstddef>
+
+#include <boost/geometry/extensions/algebra/core/tags.hpp>
+#include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
+
+namespace boost { namespace geometry
+{
+
+namespace model
+{
+
+template <typename T>
+class rotation_quaternion
+{
+ BOOST_CONCEPT_ASSERT( (concept::RotationQuaternion<rotation_quaternion>) );
+
+public:
+
+ /// @brief Default constructor, no initialization
+ inline rotation_quaternion()
+ {}
+
+ /// @brief Constructor to set components
+ inline rotation_quaternion(T const& w, T const& x, T const& y, T const& z)
+ {
+ m_values[0] = w;
+ m_values[1] = w;
+ m_values[2] = w;
+ m_values[3] = w;
+ }
+
+ /// @brief Get a coordinate
+ /// @tparam K coordinate to get
+ /// @return the coordinate
+ template <std::size_t K>
+ inline T const& get() const
+ {
+ BOOST_STATIC_ASSERT(K < 4);
+ return m_values[K];
+ }
+
+ /// @brief Set a coordinate
+ /// @tparam K coordinate to set
+ /// @param value value to set
+ template <std::size_t K>
+ inline void set(T const& value)
+ {
+ BOOST_STATIC_ASSERT(K < 4);
+ m_values[K] = value;
+ }
+
+private:
+
+ T m_values[4];
+};
+
+
+} // namespace model
+
+#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
+namespace traits
+{
+
+template <typename CoordinateType>
+struct tag<model::rotation_quaternion<CoordinateType> >
+{
+ typedef rotation_quaternion_tag type;
+};
+
+template <typename CoordinateType>
+struct coordinate_type<model::rotation_quaternion<CoordinateType> >
+{
+ typedef CoordinateType type;
+};
+
+template <typename CoordinateType>
+struct coordinate_system<model::rotation_quaternion<CoordinateType> >
+{
+ typedef cs::cartesian type;
+};
+
+template <typename CoordinateType>
+struct dimension<model::rotation_quaternion<CoordinateType> >
+ : boost::mpl::int_<3>
+{};
+
+template
+<
+ typename CoordinateType,
+ std::size_t Dimension
+>
+struct access<model::rotation_quaternion<CoordinateType>, Dimension>
+{
+ static inline CoordinateType get(
+ model::rotation_quaternion<CoordinateType> const& v)
+ {
+ return v.template get<Dimension>();
+ }
+
+ static inline void set(
+ model::rotation_quaternion<CoordinateType> & v,
+ CoordinateType const& value)
+ {
+ v.template set<Dimension>(value);
+ }
+};
+
+} // namespace traits
+#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
+
+}} // namespace boost::geometry
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_GEOMETRIES_ROTATION_QUATERNION_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk