diff --git a/include/boost/geometry/extensions/algebra/algebra.hpp b/include/boost/geometry/extensions/algebra/algebra.hpp index 593cd8aa4..e1318d614 100644 --- a/include/boost/geometry/extensions/algebra/algebra.hpp +++ b/include/boost/geometry/extensions/algebra/algebra.hpp @@ -33,8 +33,14 @@ #include #include +// experimental +#include +#include + #include #include + +// should be removed, transform() should be used instead #include #endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGEBRA_HPP diff --git a/include/boost/geometry/extensions/algebra/algorithms/assign.hpp b/include/boost/geometry/extensions/algebra/algorithms/assign.hpp index d5601c618..d25785de7 100644 --- a/include/boost/geometry/extensions/algebra/algorithms/assign.hpp +++ b/include/boost/geometry/extensions/algebra/algorithms/assign.hpp @@ -69,6 +69,9 @@ struct assign_identity } // 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 @@ struct assign } }; - } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH diff --git a/include/boost/geometry/extensions/algebra/algorithms/clear.hpp b/include/boost/geometry/extensions/algebra/algorithms/clear.hpp new file mode 100644 index 000000000..62618efcd --- /dev/null +++ b/include/boost/geometry/extensions/algebra/algorithms/clear.hpp @@ -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 + +#include + +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 +struct clear +{ + static inline void apply(Vector & v) + { + geometry::assign_zero(v); + } +}; + +template +struct clear +{ + static inline void apply(R & r) + { + geometry::assign_identity(r); + } +}; + +template +struct clear +{ + 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 diff --git a/include/boost/geometry/extensions/algebra/algorithms/detail.hpp b/include/boost/geometry/extensions/algebra/algorithms/detail.hpp index 6a875aff6..cb08efa89 100644 --- a/include/boost/geometry/extensions/algebra/algorithms/detail.hpp +++ b/include/boost/geometry/extensions/algebra/algorithms/detail.hpp @@ -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 @@ inline static void mul(S & s, T const& v) return mul_impl::apply(s, v); } +// Negation + +template +struct neg_impl +{ + BOOST_STATIC_ASSERT(0 < N); + + static inline void apply(V & v) + { + set(v, -get(v)); + neg_impl::apply(v); + } +}; + +template +struct neg_impl +{ + static inline void apply(V &) {} +}; + +template +inline static void neg(V & v) +{ + return neg_impl::apply(v); +} + // Normalization of N components starting from Ith template @@ -151,6 +180,8 @@ struct matrix_mul_impl static inline void apply(M const&, V const&, VD &) {} }; +// Matrix rotation - M*V + template inline static void matrix_rotate(M const& m, V const& v, VD & vd) { @@ -159,6 +190,8 @@ inline static void matrix_rotate(M const& m, V const& v, VD & vd) matrix_mul_impl::apply(m, v, vd); } +// Quaternion rotation - Q*V*Q' - * is Hamilton product + template inline static void quaternion_rotate(V & v, Q const& r) { @@ -180,6 +213,8 @@ inline static void quaternion_rotate(V & v, Q const& r) set<2>(v, - a * get<3>(r) - b * get<2>(r) + c * get<1>(r) + d * get<0>(r)); } +// Assign value + template struct assign_value { @@ -206,6 +241,8 @@ struct indexed_assign_value_per_index } }; +// Assign value using indexed access + template struct indexed_assign_value_per_index { @@ -238,6 +275,8 @@ struct identity_matrix_per_index } }; +// Identity matrix + template struct identity_matrix_per_index { @@ -270,6 +309,43 @@ struct identity_matrix static inline void apply(G &) {} }; +// Matrix transpose + +template +struct matrix_transpose_per_index +{ + static inline void apply(G & g) + { + // swap coordinates + typename coordinate_type::type tmp = get(g); + set(g, get(g)); + set(g, tmp); + matrix_transpose_per_index::apply(g); + } +}; + +template +struct matrix_transpose_per_index +{ + static inline void apply(G &) {} +}; + +template +struct matrix_transpose +{ + static inline void apply(G & g) + { + matrix_transpose_per_index::apply(g); + matrix_transpose::apply(g); + } +}; + +template +struct matrix_transpose +{ + static inline void apply(G &) {} +}; + }} // namespace detail::algebra #endif // DOXYGEN_NO_DETAIL diff --git a/include/boost/geometry/extensions/algebra/algorithms/reverse.hpp b/include/boost/geometry/extensions/algebra/algorithms/reverse.hpp new file mode 100644 index 000000000..6471c2ef0 --- /dev/null +++ b/include/boost/geometry/extensions/algebra/algorithms/reverse.hpp @@ -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 + +#include + +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 +struct reverse +{ + static inline void apply(Vector & v) + { + detail::algebra::neg<0, dimension::value>(v); + } +}; + +template +struct reverse +{ + static inline void apply(R & r) + { + detail::algebra::neg<1, 4>(r); + } +}; + +template +struct reverse +{ + static inline void apply(R & r) + { + detail::algebra::matrix_transpose< + R, 0, 0, dimension::value + >::apply(r); + } +}; + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_EXTENSIONS_ALGEBRA_ALGORITHMS_CLEAR_HPP diff --git a/include/boost/geometry/extensions/algebra/algorithms/rotation.hpp b/include/boost/geometry/extensions/algebra/algorithms/rotation.hpp index 3703f79c0..7e08cd25e 100644 --- a/include/boost/geometry/extensions/algebra/algorithms/rotation.hpp +++ b/include/boost/geometry/extensions/algebra/algorithms/rotation.hpp @@ -13,6 +13,9 @@ #include +// TODO - for multiplication of coordinates +// if coordinate_type is_integral - use double as the result type + namespace boost { namespace geometry { namespace detail { namespace rotation { diff --git a/include/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp b/include/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp index d4ff65590..ebc99ffb6 100644 --- a/include/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp +++ b/include/boost/geometry/extensions/algebra/geometries/rotation_quaternion.hpp @@ -20,6 +20,10 @@ #include #include +// 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 {