Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Boost.Tuple

Boost.Tuple tuples with arithmetic elements can be used as points within Boost.Geometry

Description

Boost.Tuple fixed sized collections, such as boost::tuple<double, double>, are (optionally) adapted to the Boost.Geometry point concept.

Boost.Tuple pairs or triples might have mutually different types, such as a boost::tuple<float, double>. Boost.Geometry reports the first type as its coordinate_type.

Boost.Geometry supports Boost.Tuple pairs, triples, quadruples, etc up to tuples with 10 elements (though most algorithms do not support so many dimensions).

A tuple can be the point type used by the models linestring, polygon, segment, box, and ring

Model of

Point Concept

Header

#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

The standard header boost/geometry.hpp does not include this header.

Example

Shows how to use Boost.Tuple points in Boost.Geometry

Working with Boost.Tuples in Boost.Geometry is straightforward and shown in various other examples as well.

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

int main()
{
    boost::geometry::model::polygon<boost::tuple<double, double> > poly;
    poly.outer().push_back(boost::make_tuple(1.0, 2.0));
    poly.outer().push_back(boost::make_tuple(6.0, 4.0));
    poly.outer().push_back(boost::make_tuple(5.0, 1.0));
    poly.outer().push_back(boost::make_tuple(1.0, 2.0));

    std::cout << "Area: " << boost::geometry::area(poly) << std::endl;
    std::cout << "Contains (1.5, 2.5): "
        << std::boolalpha
        << boost::geometry::within(boost::make_tuple(1.5, 2.5), poly)
        << std::endl;

    return 0;
}

Output:

Area: 6.5
Contains (1.5, 2.5): false

PrevUpHomeNext