Problem: boost/geometry/geometries/point.hpp point template does not provide a way to construct an n-dimensional point type with non-zero values.
For example:
#include <boost/geometry/geometries/point.hpp>
namespace bg = boost::geometry;
...
typedef bg::model::point<double,4,bg::cs::cartesian> point;
auto nDimPoint1 = point(); // creates a point with 4 values each 0
auto nDimPoint2 = point(1,2,3,4); // !!!compiler error!!! since point's template does not provide a strategy past 3 dimensions.
// workaround, but must be hard-coded
nDimPoint1.set<0>(1);
nDimPoint1.set<1>(2);
nDimPoint1.set<2>(3);
nDimPoint1.set<3>(4);
What I've tried: After reading through boost's documentation I was not able to find any examples with n-dimensional points, though it is possible I missed them.
I did encounter creating custom point classes and registering them, but the built in point class accomplishes exactly what I want. Unfortunately I can't solve this by inheriting from the base point since the point representation is a private variable.
Point's template contains a private array variable, m_values
, by creating a new constructor which takes a vector and copying the vector into m_values
I was able to fix the issue.
I'm also pretty new to C++'s templates, since I usually use C and python. Is it possible to extend the Point template outside the Point.hpp file to include the n-dimensional constructor I want? Or is there a better way of building n-dimensional points in boost such as cast from vector?
Ideally (imho) boost would provide a generic copy constructor which accepts std::vector and copies each value into its internal array.
Related questions: In this question Defining a dimensional point in Boost.Geometry, the author is attempting to utilize point for rtree (I am also attempting to do this), however the accepted answer claims this is not possible and a second solution https://stackoverflow.com/a/62777496/10448495, claims to solve the issue, but I don't see how it can work.