
library contain vector(any static size), matrix 4x4, quaternion, plane(3D), sphere(3D), AABB(3D) and have little fuzzy logic support. This is little code snippet of vector class: ... template < typename T, IT N, template<class> class IPolicy > class Vector : private IPolicy<T> { public: typedef Vector<T, N, IPolicy> VectorType; typedef T value_type; typedef T* iterator; typedef const T* const_iterator; public: Vector() { IPolicy<T>::construct<N>( _a ); } // copy constructor & assigment operator are fine // (hold objects by value) template<IT M> explicit Vector( const Vector<T, M>& rhs ) { enum { copy_sz = smin<M, N>::result }; std::copy(rhs._a, rhs._a + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); } explicit Vector( const T& val ) { nInternal::for_each_set<T, N>::Do(_a, val); } Vector ( const T& x, const T& y, typename boost::enable_if_c<(N == 2)> * = 0 ) { _a[0] = x; _a[1] = y; } Vector ( const T& x, const T& y, const T& z, typename boost::enable_if_c<(N == 3)> * = 0 ) { _a[0] = x; _a[1] = y; _a[2] = z; } Vector ( const T& x, const T& y, const T& z, const T& w, typename boost::enable_if_c<(N == 4)> * = 0 ) { _a[0] = x; _a[1] = y; _a[2] = z; _a[3] = w; } template<IT M> explicit Vector( const T (&arg)[M] ) { enum { copy_sz = smin<M, N>::result }; std::copy(arg, arg + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); } template<IT M> Vector& operator = ( const T (&arg)[M] ) { enum { copy_sz = smin<M, N>::result }; std::copy(arg, arg + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); return *this; } template<IT M> Vector& operator = ( const Vector<T, M>& rhs ) { return operator = ( rhs._a ); } Vector& operator = ( const T& val ) { Fill(val); return *this; } T& operator [] ( IT idx ) { return _a[idx]; } T& at( IT idx ) { if( idx < N ) return _a[idx]; throw std::out_of_range(typeid(*this).name()); } template<IT I> T& at_c() { BOOST_STATIC_ASSERT( I < N ); return _a[I]; } const T& operator [] ( IT idx ) const { return const_cast<VectorType*>(this)->operator [](idx); } const T& at( IT idx ) const { return const_cast<VectorType*>(this)->at(idx); } template<IT I> const T& at_c() const { return const_cast<VectorType*>(this)->at_c<I>(); } const_iterator begin() const { return &_a[0]; } iterator begin() { return &_a[0]; } const_iterator end() const { return &_a[N]; } iterator end() { return &_a[N]; } template<template<class> class IP> operator Vector<T, N, IP>& () { return reinterpret_cast<Vector<T, N, IP>&>(*this); } T& x( typename boost::enable_if_c<(N > 0)> * = 0 ) { return _a[0]; } T& y( typename boost::enable_if_c<(N > 1)> * = 0 ) { return _a[1]; } T& z( typename boost::enable_if_c<(N > 2)> * = 0 ) { return _a[2]; } T& w( typename boost::enable_if_c<(N > 3)> * = 0 ) { return _a[3]; } Vector operator - () const { Vector ret; nInternal::neg_op<T, N>::Do(_a, ret._a); return ret; } bool IsEqual( const VectorType& vec, const T& accuracy ) const { return nInternal::cmp_op<T, N>::Do ( _a, vec._a, nInternal::not_near<T>(accuracy) ); } bool operator == ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do(_a, vec._a, std::not_equal_to<T>()); } bool operator != ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do(_a, vec._a, std::equal_to<T>()); } bool operator < ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do ( _a, vec._a, std::not2(std::less<T>()) ); } Vector& operator += ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::plus<T>() ); return *this; } Vector& operator -= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::minus<T>() ); return *this; } Vector& operator *= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::multiplies<T>() ); return *this; } Vector& operator /= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::divides<T>() ); return *this; } ... }; Little sample: Vector<3, float> v0(0.f, 1.f, 2.f), v1(1.f), v2(v0 + v1); float _x = v0.x(), _x0 = v0[0], _x1 = v0.at(-1);

Kasak Sergey wrote:
library contain vector(any static size), matrix 4x4, quaternion, plane(3D), sphere(3D), AABB(3D) and have little fuzzy logic support. This is little code snippet of vector class: ...
I always dream that boost has such a library, especially used in graphics programming. And I have seen some previous discussion about it, but it seems no final decision/result. Best Regards cg

Hi, Sergey: Did you compare your library with what is available in Boost and Vault? Geometry is mostly here: http://boost-consulting.com/vault/index.php?&direction=0&order=&directory=Math%20-%20Geometry Quaternions are in Boost http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_math/q... and here: http://boost-consulting.com/vault/index.php?&direction=0&order=&directory=Math%20-%20Numerics There is lot of vector stuff in boost/uBlas http://boost.org/libs/numeric/ublas/doc/index.htm

Yuriy Koblents-Mishke wrote:
Hi, Sergey:
Did you compare your library with what is available in Boost and Vault?
I've looked around for quite some time and I have yet to see any small vector matrix quaternion libraries I like. The closest is for me is tvmet. I've been holding out for MTL4 but I haven't heard anything about it in a while. - Michael Marcin

It might be a good idea to dig through the Boost Quaternion classes - they don't appear to be actively maintained (they're small enough, that it may not be necessary). If you see functionality missing, it would probably be better to try and add it rather than rolling a whole new quaternion library. I'm curious as to which functionality you'd most like to see? Jeremy Pack On 3/5/07, Michael Marcin <mmarcin@method-solutions.com> wrote:
Yuriy Koblents-Mishke wrote:
Hi, Sergey:
Did you compare your library with what is available in Boost and Vault?
I've looked around for quite some time and I have yet to see any small vector matrix quaternion libraries I like. The closest is for me is tvmet.
I've been holding out for MTL4 but I haven't heard anything about it in a while.
- Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi, Jeremy!
If you see functionality missing, it would probably be better to try and add it rather than rolling a whole new >>quaternion library. I'm curious as to which functionality you'd most like to see?
Thanks, may be i can extend current solution. But my quaternion class interact with matrix class, otherwise does not make sense place this library into boost. - Kasak Sergey

