...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Basic point class, having coordinates defined in a neutral way.
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.
template<typename CoordinateType, std::size_t DimensionCount, typename CoordinateSystem> class model::point { // ... };
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 |
Function |
Description |
Parameters |
---|---|---|
point()
|
Default constructor, no initialization. |
|
template<typename C, std::enable_if_t< geometry::detail::is_coordinates_number_leq< C, 1, DimensionCount >::value, int >> point(CoordinateType const & v0)
|
Constructor to set one value. |
CoordinateType const &: v0: |
template<typename C, std::enable_if_t< geometry::detail::is_coordinates_number_leq< C, 2, DimensionCount >::value, int >> point(CoordinateType const & v0, CoordinateType const & v1)
|
Constructor to set two values. |
CoordinateType const &: v0: CoordinateType const &: v1: |
template<typename C, std::enable_if_t< geometry::detail::is_coordinates_number_leq< C, 3, DimensionCount >::value, int >> point(CoordinateType const & v0, CoordinateType const & v1, CoordinateType const & v2)
|
Constructor to set three values. |
CoordinateType const &: v0: CoordinateType const &: v1: CoordinateType const &: v2: |
Function |
Description |
Parameters |
Returns |
---|---|---|---|
template<std::size_t K> constexpr 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 |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/point.hpp>
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); bg::set<0>(point1, 1.0); point1.set<1>(2.0); double x = bg::get<0>(point1); double y = point1.get<1>(); std::cout << x << ", " << y << std::endl; return 0; }
Construct, assigning three coordinates |
|
Set a coordinate, generic. |
|
Set a coordinate, class-specific (Note:
prefer |
|
Get a coordinate, generic. |
|
Get a coordinate, class-specific (Note:
prefer |
Output:
1, 2
Note | |
---|---|
Coordinates are not initialized. If the constructor with parameters is
not called and points are not assigned using |