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
make (2 coordinate values)

Construct a geometry.

Synopsis

template<typename Geometry, typename Type, std::enable_if_t<! traits::make< Geometry >::is_specialized, int >>
Geometry make(Type const & c1, Type const & c2)

Parameters

Type

Concept

Name

Description

Geometry

Any type fulfilling a Geometry Concept

-

Must be specified

std::enable_if_t<! traits::make< Geometry >::is_specialized, int >

-

Must be specified

Type const &

numerical type (int, double, ttmath, ...) to specify the coordinates

c1

First coordinate (usually x-coordinate)

Type const &

numerical type (int, double, ttmath, ...) to specify the coordinates

c2

Second coordinate (usually y-coordinate)

Returns

The constructed geometry, here: a 2D point

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/make.hpp>

Example

Shows the usage of make as a generic constructor for different point types

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp>

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

struct mypoint { float _x, _y; };

BOOST_GEOMETRY_REGISTER_POINT_2D(mypoint, float, cs::cartesian, _x, _y)

template <typename Point>
void construct_and_display()
{
    using boost::geometry::make;
    using boost::geometry::get;

    Point p = make<Point>(1, 2);

    std::cout << "x=" << get<0>(p) << " y=" << get<1>(p)
        << " (" << typeid(Point).name() << ")"
        << std::endl;
}

int main()
{
    construct_and_display<boost::geometry::model::d2::point_xy<double> >();
    construct_and_display<boost::geometry::model::d2::point_xy<int> >();
    construct_and_display<boost::tuple<double, double> >();
    construct_and_display<boost::polygon::point_data<int> >();
    construct_and_display<mypoint>();
    return 0;
}

Output (compiled using gcc):

x=1 y=2 (N5boost8geometry5model2d28point_xyIdNS0_2cs9cartesianEEE)
x=1 y=2 (N5boost8geometry5model2d28point_xyIiNS0_2cs9cartesianEEE)
x=1 y=2 (N5boost6tuples5tupleIddNS0_9null_typeES2_S2_S2_S2_S2_S2_S2_EE)
x=1 y=2 (N5boost7polygon10point_dataIiEE)
x=1 y=2 (7mypoint)
See also

PrevUpHomeNext