From: Charles McGarvey Date: Fri, 30 Apr 2010 19:03:55 +0000 (-0600) Subject: version bump cml to version 1.0.2 X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=40755d4c6251206c18ce4784967d3a910cee096f;p=chaz%2Fyoink version bump cml to version 1.0.2 --- diff --git a/src/Moof/cml/COPYING b/src/Moof/cml/COPYING deleted file mode 100644 index 4eedd32..0000000 --- a/src/Moof/cml/COPYING +++ /dev/null @@ -1,28 +0,0 @@ - -CML - Configurable Math Library -http://www.cmldev.net/ - -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - diff --git a/src/Moof/cml/core/dynamic_1D.h b/src/Moof/cml/core/dynamic_1D.h index 2aae2c6..f69305d 100644 --- a/src/Moof/cml/core/dynamic_1D.h +++ b/src/Moof/cml/core/dynamic_1D.h @@ -13,7 +13,7 @@ Boost Software License, v1.0 (see cml/LICENSE for details). #ifndef dynamic_1D_h #define dynamic_1D_h -#include +#include #include #include @@ -37,15 +37,12 @@ class dynamic_1D /* Record the generator: */ typedef dynamic generator_type; - /* Array implementation: */ - typedef std::vector array_impl; - /* Standard: */ - typedef typename array_impl::value_type value_type; - typedef typename array_impl::pointer pointer; - typedef typename array_impl::reference reference; - typedef typename array_impl::const_reference const_reference; - typedef typename array_impl::const_pointer const_pointer; + typedef typename allocator_type::value_type value_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::const_pointer const_pointer; /* For matching by memory type: */ typedef dynamic_memory_tag memory_tag; @@ -69,16 +66,29 @@ class dynamic_1D public: /** Construct a dynamic array with no size. */ - dynamic_1D() {} + dynamic_1D() : m_size(0), m_data(0), m_alloc() {} /** Construct a dynamic array given the size. */ - explicit dynamic_1D(size_t size) : m_data(size) {} + explicit dynamic_1D(size_t size) : m_size(0), m_data(0), m_alloc() { + this->resize(size); + } + + /** Copy construct a dynamic array. */ + dynamic_1D(const dynamic_1D& other) + : m_size(0), m_data(0), m_alloc() + { + this->copy(other); + } + + ~dynamic_1D() { + this->destroy(); + } public: /** Return the number of elements in the array. */ - size_t size() const { return this->m_data.size(); } + size_t size() const { return m_size; } /** Access to the data as a C array. * @@ -87,7 +97,7 @@ class dynamic_1D * * @note This function does not range-check the argument. */ - reference operator[](size_t i) { return this->m_data[i]; } + reference operator[](size_t i) { return m_data[i]; } /** Const access to the data as a C array. * @@ -96,7 +106,7 @@ class dynamic_1D * * @note This function does not range-check the argument. */ - const_reference operator[](size_t i) const { return this->m_data[i]; } + const_reference operator[](size_t i) const { return m_data[i]; } /** Return access to the data as a raw pointer. */ pointer data() { return &m_data[0]; } @@ -107,16 +117,81 @@ class dynamic_1D public: - /** Set the array size to the given value. + /** Set the array size to the given value. The previous contents are + * destroyed before reallocating the array. If s == size(), + * nothing happens. * * @warning This is not guaranteed to preserve the original data. */ - void resize(size_t s) { this->m_data.resize(s); } + void resize(size_t s) { + + /* Nothing to do if the size isn't changing: */ + if(s == m_size) return; + + /* Destroy the current array contents: */ + this->destroy(); + + /* Set the new size if non-zero: */ + if(s > 0) { + value_type* data = m_alloc.allocate(s); + for(size_t i = 0; i < s; ++ i) + m_alloc.construct(&data[i], value_type()); + + /* Success, save s and data: */ + m_size = s; + m_data = data; + } + } + + /** Copy the source array. The previous contents are destroyed before + * reallocating the array. If other == *this, nothing happens. + */ + void copy(const dynamic_1D& other) { + + /* Nothing to do if it's the same array: */ + if(&other == this) return; + + /* Destroy the current array contents: */ + this->destroy(); + + /* Set the new size if non-zero: */ + size_t s = other.size(); + if(s > 0) { + value_type* data = m_alloc.allocate(s); + for(size_t i = 0; i < s; ++ i) + m_alloc.construct(&data[i], other[i]); + + /* Success, so save the new array and the size: */ + m_size = s; + m_data = data; + } + } protected: - array_impl m_data; + /** Destroy the current contents of the array. */ + void destroy() { + if(m_data) { + for(size_t i = 0; i < m_size; ++ i) + m_alloc.destroy(&m_data[i]); + m_alloc.deallocate(m_data, m_size); + m_size = 0; + m_data = 0; + } + } + + + protected: + + /** Current array size (may be 0). */ + size_t m_size; + + /** Array data (may be NULL). */ + value_type* m_data; + + /** Allocator for the array. */ + allocator_type m_alloc; }; } // namespace cml diff --git a/src/Moof/cml/core/dynamic_2D.h b/src/Moof/cml/core/dynamic_2D.h index c6ea386..374c539 100644 --- a/src/Moof/cml/core/dynamic_2D.h +++ b/src/Moof/cml/core/dynamic_2D.h @@ -13,7 +13,7 @@ Boost Software License, v1.0 (see cml/LICENSE for details). #ifndef dynamic_2D_h #define dynamic_2D_h -#include +#include #include #include #include @@ -40,15 +40,12 @@ class dynamic_2D /* Record the generator: */ typedef dynamic generator_type; - /* Array implementation: */ - typedef std::vector array_impl; - /* Standard: */ - typedef typename array_impl::value_type value_type; - typedef typename array_impl::pointer pointer; - typedef typename array_impl::reference reference; - typedef typename array_impl::const_reference const_reference; - typedef typename array_impl::const_pointer const_pointer; + typedef typename allocator_type::value_type value_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::const_pointer const_pointer; /* For matching by memory layout: */ typedef Layout layout; @@ -66,7 +63,8 @@ class dynamic_2D typedef twod_tag dimension_tag; /* To simplify the matrix transpose operator: */ - typedef dynamic_2D transposed_type; + typedef dynamic_2D::type, + Layout,Alloc> transposed_type; /* To simplify the matrix row and column operators: */ typedef dynamic_1D row_array_type; @@ -76,19 +74,25 @@ class dynamic_2D protected: /** Construct a dynamic array with no size. */ - dynamic_2D() {} + dynamic_2D() : m_rows(0), m_cols(0), m_data(0), m_alloc() {} - /** Construct a dynamic matrix given the dimensions. - * - * This constructor is guaranteed to throw only if the allocator throws. - * If the array implementation guarantees that the array data structure is - * not modified after an exception, then this constructor is - * exception-safe. - * - * @throws only if the allocator throws during an allocation. - */ + /** Construct a dynamic matrix given the dimensions. */ explicit dynamic_2D(size_t rows, size_t cols) - : m_rows(rows), m_cols(cols), m_data(rows*cols) {} + : m_rows(0), m_cols(0), m_data(0), m_alloc() + { + this->resize(rows, cols); + } + + /** Copy construct a dynamic matrix. */ + dynamic_2D(const dynamic_2D& other) + : m_rows(0), m_cols(0), m_data(0), m_alloc() + { + this->copy(other); + } + + ~dynamic_2D() { + this->destroy(); + } public: @@ -114,7 +118,7 @@ class dynamic_2D * @returns mutable reference. */ reference operator()(size_t row, size_t col) { - return get_element(row, col, layout()); + return this->get_element(row, col, layout()); } /** Access the given element of the matrix. @@ -124,7 +128,7 @@ class dynamic_2D * @returns const reference. */ const_reference operator()(size_t row, size_t col) const { - return get_element(row, col, layout()); + return this->get_element(row, col, layout()); } /** Return access to the data as a raw pointer. */ @@ -136,12 +140,58 @@ class dynamic_2D public: - /** Resize the array. + /** Set the array dimensions. The previous contents are destroyed + * before reallocating the array. If the number of rows and columns + * isn't changing, nothing happens. Also, if either rows or cols is 0, + * the array is cleared. * * @warning This is not guaranteed to preserve the original data. */ void resize(size_t rows, size_t cols) { - m_data.resize(rows*cols); m_rows = rows; m_cols = cols; + + /* Nothing to do if the size isn't changing: */ + if(rows == m_rows && cols == m_cols) return; + + /* Destroy the current array contents: */ + this->destroy(); + + /* Set the new size if non-zero: */ + if(rows*cols > 0) { + value_type* data = m_alloc.allocate(rows*cols); + for(size_t i = 0; i < rows*cols; ++ i) + m_alloc.construct(&data[i], value_type()); + + /* Success, so save the new array and the dimensions: */ + m_rows = rows; + m_cols = cols; + m_data = data; + } + } + + /** Copy the other array. The previous contents are destroyed before + * reallocating the array. If other == *this, nothing happens. Also, + * if either other.rows() or other.cols() is 0, the array is cleared. + */ + void copy(const dynamic_2D& other) { + + /* Nothing to do if it's the same array: */ + if(&other == this) return; + + /* Destroy the current array contents: */ + this->destroy(); + + /* Set the new size if non-zero: */ + size_t rows = other.rows(), cols = other.cols(); + if(rows*cols > 0) { + value_type* data = m_alloc.allocate(rows*cols); + for(size_t i = 0; i < rows*cols; ++ i) + m_alloc.construct(&data[i], other[i]); + + /* Success, so save the new array and the dimensions: */ + m_rows = rows; + m_cols = cols; + m_data = data; + } } @@ -166,8 +216,28 @@ class dynamic_2D protected: + /** Destroy the current contents of the array. */ + void destroy() { + if(m_data) { + for(size_t i = 0; i < m_rows*m_cols; ++ i) + m_alloc.destroy(&m_data[i]); + m_alloc.deallocate(m_data, m_rows*m_cols); + m_rows = m_cols = 0; + m_data = 0; + } + } + + + protected: + + /** Current array dimensions (may be 0,0). */ size_t m_rows, m_cols; - array_impl m_data; + + /** Array data (may be NULL). */ + value_type* m_data; + + /** Allocator for the array. */ + allocator_type m_alloc; }; } // namespace cml diff --git a/src/Moof/cml/core/external_2D.h b/src/Moof/cml/core/external_2D.h index 7461c51..fec6a76 100644 --- a/src/Moof/cml/core/external_2D.h +++ b/src/Moof/cml/core/external_2D.h @@ -66,7 +66,8 @@ class external_2D typedef twod_tag dimension_tag; /* To simplify the matrix transpose operator: */ - typedef fixed_2D transposed_type; + typedef fixed_2D::type, + Cols,Rows,Layout> transposed_type; /* Note: the transposed type must be fixed_2D, since an external array * cannot be specified without a corresponding memory location. */ @@ -204,8 +205,8 @@ class external_2D typedef twod_tag dimension_tag; /* To simplify the matrix transpose operator: */ - typedef dynamic_2D - transposed_type; + typedef dynamic_2D::type, + Layout, CML_DEFAULT_ARRAY_ALLOC> transposed_type; /* To simplify the matrix row and column operators: */ typedef dynamic_1D row_array_type; diff --git a/src/Moof/cml/core/fixed_2D.h b/src/Moof/cml/core/fixed_2D.h index 44af7e4..0f68890 100644 --- a/src/Moof/cml/core/fixed_2D.h +++ b/src/Moof/cml/core/fixed_2D.h @@ -100,7 +100,8 @@ class fixed_2D typedef twod_tag dimension_tag; /* To simplify the matrix transpose operator: */ - typedef fixed_2D transposed_type; + typedef fixed_2D::type, + Cols,Rows,Layout> transposed_type; /* To simplify the matrix row and column operators: */ typedef fixed_1D row_array_type; diff --git a/src/Moof/cml/core/meta/switch.h b/src/Moof/cml/core/meta/switch.h index 6f4383a..736e21a 100644 --- a/src/Moof/cml/core/meta/switch.h +++ b/src/Moof/cml/core/meta/switch.h @@ -83,32 +83,6 @@ template struct select_switch { typedef typename @@ -128,38 +102,7 @@ template > > > > > > > > > /* 10 */ - > > > > > > > > > > /* 10 */ - > > > > /* 4 */ -#else - , NilCase -#endif > > > > > > /* 6 */ > > > > > > > > > > /* 10 */ ::template match::result result; diff --git a/src/Moof/cml/et/scalar_promotions.h b/src/Moof/cml/et/scalar_promotions.h index bb6f8a2..5c6a4a1 100644 --- a/src/Moof/cml/et/scalar_promotions.h +++ b/src/Moof/cml/et/scalar_promotions.h @@ -19,9 +19,6 @@ Boost Software License, v1.0 (see cml/LICENSE for details). namespace cml { namespace et { -// #define CML_USE_OLD_SCALAR_PROMOTIONS -#if !defined(CML_USE_OLD_SCALAR_PROMOTIONS) - /* The type promotion code below is a slightly modified version of: * http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01.html */ @@ -87,9 +84,14 @@ struct promote2 { template struct promote_trait { + + // Need to remove const-ness: + typedef typename cml::remove_const::type T1_non_const; + typedef typename cml::remove_const::type T2_non_const; + // Handle promotion of small integers to int/unsigned int - typedef typename autopromote_trait::T_numtype T1; - typedef typename autopromote_trait::T_numtype T2; + typedef typename autopromote_trait::T_numtype T1; + typedef typename autopromote_trait::T_numtype T2; // True if T1 is higher ranked enum { @@ -140,101 +142,6 @@ template struct ScalarPromote typedef typename detail::promote_trait::T_promote type; }; -#else - -namespace detail { - -/** @class IntPromote - * @brief Helper template to int-promote a type. - */ -template struct IntPromote -{ - /* Signed -> signed int, unsigned -> unsigned int: */ - typedef typename select_switch::result result; -}; - -} // namespace detail - -/** @class ScalarPromote - * @brief Template for compile-time type promotion via C promotion rules. - */ -template struct ScalarPromote -{ - /* Integral-promote the types (if possible). */ - typedef typename detail::IntPromote::result E1; - typedef typename detail::IntPromote::result E2; - - /* If sizeof(long) == sizeof(unsigned int), promote to unsigned long. - * Otherwise, sizeof(long) > sizeof(int), so promote to long. - */ - typedef typename select_if::result uint_promotion; - - /* Do the selection on the promoted types: */ - typedef typename select_switch< - type_pair, - -#if defined(CML_USE_LONG_DOUBLE) - type_pair, long double, - type_pair, long double, - type_pair, long double, -#endif - - type_pair, double, - type_pair, double, - type_pair, double, - - type_pair, float, - type_pair, float, - type_pair, float, - - type_pair, void - - >::result float_filter; - - /* The promoted integral types really matter here: */ - typedef typename select_switch< - type_pair, - - type_pair, unsigned long, - type_pair, unsigned long, - type_pair, unsigned long, - - type_pair, long, - type_pair, uint_promotion, - type_pair, uint_promotion, - - type_pair, long, - type_pair, long, - - type_pair, unsigned int, - type_pair, unsigned int, - type_pair, unsigned int, - - type_pair, int, - type_pair, int, - type_pair, int, - - type_pair, void - - >::result int_filter; - - /* Deduce the final type: */ - typedef typename select_if< - same_type::is_true, - int_filter, float_filter>::result type; -}; -#endif - } // namespace et } // namespace cml diff --git a/src/Moof/cml/mathlib/interpolation.h b/src/Moof/cml/mathlib/interpolation.h index 79d57ae..4a9fd54 100644 --- a/src/Moof/cml/mathlib/interpolation.h +++ b/src/Moof/cml/mathlib/interpolation.h @@ -989,7 +989,7 @@ lerp(const T1& val0, const T2& val1, Scalar u) temporary_type result; detail::InterpResize(result, val1, size_tag()); - result = val0 * (Scalar(1) - u) + val1 * u; + result = (Scalar(1) - u) * val0 + u * val1; return result; } diff --git a/src/Moof/cml/mathlib/matrix_rotation.h b/src/Moof/cml/mathlib/matrix_rotation.h index 2298c22..872edff 100644 --- a/src/Moof/cml/mathlib/matrix_rotation.h +++ b/src/Moof/cml/mathlib/matrix_rotation.h @@ -281,8 +281,6 @@ matrix_rotation_euler_derivatives( /* Checking */ detail::CheckMatLinear3D(m); - identity_transform(m); - size_t i, j, k; bool odd, repeat; detail::unpack_euler_order(order, i, j, k, odd, repeat); @@ -952,6 +950,20 @@ void matrix_to_euler( } } +/** Convenience function to return a 3D vector containing the Euler angles + * in the requested order. + */ +template < class MatT, typename Real > vector< Real, fixed<3> > +matrix_to_euler( + const MatT& m, + EulerOrder order, + Real tolerance = epsilon::placeholder()) +{ + Real e0, e1, e2; + matrix_to_euler(m, e0, e1, e2, order, tolerance); + return vector< Real, fixed<3> >(e0, e1, e2); +} + /** Convert a 2D rotation matrix to a rotation angle */ template < class MatT > typename MatT::value_type matrix_to_rotation_2D(const MatT& m) diff --git a/src/Moof/cml/matrix/external.h b/src/Moof/cml/matrix/external.h index 1af9266..6bfb8c4 100644 --- a/src/Moof/cml/matrix/external.h +++ b/src/Moof/cml/matrix/external.h @@ -78,7 +78,7 @@ class matrix,BasisOrient,Layout> /* To simplify the matrix transpose operator: */ typedef matrix< - Element, + typename cml::remove_const::type, typename array_type::transposed_type::generator_type, BasisOrient, Layout diff --git a/src/Moof/cml/matrix/fixed.h b/src/Moof/cml/matrix/fixed.h index f35bf1c..1a64938 100644 --- a/src/Moof/cml/matrix/fixed.h +++ b/src/Moof/cml/matrix/fixed.h @@ -71,10 +71,9 @@ class matrix,BasisOrient,Layout> /* To simplify the matrix transpose operator: */ typedef matrix< - Element, + typename cml::remove_const::type, typename array_type::transposed_type::generator_type, - BasisOrient, - Layout + BasisOrient, Layout > transposed_type; /* To simplify the matrix row and column operators: */ diff --git a/src/Moof/cml/matrix/inverse.h b/src/Moof/cml/matrix/inverse.h index 4d80e6f..359a42c 100644 --- a/src/Moof/cml/matrix/inverse.h +++ b/src/Moof/cml/matrix/inverse.h @@ -13,6 +13,7 @@ Boost Software License, v1.0 (see cml/LICENSE for details). #ifndef matrix_inverse_h #define matrix_inverse_h +#include #include namespace cml { diff --git a/src/Moof/cml/quaternion.h b/src/Moof/cml/quaternion.h index 595fe03..eee3da8 100644 --- a/src/Moof/cml/quaternion.h +++ b/src/Moof/cml/quaternion.h @@ -59,10 +59,8 @@ template, #include #include #include -#include - #include - +#include #endif // ------------------------------------------------------------------------- diff --git a/src/Moof/cml/quaternion/quaternion_print.h b/src/Moof/cml/quaternion/quaternion_print.h index dd73d3c..483dfc4 100644 --- a/src/Moof/cml/quaternion/quaternion_print.h +++ b/src/Moof/cml/quaternion/quaternion_print.h @@ -48,11 +48,21 @@ operator<<(std::ostream& os, const cml::quaternion& q) template std::ostream& operator<<(std::ostream& os, const cml::quaternion& q) { - os << "["; - for (size_t i = 0; i < 4; ++i) { - os << " " << q[i]; - } - os << " ]"; + typedef typename cml::quaternion::order_type order_type; + enum { + W = order_type::W, + X = order_type::X, + Y = order_type::Y, + Z = order_type::Z + }; + + os << "[ " + << " " << q[W] + << " " << q[X] + << " " << q[Y] + << " " << q[Z] + << " ]"; + return os; } diff --git a/src/Moof/cml/vector/external.h b/src/Moof/cml/vector/external.h index 43c4c46..6f0f215 100644 --- a/src/Moof/cml/vector/external.h +++ b/src/Moof/cml/vector/external.h @@ -49,7 +49,8 @@ class vector< Element, external > typedef vector_type expr_type; /* For integration into the expression template code: */ - typedef vector< Element,fixed > temporary_type; + typedef vector::type, + fixed > temporary_type; typedef typename temporary_type::subvector_type subvector_type; /* Note: this ensures that an external vector is copied into the proper * temporary; external<> temporaries are not allowed. @@ -188,7 +189,8 @@ class vector< Element, external<> > typedef vector_type expr_type; /* For integration into the expression template code: */ - typedef vector< Element, dynamic<> > temporary_type; + typedef vector::type, + dynamic<> > temporary_type; /* Note: this ensures that an external vector is copied into the proper * temporary; external<> temporaries are not allowed. */ diff --git a/src/Moof/stlplus/COPYING b/src/Moof/stlplus/COPYING deleted file mode 100644 index 7ad0a6e..0000000 --- a/src/Moof/stlplus/COPYING +++ /dev/null @@ -1,29 +0,0 @@ - -Parts of STLplus C++ Library Collection -http://stlplus.sourceforge.net/ - -© 1999-2004 Southampton University, 2004-2009 Andy Rushton. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above Copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above Copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the STLplus library nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -This software is provided by the Copyright holders and contributors "as is" and -any express or implied warranties, including, but not limited to, the implied -warranties of merchantability and fitness for a particular purpose are -disclaimed. In no event shall the Copyright owner or contributors be liable for -any direct, indirect, incidental, special, exemplary, or consequential damages -(including, but not limited to, procurement of substitute goods or services; -loss of use, data, or profits; or business interruption) however caused and on -any theory of liability, whether in contract, strict liability, or tort -(including negligence or otherwise) arising in any way out of the use of this -software, even if advised of the possibility of such damage. -