Hi,

On Tue, 2007-05-08 at 10:42 -0500, Daniel E. Shipton wrote: 
> On 5/8/07, Gerrit Voss <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > On Tue, 2007-05-08 at 00:22 -0400, Dirk Reiners wrote:
> > >       Hi Gerrit,
> > >
> > > Gerrit Voss wrote:
> > > >
> >
> > >  > btw I'm playing around with gmtl for 2.x.
> > >
> > > How's that going? Pure or using a wrapper to adapt to our old API?
> >
> > small wrapper as we build around member functions and gmtl is build
> > around free functions.
> >
> > So far it looks ok, but I haven't decided if the missing type
> > propagation and the inflexibilities in using different data_types
> > together is a good or bad thing ;-) (Or just something I haven't
> > figured out yet ;-))
> >
> 
> Do you mind expanding those comments about what you found.. we might
> have a few answers ;)

one simple example is :

gmtl::Vec2f v1;
gmtl::Vec2f v2;

v1 = v2 * 2.;

does not compile because the scalar is double not float.

This is mainly because you force the double/float conversion to the
parameter of the overloaded, templated * operator by using T for the
vector and the scalar arg. 
But this way the compiler fails to deduct the template arguments in
order to find a valid operator * as neither a T=double nor T=float
instantiation exactly matches the required signature (Vec2f, double).

A more flexible way would be to take T for the Vector and T1 for the
scalar Argument during the operator definition and do the to T
conversion in the ScalarArg constructor, something like :

template<typename T, unsigned SIZE, typename R1, typename T1> inline

VecBase<T, 
        SIZE, 
        meta::VecBinaryExpr<VecBase<T,SIZE,R1>,
                            VecBase<T,SIZE,meta::ScalarArg<T> >,
                            meta::VecMultBinary> 
       >
operator *(const VecBase<T,SIZE,R1>& v1, const T1 scalar)
{
   return 
     VecBase<T,
             SIZE,
             meta::VecBinaryExpr<VecBase<T,SIZE,R1>,
                                 VecBase<T,SIZE, meta::ScalarArg<T> >,
                                 meta::VecMultBinary> >(
                                         
               meta::VecBinaryExpr<VecBase<T,SIZE,R1>,
                     VecBase<T,SIZE, meta::ScalarArg<T> >,
                     meta::VecMultBinary>(
              
                       v1,
                       meta::ScalarArg<T>(scalar)) );
}

this way any type that is convertible to T works as a scalar
argument.

But as I said I haven't made up my mind if enforcing the scalar
argument type to match the vector is a good or bad thing. 

I just stumbled across it as I was doing some simulation code which 
is written to run with either float or double precision so I needed to
adjust the constants depending on the precision.


I'm still playing with the type propagation so I don't have a good
example yet. I ran across it first when I wanted to use a coefficient
array to be multiplied to a vector (something like a * v) but I'm
still running over all the possibilities to do this ;-) So there is no
finished example yet ;-)



regards,
  gerrit






-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to