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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
BOOST_GEOMETRY_REGISTER_POINT_2D

Macro to register a 2D point type.

Description

The macro BOOST_GEOMETRY_REGISTER_POINT_2D registers a two-dimensional point type such that it is recognized by Boost.Geometry and that Boost.Geometry functionality can used with the specified type.

Synopsis

#define BOOST_GEOMETRY_REGISTER_POINT_2D(Point, CoordinateType, CoordinateSystem,
                                  Field0, Field1)

Parameters

Name

Description

Point

Point type to be registered

CoordinateType

Type of the coordinates of the point (e.g. double)

CoordinateSystem

Coordinate system (e.g. cs::cartesian)

Field0

Member containing first (usually x) coordinate

Field1

Member containing second (usually y) coordinate

Header

#include <boost/geometry/geometries/register/point.hpp>

[Caution] Caution

Use the macro outside any namespace

[Note] Note

A point can include a namespace

Examples

Show the use of the macro BOOST_GEOMETRY_REGISTER_POINT_2D

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

1
struct legacy_point
{
    double x, y;
};

BOOST_GEOMETRY_REGISTER_POINT_2D(legacy_point, double, cs::cartesian, x, y) 2

int main()
{
    legacy_point p1, p2;

    namespace bg = boost::geometry;

    3
    bg::assign_values(p1, 1, 1);
    bg::assign_values(p2, 2, 2);

    double d = bg::distance(p1, p2);

    std::cout << "Distance: " << d << std::endl;

    return 0;
}

1

Somewhere, any legacy point struct is defined

2

The magic: adapt it to Boost.Geometry Point Concept

3

Any Boost.Geometry function can be used for legacy point now. Here: assign_values and distance

Output:

Distance: 1.41421

PrevUpHomeNext