Boost logo

Boost :

From: Barend Gehrels (barend_at_[hidden])
Date: 2008-03-27 15:48:42


> > The distance of two integers may result in a floating point value.
> > Therefore distance returns a double. Internally, you will see, often,
> > the same numeric types or better is used as you describe. See
> > select_type_traits and large_type_traits.
>
> I couldn't find one for the instance of distance, perhaps I wasn't looking properly,
> in any case the simplest definition in my opinion could be:
>
> template<typename point_type>
> point_trait<point_type>::value_type distance(const point_type& p1, const point_type& p2);
>
See also the discussions on the other thread about distance and
"distance_result". It turns out to be very useful to have a variant
which is squared, in some cases, for fast comparisons. But not all
point-types need that.
Besides that the library as is in preview can compare two types.
But all this, indeed, is not "the simplest definition".

> btw will there be support for base value inputs?
>
> template<typename T>
> T distance(const T& x1,const T& y1, const T& y2,const T& x2);
>
Good idea.
> > Points of different types can be handled.
> > If you use a derived class, you have to provide an appropriate traits
> > class. It is not promoted. At least not in the compilers I use.
> All the compilers I use do it quite easily.
>
> class my_rational
> {
> public:
> my_rational(const int& i);
> my_rational& operator=(const int& i);
> };
>
> void foo(my_rational value){...}
> {
> int i = 123;
> foo(i);
> }
>
> as per the example above if I provided a distance strategy/routine
> using my_rational, then I should not need to do anything
> else in order to be able to pass in a series of integers
> into the routine - the result would of course be my_rational
> but the class my also have a few cast operators to convert
> into the various C++ PODs
>

This is not how I use it in the traits class, but I have to check again
if its promoted there. Thought it was not.

> > Besides that, the library user might choose to specify a strategy.
> Thats great, but consider me a really dumb user, I have 4 values
> I've just read in from a file and i want to compute the euclidian
> distance, I would like to be able to say the following without having
> to worry about strategies or converting my values into point types etc:
>
> dist = boost::geometry::distance(x1,y1,x2,y2);
>
The strategy is optional... Dumb users don't have to use them...
But again, offering a calculation of the distance of four coordinates is
a good idea.

> (snip)
>
> There is so much to this topic, you indeed are very courageous to take
> it on.
>
Thanks.

Barend Gehrels,
Geodan, Amsterdam


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