|  | Home | Libraries | People | FAQ | More | 
Calculates the number of segments of a geometry.
The free function num_segments calculates the number of segments of a geometry.
template<typename Geometry> std::size_t num_segments(Geometry const & geometry)
| Type | Concept | Name | Description | 
|---|---|---|---|
| Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept | 
The calculated number of segments
Either
          #include <boost/geometry.hpp>
        
Or
          #include <boost/geometry/algorithms/num_segments.hpp>
        
The function num_segments is not defined by OGC.
| Case | Behavior | 
|---|---|
| pointlike (e.g. point) | Returns 0 | 
| Segment | Returns 1 | 
| Box | Returns d * 2^(d-1), where d is the dimension of the box | 
| Rangelike (linestring, ring) | Returns boost::size(geometry) - 1 | 
| Other geometries | Returns the sum of the number of segments of its elements | 
Constant or Linear
Get the number of segments in a geometry
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> int main() { boost::geometry::model::multi_polygon < boost::geometry::model::polygon < boost::geometry::model::d2::point_xy<double>, true, false // cw, open polygon > > mp; boost::geometry::read_wkt("MULTIPOLYGON(((0 0,0 10,10 0),(1 1,8 1,1 8)),((10 10,10 20,20 10)))", mp); std::cout << "Number of segments: " << boost::geometry::num_segments(mp) << std::endl; return 0; }
Output:
Number of segments: 9