Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84615 - in trunk/boost/geometry/extensions/algebra: . algorithms geometries
From: adam.wulkiewicz_at_[hidden]
Date: 2013-06-02 19:53:13


Author: awulkiew
Date: 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
New Revision: 84615
URL: http://svn.boost.org/trac/boost/changeset/84615

Log:
geometry extensions: added experimental clear() and reverse() for translations/vectors (assigning zeros and negating) and rotations (assigning identity and calculating invese/conjugate)
Added:
   trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp (contents, props changed)
   trunk/boost/geometry/extensions/algebra/algorithms/reverse.hpp (contents, props changed)
Text files modified:
   trunk/boost/geometry/extensions/algebra/algebra.hpp | 6 +++
   trunk/boost/geometry/extensions/algebra/algorithms/assign.hpp | 4 +
   trunk/boost/geometry/extensions/algebra/algorithms/detail.hpp | 76 ++++++++++++++++++++++++++++++++++++++++
   trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp | 3 +
   trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp | 4 ++
   5 files changed, 92 insertions(+), 1 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-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -33,8 +33,14 @@
 #include <boost/geometry/extensions/algebra/algorithms/assign.hpp>
 #include <boost/geometry/extensions/algebra/algorithms/convert.hpp>
 
+// experimental
+#include <boost/geometry/extensions/algebra/algorithms/clear.hpp>
+#include <boost/geometry/extensions/algebra/algorithms/reverse.hpp>
+
 #include <boost/geometry/extensions/algebra/algorithms/translation.hpp>
 #include <boost/geometry/extensions/algebra/algorithms/rotation.hpp>
+
+// should be removed, transform() should be used instead
 #include <boost/geometry/extensions/algebra/algorithms/transform_geometrically.hpp>
 
 #endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGEBRA_HPP

Modified: trunk/boost/geometry/extensions/algebra/algorithms/assign.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algorithms/assign.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/algorithms/assign.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -69,6 +69,9 @@
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
+// TODO
+// Use assign_zero for initialization of 0-angle rotation instead of assign_identity?
+
 /*!
 \brief assign identity to Transformation
 \ingroup assign
@@ -117,7 +120,6 @@
     }
 };
 
-
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 

Added: trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -0,0 +1,64 @@
+// 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_ALGORITHMS_CLEAR_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_CLEAR_HPP
+
+#include <boost/geometry/algorithms/clear.hpp>
+
+#include <boost/geometry/extensions/algebra/algorithms/assign.hpp>
+
+namespace boost { namespace geometry
+{
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch
+{
+
+// This is experimental implementation of clear() which assigns zeros to vectors
+// and identities to rotations. It doesn't work for them as for Geometries.
+
+template <typename Vector>
+struct clear<Vector, vector_tag>
+{
+ static inline void apply(Vector & v)
+ {
+ geometry::assign_zero(v);
+ }
+};
+
+template <typename R>
+struct clear<R, rotation_quaternion_tag>
+{
+ static inline void apply(R & r)
+ {
+ geometry::assign_identity(r);
+ }
+};
+
+template <typename R>
+struct clear<R, rotation_matrix_tag>
+{
+ static inline void apply(R & r)
+ {
+ geometry::assign_identity(r);
+ }
+};
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+}} // namespace boost::geometry
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_CLEAR_HPP

Modified: trunk/boost/geometry/extensions/algebra/algorithms/detail.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algorithms/detail.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/algorithms/detail.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -9,6 +9,9 @@
 #ifndef BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_DETAIL_HPP
 #define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_DETAIL_HPP
 
+// TODO - for multiplication of coordinates
+// if coordinate_type is_integral - use double as the result type
+
 namespace boost { namespace geometry
 {
 
@@ -93,6 +96,32 @@
     return mul_impl<S, T, IS, 0, N>::apply(s, v);
 }
 
+// Negation
+
+template <typename V, std::size_t I, std::size_t N>
+struct neg_impl
+{
+ BOOST_STATIC_ASSERT(0 < N);
+
+ static inline void apply(V & v)
+ {
+ set<I>(v, -get<I>(v));
+ neg_impl<V, I+1, N>::apply(v);
+ }
+};
+
+template <typename V, std::size_t N>
+struct neg_impl<V, N, N>
+{
+ static inline void apply(V &) {}
+};
+
+template <std::size_t I, std::size_t N, typename V>
+inline static void neg(V & v)
+{
+ return neg_impl<V, I, N>::apply(v);
+}
+
 // Normalization of N components starting from Ith
 
 template <std::size_t I, std::size_t N, typename S>
@@ -151,6 +180,8 @@
     static inline void apply(M const&, V const&, VD &) {}
 };
 
+// Matrix rotation - M*V
+
 template <typename M, typename V, typename VD>
 inline static void matrix_rotate(M const& m, V const& v, VD & vd)
 {
@@ -159,6 +190,8 @@
     matrix_mul_impl<M, V, VD, 0, dimension>::apply(m, v, vd);
 }
 
+// Quaternion rotation - Q*V*Q' - * is Hamilton product
+
 template <typename V, typename Q>
 inline static void quaternion_rotate(V & v, Q const& r)
 {
@@ -180,6 +213,8 @@
     set<2>(v, - a * get<3>(r) - b * get<2>(r) + c * get<1>(r) + d * get<0>(r));
 }
 
+// Assign value
+
 template <typename G, typename V, std::size_t B, std::size_t E>
 struct assign_value
 {
@@ -206,6 +241,8 @@
     }
 };
 
+// Assign value using indexed access
+
 template <typename G, typename V, std::size_t BI, std::size_t EI, std::size_t ED>
 struct indexed_assign_value_per_index<G, V, BI, ED, EI, ED>
 {
@@ -238,6 +275,8 @@
     }
 };
 
+// Identity matrix
+
 template <typename G, std::size_t BI, std::size_t EI, std::size_t ED>
 struct identity_matrix_per_index<G, BI, BI, EI, ED>
 {
@@ -270,6 +309,43 @@
     static inline void apply(G &) {}
 };
 
+// Matrix transpose
+
+template <typename G, std::size_t I, std::size_t D, std::size_t N>
+struct matrix_transpose_per_index
+{
+ static inline void apply(G & g)
+ {
+ // swap coordinates
+ typename coordinate_type<G>::type tmp = get<I, D>(g);
+ set<I, D>(g, get<D, I>(g));
+ set<D, I>(g, tmp);
+ matrix_transpose_per_index<G, I, D+1, N>::apply(g);
+ }
+};
+
+template <typename G, std::size_t I, std::size_t N>
+struct matrix_transpose_per_index<G, I, N, N>
+{
+ static inline void apply(G &) {}
+};
+
+template <typename G, std::size_t I, std::size_t D, std::size_t N>
+struct matrix_transpose
+{
+ static inline void apply(G & g)
+ {
+ matrix_transpose_per_index<G, I, I+1, N>::apply(g);
+ matrix_transpose<G, I+1, D, N>::apply(g);
+ }
+};
+
+template <typename G, std::size_t D, std::size_t N>
+struct matrix_transpose<G, N, D, N>
+{
+ static inline void apply(G &) {}
+};
+
 }} // namespace detail::algebra
 #endif // DOXYGEN_NO_DETAIL
 

Added: trunk/boost/geometry/extensions/algebra/algorithms/reverse.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/geometry/extensions/algebra/algorithms/reverse.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -0,0 +1,66 @@
+// 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_ALGORITHMS_REVERSE_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_REVERSE_HPP
+
+#include <boost/geometry/algorithms/reverse.hpp>
+
+#include <boost/geometry/extensions/algebra/algorithms/detail.hpp>
+
+namespace boost { namespace geometry
+{
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch
+{
+
+// This is experimental implementation of reverse() which negates vectors
+// and inverses rotations. It doesn't work for them as for Geometries.
+
+template <typename Vector>
+struct reverse<Vector, vector_tag>
+{
+ static inline void apply(Vector & v)
+ {
+ detail::algebra::neg<0, dimension<Vector>::value>(v);
+ }
+};
+
+template <typename R>
+struct reverse<R, rotation_quaternion_tag>
+{
+ static inline void apply(R & r)
+ {
+ detail::algebra::neg<1, 4>(r);
+ }
+};
+
+template <typename R>
+struct reverse<R, rotation_matrix_tag>
+{
+ static inline void apply(R & r)
+ {
+ detail::algebra::matrix_transpose<
+ R, 0, 0, dimension<R>::value
+ >::apply(r);
+ }
+};
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+}} // namespace boost::geometry
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_CLEAR_HPP

Modified: trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -13,6 +13,9 @@
 
 #include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
 
+// TODO - for multiplication of coordinates
+// if coordinate_type is_integral - use double as the result type
+
 namespace boost { namespace geometry {
 
 namespace detail { namespace rotation {

Modified: trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp (original)
+++ trunk/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp 2013-06-02 19:53:12 EDT (Sun, 02 Jun 2013)
@@ -20,6 +20,10 @@
 #include <boost/geometry/extensions/algebra/core/tags.hpp>
 #include <boost/geometry/extensions/algebra/geometries/concepts/rotation_quaternion_concept.hpp>
 
+// WARNING!
+// It is probable that the sequence of coordinate will change in the future
+// at the beginning there would be xyz, w would become the last coordinate
+
 namespace boost { namespace geometry
 {
 


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