Boost logo

Geometry :

Subject: Re: [geometry] How far should I expect to get with points that are "values"?
From: Barend Gehrels (barend_at_[hidden])
Date: 2014-07-16 03:09:23


Hi Patrick,

Patrick J. LoPresti wrote On 16-7-2014 3:21:
> I usually like value semantics, especially for tiny classes like
> points. So I do not provide the ability to set the components of my
> point objects.
>
> What parts of Boost.Geometry should I expect to work and not to work
> for me? For example, this code fails to compile:
>
>
> #include <boost/geometry.hpp>
> #include <boost/geometry/geometries/register/point.hpp>
>
> struct MyPoint {
> int x,y;
> };
>
> BOOST_GEOMETRY_REGISTER_POINT_2D_CONST(MyPoint, int, cs::cartesian, x, y);
>
> namespace bg = boost::geometry;
>
> MyPoint make(int x, int y)
> {
> return bg::make<MyPoint>(1, 2);
> }
>
>
> If I use the "BOOST_GEOMETRY_REGISTER_POINT_2D" version (without the
> CONST), it works fine... But that is not an option for my actual class
> where I have no setters for the components.

Why is this not an option? You don't to have setters or getters. If you
use this macro without the const, it just creates traits to get and set
x,y directly.

The _CONST suffix means that the set part of the traits is not
implemented. But Boost.Geometry can therefore not create any point then.

> In particular, will a bg::index::rtree, holding rectangles and using
> rectangle queries, work OK? (I notice that "intersects()" works for my
> boxes but "intersection()" does not...)
>
> Of course, I can add setters to my points if necessary.
>

No, that is not necessary. It should work fine like this.

Regards, Barend


Geometry list run by mateusz at loskot.net