| Home | Libraries | People | FAQ | More

#### model::segment

Class segment: small class containing two points.

###### Description

From Wikipedia: In geometry, a line segment is a part of a line that is bounded by two distinct end points, and contains every point on the line between its end points.

###### Model of

Segment Concept

###### Synopsis

    template<typename Point>
    class model::segment
    {
      // ...
    };

###### Template parameter(s)

Parameter | Description
--- | ---
typename Point |

###### Constructor(s)

Function | Description | Parameters
--- | --- | ---

    segment()

Default constructor, no initialization.

    segment(Point const & p1, Point const & p2)

Constructor taking the first and the second point.

Point const &: p1:

Point const &: p2:

###### Header

Either

`#include <boost/geometry/geometries/geometries.hpp>`

Or

`#include <boost/geometry/geometries/segment.hpp>`

###### Examples

Declaration and use of the Boost.Geometry model::segment, modelling the Segment Concept

    #include <iostream>
    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/geometries.hpp>

    namespace bg = boost::geometry;

    int main()
    {
        typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
        typedef bg::model::segment<point_t> segment_t;

        segment_t seg1;
        segment_t seg2(point_t(0.0, 0.0), point_t(5.0, 5.0));

    #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX

        segment_t seg3{{0.0, 0.0}, {5.0, 5.0}};

    #endif

        bg::set<0, 0>(seg1, 1.0);
        bg::set<0, 1>(seg1, 2.0);
        bg::set<1, 0>(seg1, 3.0);
        bg::set<1, 1>(seg1, 4.0);

        double x0 = bg::get<0, 0>(seg1);
        double y0 = bg::get<0, 1>(seg1);
        double x1 = bg::get<1, 0>(seg1);
        double y1 = bg::get<1, 1>(seg1);

        std::cout << x0 << ", " << y0 << ", " << x1 << ", " << y1 << std::endl;

        return 0;
    }

| Default-construct a segment.
| Construct, assigning the first and the second point.
| Construct, using C++11 unified initialization syntax.
| Set a coordinate.
| Get a coordinate.

Output:

    1, 2, 3, 4