Boost logo

Geometry :

Subject: Re: [geometry] Geometries represented in multiple point types
From: Barend Gehrels (barend_at_[hidden])
Date: 2013-01-30 12:47:31


Hi Andrew,

Welcome to the list.

On 30-1-2013 0:48, Andrew Hundt wrote:
> I am dealing with a box type that is specified in multiple coordinate
> systems because it is translating from vector to raster. One point
> type is integer based for the location in an image (cartesian), and
> the other is a point defined with doubles, also a cartesian system.

Interesting.

> I initially tried to define the coordinates by defining tags
> inheriting from the point_type tag assuming that tag_cast would be
> applied, keeping all existing geometry calls functional as follows:
>
> struct grid_point_tag : boost::geometry::point_tag {};
> struct world_point_tag : boost::geometry::point_tag {};
>
> However, this turned out not to be the case as nearly all uses of
> point_tag don't use tag_cast. Alternatively I can define an entirely
> new tag system for these points and use that. While it would work
> around the problem I don't feel like it is the best way to solve it.
> If there are any ideas they would be greatly appreciated.

Yes, the tag_cast was designed for other purposes (though I agree it
could be used wider), so for point_tag it is not used. It might probably
be done if it enables new possibilities.

Actually I don't see yet how it would solve your problem. The point_type
defined by your box should be sometimes one point_type, sometimes
another point_type? That is not solved out of the box. So basically you
already have (for the library) two box types available, if I see it right.

One of the options (I did that recently for one of my projects) is
creating two different wrapper classes with different traits
registrations. You then have effectively two types.

So you could create a class BoxInGrid (and implement all the traits)
and a class BoxInWorld (also implements all the traits but defining
another point type)

These classes could take a (either const or not const) reference to your
box such that it stays as light-weight as possible (but admitted, still
a wrapper).

Alternatively (probably better) you could of course use only one
wrapper, and implement traits for the original too. Then also you have
two different box types.

Hope this helps.

Regards, Barend


Geometry list run by mateusz at loskot.net