Boost logo

Boost :

From: John Femiani (JOHN.FEMIANI_at_[hidden])
Date: 2008-05-02 00:04:48

> Please feel free to critique the code. I want to make sure
> I've got everything right before I rewrite the library.

I am a boost user who would be interested in a geometry lib.
I only had a chance to glance at the code & thread, but I like the idea
of wrapping a generic type in order to create an adapted point type.
This way one can reuse, say, an array of float and still use the type
system to keep vectors and points separate. I DO think that when I am
writing code that needs points I dont want to depend on the fact that a
wrapper was used. I would rather have concepts for the wrapper's
interface, including the member, free functions, and metafunctions that
must be available.

but I have to say that compile time indexing is useful for more than
just performance, it is also good for genericity. If I have a struct,
for instance, I can not (safely) index the coordinates. If I have an
encapsulated class, I definately can not. Wouldn't it be possible to
use a _different_ type for each orientation, and provide multiple
overloads to the get/set functions? For example:

struct some_legacy_point {
        double x_;
        double z_;
        string something_else_;
        double y_; //Dont ask why it is in this order, its legacy,

typedef boost::mpl::int_<0> X;
typedef boost::mpl::int_<1> Y;

//Just provides access to xy
class adapted_point_reference {
        some_legacy_point& base_; //This is a reference, it is not
        //Construct as a reference
      adapted_point_reference(some_legacy_point & base) : base_(base) {}

        //CopyConstructable (refers to same some_legacy_point)
        adapted_point_reference(adapted_point_xy & other) :
base_(other._base) {}
        //I image these are part of AffinePointConcept or something
        typedef double coordinate ;
         coordinate get(X const&) {return base_.x_;}
        coordinate get(Y const&) {return base_.y_;}

        //I imagine these are part of MutableAffinePointConcept or
        coordinate put(X const&, double value) {base_.x_ = value;}
        coordinate put(Y const&, double value) {base_.y_ = value;}

I think the same approach would work if some_legacy_point keeps
coordinates in an array.

-- John Femiani

Boost list run by bdawes at, gregod at, cpdaniel at, john at