Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84612 - in trunk/boost/geometry/extensions/algebra: . algorithms
From: adam.wulkiewicz_at_[hidden]
Date: 2013-06-02 15:56:48


Author: awulkiew
Date: 2013-06-02 15:56:47 EDT (Sun, 02 Jun 2013)
New Revision: 84612
URL: http://svn.boost.org/trac/boost/changeset/84612

Log:
geometry extensions: implemented assign_zero() for algebra.
Removed:
   trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp
   trunk/boost/geometry/extensions/algebra/algorithms/num_points.hpp
Text files modified:
   trunk/boost/geometry/extensions/algebra/algebra.hpp | 2 -
   trunk/boost/geometry/extensions/algebra/algorithms/assign.hpp | 38 +++++++++++++++++++++++++--
   trunk/boost/geometry/extensions/algebra/algorithms/detail.hpp | 50 +++++++++++++++++++++++++++++++++++++
   trunk/boost/geometry/extensions/algebra/algorithms/rotation.hpp | 54 ++++++++++++++++++---------------------
   4 files changed, 110 insertions(+), 34 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 15:56:47 EDT (Sun, 02 Jun 2013)
@@ -31,8 +31,6 @@
 #include <boost/geometry/extensions/algebra/geometries/rotation_matrix.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/rotation.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 15:56:47 EDT (Sun, 02 Jun 2013)
@@ -19,7 +19,7 @@
 
 #include <boost/geometry/extensions/algebra/core/tags.hpp>
 
