I am trying to get familiar with boost::geometry::point. In my class I have a default constructor with no parameters and I want to initialize in this case all point values with zero.
As the set/get functions are templates, the following code part would yield an error at compile time:
for( std::size_t i = 0; i < pnt.size() ; i++ )
{
pnt.set<i>( 0.0 );
}
To refer the documentation http://www.boost.org/doc/libs/1_51_0/libs/geometry/doc/html/geometry/reference/models/model_point.html
I need to set some values because:
Coordinates are not initialized. If the constructor with parameters is not called and points are not assigned using set or assign then the coordinate values will contain garbage.
Is there a way to initialize all values with zero at compile time? If not then at runtime?
You can use
assign_zeroorassign_values(this one only works for 2, 3 and 4 components):If you are using a custom point class you need to register it using one of the
BOOST_GEOMETRY_REGISTER_POINT...in order to be able to use Boost Geometry functionality. You can find several examples here.