If it is geared towards 3D development, it probably ought to provide conversions to and from the various constructs used for 3D transformations (things like rotation matrices, Euler angles etc.). Without that, I think it will just be duplicating functionality already in Boost, just with a different API. How hard would it be to make the Boost Quaternion classes work with the Matrix classes in Ublas? Jeremy Pack On 3/6/07, Triger Trader <tiger_trader@mail.ru> wrote:
Hi, Jeremy!
If you see functionality missing, it would probably be better to try and add it rather than rolling a whole new >>quaternion library. I'm curious as to which functionality you'd most like to see?
Thanks, may be i can extend current solution. But my quaternion class interact with matrix class, otherwise does not make sense place this library into boost.
- Kasak Sergey _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Without that, I think it will just be duplicating functionality already in Boost, just with a different API.
No, this is special library for 3D development. You can choose between performance or precision, size or speed.
How hard would it be to make the Boost Quaternion classes work with the Matrix classes in Ublas?
No, boost quaternion class does not have special functions and matrix conversion. uBLAS - vary size, any needs library. But 3D development want only fixed size vectors and matrices, because we can do loop unrolling for that. Max performance want every 3D developer, plus easy to use tool(and understood). - Kasak Sergey

Jeremy Pack wrote:
If it is geared towards 3D development, it probably ought to provide conversions to and from the various constructs used for 3D transformations (things like rotation matrices, Euler angles etc.). Without that, I think it will just be duplicating functionality already in Boost, just with a different API.
How hard would it be to make the Boost Quaternion classes work with the Matrix classes in Ublas?
Even the Ublas documents recommend not using it for small fixed sized vectors and matrices. It recommends tvmet. What I need is a library with: all types parameterized on a value_type all or most operations optionally customizeable for efficiency or precision concerns conversion between types with different value_types 2, 3 and 4 component vector and point classes 2x2, 3x3, 3x4, 4x4 matrix classes an euler paramaters class (normalized quaternions) euler angles with clear semantics (preferably definable discussed in P.S. below) degrees and radians classes (i also need to define another similar type myself and use it with the rest of the system) trig functions to work with the degrees and radians types cross and dot products for 3 component vectors conversions between euler angles, euler parameters, and matrix representations transformation concatenation vector transformations an optimized implementation using all the tricks of Boost.Fusion and generic programming in general a drop-in replacement unoptimized naive implementation to ease debugging and give a fallback for non-conforming compilers a Boost compatible license This is just off the top of my head but I think it's enough to show that many libraries cover some of my needs but no existing library I have found can cover all of them. P.S. Euler angles are the bain of my existence when writing math libraries and reading reference material or other people's code. The semantics or almost never clearly defined enough. If possible I'd like any euler angles tuple to have the following configurable with details documented. First [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Then [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Finally [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. - Michael Marcin

