| Home | Libraries | People | FAQ | More

#### num_segments

Calculates the number of segments of a geometry.

###### Description

The free function num_segments calculates the number of segments of a geometry.

###### Synopsis

    template<typename Geometry>
    std::size_t num_segments(Geometry const & geometry)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept

###### Returns

The calculated number of segments

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/num_segments.hpp>`

###### Conformance

The function num_segments is not defined by OGC.

###### Behavior

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

###### Complexity

Constant or Linear

###### Examples

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