-
+#include <boost/geometry/extensions/algebra/algorithms/detail.hpp>
 
 namespace boost { namespace geometry
 {
@@ -30,8 +30,40 @@
 
 template <typename Vector>
 struct assign_zero<vector_tag, Vector>
- : detail::assign::assign_zero_point<Vector>
-{};
+{
+ static inline void apply(Vector & g)
+ {
+ detail::algebra::assign_value<
+ Vector,
+ typename coordinate_type<Vector>::type,
+ 0, dimension<Vector>::type::value
+ >::apply(g, 0);
+ }
+};
+
+template <typename R>
+struct assign_zero<rotation_quaternion_tag, R>
+{
+ static inline void apply(R & g)
+ {
+ detail::algebra::assign_value<
+ R, typename coordinate_type<R>::type,
+ 0, 4
+ >::apply(g, 0);
+ }
+};
+
+template <typename R>
+struct assign_zero<rotation_matrix_tag, R>
+{
+ static inline void apply(R & g)
+ {
+ detail::algebra::indexed_assign_value<
+ R, typename coordinate_type<R>::type,
+ 0, 0, dimension<R>::type::value, dimension<R>::type::value
+ >::apply(g, 0);
+ }
+};
 
 template <typename V>
 struct assign<vector_tag, V, 2>

Deleted: trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algorithms/clear.hpp 2013-06-02 15:56:47 EDT (Sun, 02 Jun 2013)
+++ (empty file)
@@ -1,48 +0,0 @@
-// 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/core/tags.hpp>
-
-
-
-namespace boost { namespace geometry
-{
-
-
-#ifndef DOXYGEN_NO_DISPATCH
-namespace dispatch
-{
-
-
-
-template <typename Geometry>
-struct clear<vector_tag, Geometry>
- : detail::clear::no_action<Geometry>
-{};
-
-
-
-} // 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 15:56:47 EDT (Sun, 02 Jun 2013)
@@ -12,6 +12,7 @@
 namespace boost { namespace geometry
 {
 
+#ifndef DOXYGEN_NO_DETAIL
 namespace detail { namespace algebra {
 
 // Cross 3D of 3 components of Vectors/Quaternion starting from IS1 and IS2 and placing the result starting from D
@@ -179,7 +180,56 @@
     set<2>(v, - a * get<3>(r) - b * get<2>(r) + c * get<1>(r) + d * get<0>(r));
 }
 
+template <typename G, typename V, std::size_t B, std::size_t E>
+struct assign_value
+{
+ static inline void apply(G & g, V const& v)
+ {
+ set<B>(g, v);
+ assign_value<G, V, B+1, E>::apply(g, v);
+ }
+};
+
+template <typename G, typename V, std::size_t E>
+struct assign_value<G, V, E, E>
+{
+ static inline void apply(G &, V const&) {}
+};
+
+template <typename G, typename V, std::size_t BI, std::size_t BD, std::size_t EI, std::size_t ED>
+struct indexed_assign_value_per_index
+{
+ static inline void apply(G & g, V const& v)
+ {
+ set<BI, BD>(g, v);
+ indexed_assign_value_per_index<G, V, BI, BD+1, EI, ED>::apply(g, v);
+ }
+};
+
+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>
+{
+ static inline void apply(G &, V const&) {}
+};
+
+template <typename G, typename V, std::size_t BI, std::size_t BD, std::size_t EI, std::size_t ED>
+struct indexed_assign_value
+{
+ static inline void apply(G & g, V const& v)
+ {
+ indexed_assign_value_per_index<G, V, BI, BD, EI, ED>::apply(g, v);
+ indexed_assign_value<G, V, BI+1, BD, EI, ED>::apply(g, v);
+ }
+};
+
+template <typename G, typename V, std::size_t BD, std::size_t EI, std::size_t ED>
+struct indexed_assign_value<G, V, EI, BD, EI, ED>
+{
+ static inline void apply(G &, V const&) {}
+};
+
 }} // namespace detail::algebra
+#endif // DOXYGEN_NO_DETAIL
 
 }} // namespace boost::geometry
 

Deleted: trunk/boost/geometry/extensions/algebra/algorithms/num_points.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algebra/algorithms/num_points.hpp 2013-06-02 15:56:47 EDT (Sun, 02 Jun 2013)
+++ (empty file)
@@ -1,47 +0,0 @@
-// 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_NUM_POINTS_HPP
-#define BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_NUM_POINTS_HPP
-
-#include <boost/geometry/algorithms/num_points.hpp>
-
-#include <boost/geometry/extensions/algebra/core/tags.hpp>
-
-
-namespace boost { namespace geometry
-{
-
-
-
-#ifndef DOXYGEN_NO_DISPATCH
-namespace dispatch
-{
-
-
-template <typename Geometry>
-struct num_points<vector_tag, Geometry>
- : detail::num_points::other_count<0>
-{};
-
-
-
-} // namespace dispatch
-#endif
-
-
-}} // namespace boost::geometry
-
-
-#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_NUM_POINTS_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 15:56:47 EDT (Sun, 02 Jun 2013)
@@ -56,6 +56,7 @@
         cv_type c = d / l;
 
         // rotation angle == 0
+ // not needed really, because in this case function still returns zero-rotation
         if ( 1 - std::numeric_limits<cv_type>::epsilon() <= c )
         {
             set<0, 0>(r, 1); set<0, 1>(r, 0); set<0, 2>(r, 0);
@@ -130,6 +131,7 @@
         // TODO return also if l == 0;
 
         // rotation angle == 0
+ // not needed really, because in this case function still returns zero-rotation
         if ( 1 - std::numeric_limits<cv_type>::epsilon() <= c )
         {
             set<0, 0>(r, 1); set<0, 1>(r, 0);
@@ -148,8 +150,6 @@
 
             set<0, 0>(r, c); set<0, 1>(r, -s);
             set<1, 0>(r, s); set<1, 1>(r, c);
-
- int a = 10;
         }
     }
 };
@@ -196,37 +196,33 @@
 
         // TODO - should store coordinates in more precise variables before the normalization?
 
- // half angle
- cv_type d = da::dot<0, 0, 3>(v1, v2);
- cv_type l = ::sqrt(da::dot<0, 0, 3>(v1, v1) * da::dot<0, 0, 3>(v2, v2));
- cv_type w = l + 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
- da::cross<0, 0, 1>(vector_type(1, 0, 0), v1, r);
- if ( da::dot<1, 1, 3>(r, r) < std::numeric_limits<cr_type>::epsilon() )
- da::cross<0, 0, 1>(vector_type(0, 1, 0), v1, r);
-
- // normalize axis
- da::normalize<1, 3>(r);
- }
+ cv_type d = da::dot<0, 0, 3>(v1, v2); // l1 * l2 * cos
+ cv_type l = ::sqrt(da::dot<0, 0, 3>(v1, v1) * da::dot<0, 0, 3>(v2, v2)); // l1 * l2
+ cv_type w = l + d; // l1 * l2 * ( 1 + cos )
+
+ // rotation angle == 0
+ // not needed really, because in this case function still returns zero-rotation
+ if ( 2*l-std::numeric_limits<cv_type>::epsilon() <= w )
+ {
+ set<0>(r, 1); set<0>(r, 0); set<0>(r, 0); set<0>(r, 0);
+ }
+ // rotation angle == pi
+ else if ( w <= std::numeric_limits<cv_type>::epsilon() )
+ {
+ set<0>(r, 0);
+ // find arbitrary rotation axis perpendicular to v1
+ da::cross<0, 0, 1>(vector_type(1, 0, 0), v1, r);
+ if ( da::dot<1, 1, 3>(r, r) < std::numeric_limits<cr_type>::epsilon() )
+ da::cross<0, 0, 1>(vector_type(0, 1, 0), v1, r);
+
+ // normalize axis
+ da::normalize<1, 3>(r);
         }
         else
         {
- set<0>(r, w);
+ set<0>(r, w); // l1 * l2 * ( 1 + cos )
             // rotation axis
- da::cross<0, 0, 1>(v1, v2, r);
+ da::cross<0, 0, 1>(v1, v2, r); // l1 * l2 * sin * UNITA
 
             // normalize quaternion
             da::normalize<0, 4>(r);


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