cankosa
cankosa

Reputation: 43

Using boost geometry with dimension specified at runtime

The boost::geometry::model::point takes as a compile-time argument the dimension of the point. For instance,

typedef bg::model::point<float, 2, bg::cs::cartesian> point;

Is there any way of specifying the dimension at run time, say, depending on input given to program?

My goal is to use the rtree data structure in boost::geometry::index with arbitrary dimensions. Is it possible to write a custom point class with this feature, or would the type system prevent me from doing this?

Upvotes: 3

Views: 453

Answers (2)

tahsin kose
tahsin kose

Reputation: 1

I'm not sure why the answer "not possible" is accepted to this question. The question simply asks whether this is possible or not, rather than it is performant or mediocre. I'm currently using rtree data structure of boost::geometry supporting [1-6] dimensions as an internal container in my classes.

template <typename T, std::size_t N>
using BoostHyperPoint = bg::model::point<T, N, bg::cs::cartesian>;

You can almost trivially define such a templated point as in the above. With a little more effort, you can have a generic rtree class.

Upvotes: 0

sehe
sehe

Reputation: 393114

There is no way, facilitated by the library.

You can always employ your own type erasure. This will take some effort, and depending on how it's executed, possibly some performance.

That's actually also the reason this doesn't "jell" with the library design. The library focuses strongly on performance through genericity.

Contrary to what you expect this does not support runtime polymorphism, because that would hamper performance. Instead, strictly compiletime polymorphism is used. The compiler can inline and "see through" all the code paths to generate optimal code.

Upvotes: 1

Related Questions