Boost logo

Boost :

From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-03-25 16:40:17


>
> Herewith the URL to the second preview of Geodan's Geometry Library,
> including documentation and examples.

Hello,

Thanks for this submission, I have compiled and run successfully all the
examples provided, and had a quick look at the documentation and
implementation. What I've seen until now is quite convincing :-)

Here are a few remarks...

* I think a lot of people will most often choose to initialize their points
to 0. Maybe it would be better if the default behavior was init_zero, and to
have an additional "init_none" value in the "init" enum, that could be used
explicitly when needed? If non-init is the default, I'm already afraid about
all the "uninitialized value" bugs that programmers will mistakenly
produce...

* Maybe the parameterized constructor of point should be declared explicit,
since implicitly converting a scalar to a point is likely to be an
unintended error.

* You could take advantage of the "dimension-agnosticness" of your point
concept more than you're currently doing in your algorithms. For example, I
have rewritten the pythagoras algorithm to make it dimension-agnostic, this
way:

template <typename P1, typename P2, size_t I, typename T>
struct compute_pythagoras
{
    static T result(const P1& p1, const P2& p2)
    {
        T d = p2.template value<I-1>() - p1.template value<I-1>();
        return d*d + compute_pythagoras<P1, P2, I-1, T>::result(p1, p2);
    }
};

template <typename P1, typename P2, typename T>
struct compute_pythagoras<P1, P2, 0, T>
{
    static T result(P1, P2)
    { return 0; }
};

template <typename P1, typename P2 = P1>
struct pythagoras
{
        static inline bool squared() { return true; }

        inline distance_result operator()(const P1& p1, const P2& p2) const
        {
            typedef typename select_type_traits<typename
P1::coordinate_type, typename P2::coordinate_type>::type T;

            return distance_result(compute_pythagoras<P1, P2,
P1::coordinate_count, T>::result(p1, p2), true);
        }
};

This way you can use pythagoras either with a point_xy or with other point
classes of higher dimensions. I've quickly made up a point_xyz class and it
worked perfectly after having defined a strategy for it. Every algorithm
doesn't have to be that generic, sometimes it just doesn't make sense. But
for the simplest ones, and if it's not too much effort, I think it's worth
it.

Regards
Bruno


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