Boost logo

Boost :

From: John Femiani (JOHN.FEMIANI_at_[hidden])
Date: 2007-10-05 15:51:23


What would be the difference between the cartesian and the vector types?

-- John
 
> -----Original Message-----
> From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]
> On Behalf Of Fernando Cacciola
> Sent: Friday, October 05, 2007 12:35 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Generic Point class and algorithms (was:[GTL]-
> geometric template library - determininginterest)
>
> Michael Fawcett wrote:
>
> >> I.e. point+point is undefined, point-point is a vector, etc...
> >
> > This has been the source of quite a bit of contention in the past.
> > distinction is highly important, and then there are game developers
> > (and others I'm sure) who frequently mix both for optimization
tricks
> > and compatibility with the graphics API.
> >
> Some folks in between those two groups argue that lineal combinations
of
> points in the affine space is also well defined, and that uses point
> addition.
>
> Thus, I typically choose to define:
>
> - point -> point (reflexion)
>
> scalar * point -> point (affine scaling)
> point * scalar -> point (affine scaling)
>
> point * matrix -> point ( affine transformation)
>
> point + point -> point (lineal combination)
>
> point - point -> vector (subtraction)
>
>
>
>
> - vector -> vector (inversion)
>
> scalar * vector ->
> vector * scalar -> vector (scaling)
>
> vector + vector -> vector (addition)
>
> vector - vector -> vector (substraction)
>
> point + vector -> point
> point - vector -> point (displacement)
>
> vector * matrix -> vector (lineal transfomation)
>
> Which allow you to have your cacke and eat it too.
>
> Of course you could say that (ptA - ptA) is not the same as (ptA +
(-ptA)
> )
> and that is a problem
> (the former is a vector while the second is a point)
>
> Yet OTOH both results have the same components, so, why would that be
a
> problem is a statically typed language?
>
>
>
> Furthermore, I sometimes like to use subtyping as in:
>
> cartesian <-- vector
> <-- point
>
> which in conjuction with the the curiously recurring pattern (to
inject
> the
> "self" most-derived type into cartesian) can be used to define:
>
> unary -
> binary - + *
>
> right in the base class.
>
> (point-point) needs to be overriden in the point class though.
>
> But of course, as Joel said, these sort of thing (inheritance) is
> unnecesary
> when generic programming is _fully_ used.
> But the inheritance comes in handy in non-generic but parametrized
> contexts
> (where you can parametrize on "cartesian" and pass either points or
> vectors
> without conversion)
>
> Best
>
>
> --
> Fernando Cacciola
> SciSoft
> http://fcacciola.50webs.com
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk