Boost logo

Geometry :

Subject: Re: [geometry] nsphere concept
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2013-05-31 22:33:42

Barend Gehrels wrote:
> On 31-5-2013 23:28, Adam Wulkiewicz wrote:
>> Yes, I saw how nsphere is implemented and accessed. I find it
>> nonintuitive because N-th radius is returned by get_radius<N>() and
>> N-th center point coordinate is returned by get<N>(). Other geometries
>> which contain some points like box or segment uses indexed access,
>> e.g. get<0, N>(). I feel that it would be more suitable for
>> nsphere/ball too.
> I did not look it up when I wrote my previous reply, but apparently the
> original nsphere already has what I suggested...
> OK, to be honest I find a separate function much more intuitive. bg::get
> returns a coordinate. But a radius is not a coordinate. So that is why
> we took a different function there, and it makes sense. It feels strange
> to me to return a coordinate (the center) and a length-measurement (the
> radius) using one function, just by changing the index. And yes, it
> gives problems too for different coordinate type / radius type (these
> should also differ...)
> For box/segment, get is indeed indexed, but in both cases it returns
> real coordinates and not another geometry property.

Yes, as I've written it would require the change of the purpose of the
get<>() function. Now it's the function returning coordinates. After the
change it would be a general-purpose accessor. Returning various types
isn't really a problem, tuple's get<>() does it.

If we had the general get<>() we still would be forced to use different
traits e.g. coordinate_type and radius_type. It would be nice if there
were also a general indexed value_type or access_type trait. By default
defined e.g. like this to ensure backward compatibility:

namespace traits {

template <typename Geometry, size_t I>
struct indexed_access_type
   typedef coordinate_type<Geometry>::type type;


Why should we consider it?

Now get<>() is used to access point/position coordinates. But it may
change soon.

I've already used it to access vector, matrix and quaternion elements,
which aren't position coordinates. Oriented boxes could store center
point and Dim*vectors with coordinates of different type than the point.
Planes and Rays could store a point and a vector. Even if they all used
the same coordinate_types, points would be positions and vectors would
be directions or directions multiplied by lengths.

Regarding nsphere. One-argument get<>() is used to access Geometry's
position coordinate. The same function is used in the case of Nsphere.
In the case of Points it's ok since they have coordinates which can be
indexed. But Nsphere really hasn't coordinates, it may have the center
which has coordinates. Any other point of sphere (or rather ball) may be
good to indicate it's position, the center is probably just the best
one. Using get<>() to access center's coordinates is an elliptical
construction. This however probably just depends on the point of view.

get_radius<>() is ok, it's just redundant.


Geometry list run by mateusz at