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

model::point

Basic point class, having coordinates defined in a neutral way.

Description

Defines a neutral point class, fulfilling the Point Concept. Library users can use this point class, or use their own point classes. This point class is used in most of the samples and tests of Boost.Geometry This point class is used occasionally within the library, where a temporary point class is necessary.

Model of

Point Concept

Synopsis

template<typename CoordinateType, std::size_t DimensionCount, typename CoordinateSystem>
class model::point
{
  // ...
};

Template parameter(s)

Parameter

Description

typename CoordinateType

numerical type (int, double, ttmath, ...)

std::size_t DimensionCount

number of coordinates, usually 2 or 3

typename CoordinateSystem

coordinate system, for example cs::cartesian

Constructor(s)

Function

Description

Parameters

point()

Default constructor, no initialization.

point(CoordinateType const & v0)

Constructor to set one value.

CoordinateType const &: v0:

point(CoordinateType const & v0, CoordinateType const & v1)

Constructor to set two values.

CoordinateType const &: v0:

CoordinateType const &: v1:

point(CoordinateType const & v0, CoordinateType const & v1, CoordinateType const & v2)

Constructor to set three values.

CoordinateType const &: v0:

CoordinateType const &: v1:

CoordinateType const &: v2:

Member Function(s)

Function

Description

Parameters

Returns

template<std::size_t K>
CoordinateType const & get()

Get a coordinate.

the coordinate

template<std::size_t K>
void set(CoordinateType const & value)

Set a coordinate.

CoordinateType const &: value: value to set

Header

Either

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

Or

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

Examples

Declaration and use of the Boost.Geometry model::point, modelling the Point Concept

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

namespace bg = boost::geometry;

int main()
{
    bg::model::point<double, 2, bg::cs::cartesian> point1;
    bg::model::point<double, 3, bg::cs::cartesian> point2(1.0, 2.0, 3.0); 1

    bg::set<0>(point1, 1.0); 2
    point1.set<1>(2.0); 3

    double x = bg::get<0>(point1); 4
    double y = point1.get<1>(); 5

    std::cout << x << ", " << y << std::endl;
    return 0;
}

1

Construct, assigning three coordinates

2

Set a coordinate, generic.

3

Set a coordinate, class-specific (Note: prefer bg::set()).

4

Get a coordinate, generic.

5

Get a coordinate, class-specific (Note: prefer bg::get()).

Output:

1, 2
Notes
[Note] Note

Coordinates are not initialized. If the constructor with parameters is not called and points are not assigned using set or assign then the coordinate values will contain garbage


PrevUpHomeNext