...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Class segment: small class containing two points.
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.
template<typename Point> class model::segment : public std::pair< Point, Point > { // ... };
Parameter |
Description |
---|---|
typename Point |
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: |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/segment.hpp>
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)); segment_t seg3{{0.0, 0.0}, {5.0, 5.0}}; 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