With matrices and vectors that small that are not resizeable at runtime, I doubt it would need to use Boost Fusion in order to be optimized - templates would only be necessary to make it work the same for floats, doubles or other custom user classes. It would, however, be useful to provide a choice between fast or accurate algorithms, because of the instability of some of the conversions (Euler angles again...). I definitely agree with your point on the difficulties of Euler angles. I've been bitten by that a number of times. Degrees and Radians would probably be best handled by a more generic units library. Either way, designing classes and conversions for them is rather trivial. The main difficulty would be finding the best formulas for the "accurate" function implementations. Jeremy Pack On 3/6/07, Michael Marcin <mmarcin@method-solutions.com> wrote:
Jeremy Pack wrote:
If it is geared towards 3D development, it probably ought to provide conversions to and from the various constructs used for 3D transformations (things like rotation matrices, Euler angles etc.). Without that, I think it will just be duplicating functionality already in Boost, just with a different API.
How hard would it be to make the Boost Quaternion classes work with the Matrix classes in Ublas?
Even the Ublas documents recommend not using it for small fixed sized vectors and matrices. It recommends tvmet.
What I need is a library with:
all types parameterized on a value_type all or most operations optionally customizeable for efficiency or precision concerns conversion between types with different value_types 2, 3 and 4 component vector and point classes 2x2, 3x3, 3x4, 4x4 matrix classes an euler paramaters class (normalized quaternions) euler angles with clear semantics (preferably definable discussed in P.S. below) degrees and radians classes (i also need to define another similar type myself and use it with the rest of the system) trig functions to work with the degrees and radians types cross and dot products for 3 component vectors conversions between euler angles, euler parameters, and matrix representations transformation concatenation vector transformations an optimized implementation using all the tricks of Boost.Fusion and generic programming in general a drop-in replacement unoptimized naive implementation to ease debugging and give a fallback for non-conforming compilers a Boost compatible license
This is just off the top of my head but I think it's enough to show that many libraries cover some of my needs but no existing library I have found can cover all of them.
P.S. Euler angles are the bain of my existence when writing math libraries and reading reference material or other people's code. The semantics or almost never clearly defined enough. If possible I'd like any euler angles tuple to have the following configurable with details documented.
First [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Then [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Finally [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis.
- Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

I'm always amazed that this discussion comes up from time to time and no one mentions cgal (www.cgal.org) which has a lot of the functionality (although 3D transformations could perhaps be improved, you can do it by extending the framework). In addition to kernel objects (2D, 3D, and d-dimensional for any d), incl. usual objects and transformation hierarchy, and predicates / constructions / intersections / distance computations, it has a bunch of data structure and algorithms such as convex hulls, minimum encl. boxes and ellipsoids, interpolation, triangulations and meshes, whatnot. It is *huge* and if not complete, much more so than anything you would write from scratch. It's also very easy to screw those functions, such as distance between two segments in 3D. Just try, and then you'll appreciate how much cgal can do for you. Their transformation hierarchy is excellent, storing only a single float/double for a scaling transformation from the origin, or three float/doubles for a translation, e.g., and allowing either Cartesian or homogeneous coordinates. It would be much more efficient to design an interface for quaternion / Euler angles / yaw/pitch/roll on top of the 3D transformation hierarchy, and the folks at cgal would not only love you but perhaps integrate your contribution into their releases. (Making no promises, I'm not involved with this project any more...) Go take a look at www.cgal.org and send msgs to their devel mailing list for any questions. Good luck with your projects regardless if you do or not! -- Herve On Mar 6, 2007, at 3:07 PM, Michael Marcin wrote:
Jeremy Pack wrote:
If it is geared towards 3D development, it probably ought to provide conversions to and from the various constructs used for 3D transformations (things like rotation matrices, Euler angles etc.). Without that, I think it will just be duplicating functionality already in Boost, just with a different API.
How hard would it be to make the Boost Quaternion classes work with the Matrix classes in Ublas?
Even the Ublas documents recommend not using it for small fixed sized vectors and matrices. It recommends tvmet.
What I need is a library with:
all types parameterized on a value_type all or most operations optionally customizeable for efficiency or precision concerns conversion between types with different value_types 2, 3 and 4 component vector and point classes 2x2, 3x3, 3x4, 4x4 matrix classes an euler paramaters class (normalized quaternions) euler angles with clear semantics (preferably definable discussed in P.S. below) degrees and radians classes (i also need to define another similar type myself and use it with the rest of the system) trig functions to work with the degrees and radians types cross and dot products for 3 component vectors conversions between euler angles, euler parameters, and matrix representations transformation concatenation vector transformations an optimized implementation using all the tricks of Boost.Fusion and generic programming in general a drop-in replacement unoptimized naive implementation to ease debugging and give a fallback for non-conforming compilers a Boost compatible license
This is just off the top of my head but I think it's enough to show that many libraries cover some of my needs but no existing library I have found can cover all of them.
P.S. Euler angles are the bain of my existence when writing math libraries and reading reference material or other people's code. The semantics or almost never clearly defined enough. If possible I'd like any euler angles tuple to have the following configurable with details documented.
First [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Then [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis. Finally [yaw | pitch | roll] is applied as a [counter-clockwise | clockwise] rotation around the [positive | negative] [x | y | z] axis.
- Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/ listinfo.cgi/boost

Hervé Brönnimann wrote:
I'm always amazed that this discussion comes up from time to time and no one mentions cgal (www.cgal.org) which has a lot of the functionality (although 3D transformations could perhaps be improved, you can do it by extending the framework).
In addition to kernel objects (2D, 3D, and d-dimensional for any d), incl. usual objects and transformation hierarchy, and predicates / constructions / intersections / distance computations, it has a bunch of data structure and algorithms such as convex hulls, minimum encl. boxes and ellipsoids, interpolation, triangulations and meshes, whatnot. It is *huge* and if not complete, much more so than anything you would write from scratch. It's also very easy to screw those functions, such as distance between two segments in 3D. Just try, and then you'll appreciate how much cgal can do for you.
Their transformation hierarchy is excellent, storing only a single float/double for a scaling transformation from the origin, or three float/doubles for a translation, e.g., and allowing either Cartesian or homogeneous coordinates. It would be much more efficient to design an interface for quaternion / Euler angles / yaw/pitch/roll on top of the 3D transformation hierarchy, and the folks at cgal would not only love you but perhaps integrate your contribution into their releases. (Making no promises, I'm not involved with this project any more...)
Go take a look at www.cgal.org and send msgs to their devel mailing list for any questions. Good luck with your projects regardless if you do or not!
I've never heard of it before but I just went to their page and I am instantly met with the first case where it does not fit my requirements. It requires you to buy a commercial license... this is hardly a Boost compatible license. - Michael Marcin

Michael: You are disingenuous :) It is not a boost-compatible license, but it is ***open-source*** and that applies to every user, even those working for a commercial product: <Quote from www.cgal.org>
CGAL is distributed under a dual-license scheme. Users who develop software under an open source license can use CGAL freely. Users who want to protect their intellectual property, but want to profit from off-the-shelf, reliable, and efficient geometric algorithms can obtain a commercial license from GeometryFactory. For more details see the License page.
See http://www.cgal.org/license.html for details. In short, cgal is split into three core areas (kernel, basic lib, and support lib). As stated on their page:
Approximately, the Kernel and Support libraries are under the LGPL, and the Basic library is under the QPL, but there are some exceptions in both directions. A more detailed list of packages with their license can be found in the packages overview web page.
If you do not want to make your additions or modifications public, you can buy the commercial license. But if you only want to *use* it off the shelf, even for proprietary and commercial projects, the LGPL should allow you to do that without buying a commercial license. From their web page:
The Lesser General Public License gives you the right to use and copy the code freely. It is also possible to modify the code under the condition that the resulting modification is released as source code under the LGPL with any binary distribution that you may do of a resulting application using these LGPL parts.
The Q Public License gives you the right to use the code under the condition that any program using it be released itself under an Open Source license. Note that this also concerns software that you develop for in-house usage. Concerning modifications, they are also allowed under the condition that they be distributed as patches against the original sources. But the parts that were discussed in this thread, i.e. the 2D/3D kernel, are mostly (all) under LGPL. So unless your circumstances are very particular and you *really* need the QPL parts, I don't
In other words, as long as you do not require a modification, and do not distribute cgal (either in source or in binary) with your own project., you do not need to buy a license. If you require modifications, you can make a package which you distribute as open source from your modifications (with the proviso of the LGPL that your modifications must acknowledge CGAL and must be distribute in source openly under a LGPL license, and not only in binary). But your own project can use these LGPL again without needing to purchase a commercial license. The parts under QPL are more stringent requirements, again from their page: think you are required to purchase a commercial license at all. -- Hervé Brönnimann hervebronnimann@mac.com On Mar 7, 2007, at 10:12 PM, Michael Marcin wrote:
I've never heard of it before but I just went to their page and I am instantly met with the first case where it does not fit my requirements. It requires you to buy a commercial license... this is hardly a Boost compatible license.
- Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/ listinfo.cgi/boost

Hervé Brönnimann wrote:
Michael: You are disingenuous :)
Quite possibly :)
It is not a boost-compatible license, but it is ***open-source*** and that applies to every user, even those working for a commercial product:
It is open-source but GPL and LGPL licenses are pretty bad for this type of library. To use LGPL properly you basically have to use a .dll for the math libray which is no-go for these types of performance critical problems. Also those 3 letters tend have the business types around here on edge. To ensure the protection the company's IP they would make sure we bought the commercial license. To do that more hoops have to be jumped through to approve the expense and make sure the terms are acceptable to all the business and lawyer types. And all this is before we can even use the damn thing seriously to decide if we like it. I love the open-source community but GPL is just too scary to go near if your company holds value in its proprietary technology. - Michael Marcin P.S. I've never used source code without having to modify it or work around it, boost and various standard libraries included.

Hi, Yuiri!
Geometry is mostly here: http://boost-consulting.com/vault/index.php?&direction=0&order=&directory=Math%20-%20Geometry
Wykobi_Computational_Geometry - too fat and huge, need lot of redesign job. MN_Geometry_01 - good, but no special vector related functions. geometryJH_01 - too cheap implementation.
There is lot of vector stuff in boost/uBlas
uBlas is not for geometry vector. And again, my library designed for realtime 3D application programming, is not for scientific calculations.

Kasak Sergey said: (by the date of Mon, 5 Mar 2007 03:45:25 +0300)
library contain vector(any static size), matrix 4x4, quaternion, plane(3D), sphere(3D), AABB(3D) and have little fuzzy logic support. This is little code snippet of vector class:
Hello Sergey, It is really great that you want to spent time hard working on such a library. There have been numerous discussions in the past. I can forward you all of them if you want (they sit in my inbox). Every time I was hoping that such library will finally be done. The problem is very difficult, because every person seems to have a unique idea about what this library should have, or shouldn't. Perhaps even the library name name should be different to make it clear how the scope of the library is restricted. I still remember my total surprise, when somebody asked why there is no *planned* support for conversions between cartesian, polar and cylindrical coordinates. Support for polylines, points, splines, boxes, tetrahedrons. Support for higher dimensions 4D, 5D, etc... It's a geometry after all, right? A quote from old thread, I proposed that such library should have only:
vector2 vector3 vector4 matrix2 matrix3 matrix4 quaternion se3
Someone (Geoffrey Irving) added:
vector1 matrix1 diagonal_matrix2 diagonal_matrix3 symmetric_matrix2 symmetric_matrix3 upper_triangular_matrix2 upper_triangular_matrix3
And finally someone (Theodore Papadopoulo) added:
Euclidean::Point<N> Euclidean::Line<N> Euclidean::SemiLine<N> Euclidean::Segment<N> Euclidean::Simplex<N> Euclidean::Basis<N> Affine:: same as Euclidean except maybe for Basis?? Projective::Point<N> Projective::Line<N> Projective::Basis<N> SemiLines, Segments and Simplices are more complicated to define...
see? And currently I think that se3 is not necessary. If someone needs it, he will create it from available components. So your first step is to very stricly define the scope if your library. It should be: 1. very small (or else, you will never write it), 2. and very coherent (or everyone will point out, why have this, and not that) Ad.2: For instance, why put into library the AABB and not K-dop ? Remove AABB then. Because adding K-dop means that you should add dozens of other bounding volume shapes. I'm not sure about sphere or plane too. What's the rationale? What is that fuzzy logic? wish you luck -- Janek Kozicki |

Kasak, Yes! This is something I've wanted for some time. Some thoughts: * Default to value_type=double so "vector3" Just Works. * It would be good to focus on Concepts so that an n-dimensional vector could be used with other templated linear algebra stuff, including uBlas. * A vector should have a data() method or a data(v) friend function to give access to its internal representation, e.g., for passing it directly to OpenGL. Then I could call glVertex3f(data(v)). * It should be safe to cast a C-style array to a vector, so I could have void old_function(double* vec3) { vector3& v = some_kind_of_cast<vector3&>(vec3); new_function(v); } * Make sure it would be easy to add fourth-order tensors (linear transformations for 3x3 matrices). In computational mechanics those get used a lot. But yes, this is desperately needed in computer graphics and in computational mechanics. I my experience TVMET's behavior (like lack of a regular copy constructor, I think) make for too steep a learning curve. —Ben On 3/4/07, Kasak Sergey <tiger_trader@mail.ru> wrote:
library contain vector(any static size), matrix 4x4, quaternion, plane(3D), sphere(3D), AABB(3D) and have little fuzzy logic support. This is little code snippet of vector class: ... template < typename T, IT N, template<class> class IPolicy > class Vector : private IPolicy<T> { public: typedef Vector<T, N, IPolicy> VectorType; typedef T value_type; typedef T* iterator; typedef const T* const_iterator; public: Vector() { IPolicy<T>::construct<N>( _a ); }
// copy constructor & assigment operator are fine // (hold objects by value)
template<IT M> explicit Vector( const Vector<T, M>& rhs ) { enum { copy_sz = smin<M, N>::result }; std::copy(rhs._a, rhs._a + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); }
explicit Vector( const T& val ) { nInternal::for_each_set<T, N>::Do(_a, val); }
Vector ( const T& x, const T& y, typename boost::enable_if_c<(N == 2)> * = 0 ) { _a[0] = x; _a[1] = y; }
Vector ( const T& x, const T& y, const T& z, typename boost::enable_if_c<(N == 3)> * = 0 ) { _a[0] = x; _a[1] = y; _a[2] = z; }
Vector ( const T& x, const T& y, const T& z, const T& w, typename boost::enable_if_c<(N == 4)> * = 0 ) { _a[0] = x; _a[1] = y; _a[2] = z; _a[3] = w; }
template<IT M> explicit Vector( const T (&arg)[M] ) { enum { copy_sz = smin<M, N>::result }; std::copy(arg, arg + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); }
template<IT M> Vector& operator = ( const T (&arg)[M] ) { enum { copy_sz = smin<M, N>::result }; std::copy(arg, arg + copy_sz, _a); IPolicy<T>::construct<N - copy_sz>( _a + copy_sz ); return *this; }
template<IT M> Vector& operator = ( const Vector<T, M>& rhs ) { return operator = ( rhs._a ); }
Vector& operator = ( const T& val ) { Fill(val); return *this; }
T& operator [] ( IT idx ) { return _a[idx]; }
T& at( IT idx ) { if( idx < N ) return _a[idx];
throw std::out_of_range(typeid(*this).name()); }
template<IT I> T& at_c() { BOOST_STATIC_ASSERT( I < N ); return _a[I]; }
const T& operator [] ( IT idx ) const { return const_cast<VectorType*>(this)->operator [](idx); }
const T& at( IT idx ) const { return const_cast<VectorType*>(this)->at(idx); }
template<IT I> const T& at_c() const { return const_cast<VectorType*>(this)->at_c<I>(); }
const_iterator begin() const { return &_a[0]; } iterator begin() { return &_a[0]; }
const_iterator end() const { return &_a[N]; } iterator end() { return &_a[N]; }
template<template<class> class IP> operator Vector<T, N, IP>& () { return reinterpret_cast<Vector<T, N, IP>&>(*this); }
T& x( typename boost::enable_if_c<(N > 0)> * = 0 ) { return _a[0]; }
T& y( typename boost::enable_if_c<(N > 1)> * = 0 ) { return _a[1]; }
T& z( typename boost::enable_if_c<(N > 2)> * = 0 ) { return _a[2]; }
T& w( typename boost::enable_if_c<(N > 3)> * = 0 ) { return _a[3]; }
Vector operator - () const { Vector ret; nInternal::neg_op<T, N>::Do(_a, ret._a); return ret; }
bool IsEqual( const VectorType& vec, const T& accuracy ) const { return nInternal::cmp_op<T, N>::Do ( _a, vec._a, nInternal::not_near<T>(accuracy) ); }
bool operator == ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do(_a, vec._a, std::not_equal_to<T>()); }
bool operator != ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do(_a, vec._a, std::equal_to<T>()); }
bool operator < ( const VectorType& vec ) const { return nInternal::cmp_op<T, N>::Do ( _a, vec._a, std::not2(std::less<T>()) ); }
Vector& operator += ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::plus<T>() ); return *this; }
Vector& operator -= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::minus<T>() ); return *this; }
Vector& operator *= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::multiplies<T>() ); return *this; }
Vector& operator /= ( const VectorType& other ) { nInternal::bin_op<T, N>::Do ( _a, _a, other._a, std::divides<T>() ); return *this; } ... };
Little sample: Vector<3, float> v0(0.f, 1.f, 2.f), v1(1.f), v2(v0 + v1); float _x = v0.x(), _x0 = v0[0], _x1 = v0.at(-1);
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi, Ben.
Some thoughts: * Default to value_type=double so "vector3" Just Works.
already has, more different typedefs by default: Vector3f, Vector3d...
* It would be good to focus on Concepts so that an n-dimensional vector could be used with other templated linear algebra stuff, including uBlas.
You can use any geometry container in STL algorithms.Not sure about all uBLAS stuff but, I think, it possible...
* A vector should have a data() method or a data(v) friend >> function to give access to its internal representation, e.g., for passing it >> directly to OpenGL. Then I could call glVertex3f(data(v)). * It should be safe to cast a C-style array to a vector, so >> I could have void old_function(double* vec3) { vector3& v = some_kind_of_cast<vector3&>(vec3); new_function(v); }
* Make sure it would be easy to add fourth-order tensors(linear transformations for 3x3 matrices). In computational mechanics those get used a lot.
quaternion+matrix4 can do all 3D related stuff. Also it compatible with all modern API. - Kasak Sergey Already has.
participants (9)
-
Ben FrantzDale
-
gchen
-
Hervé Brönnimann
-
Janek Kozicki
-
Jeremy Pack
-
Kasak Sergey
-
Michael Marcin
-
Triger Trader
-
Yuriy Koblents-Mishke