...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
2D point in Cartesian coordinate system
template<typename CoordinateType, typename CoordinateSystem> class model::d2::point_xy : public model::point< CoordinateType, 2, cs::cartesian > { // ... };
Parameter |
Default |
Description |
---|---|---|
typename CoordinateType |
numeric type, for example, double, float, int |
|
typename CoordinateSystem |
cs::cartesian |
coordinate system, defaults to cs::cartesian |
Function |
Description |
Parameters |
---|---|---|
point_xy()
|
Default constructor, no initialization. |
|
point_xy(CoordinateType const & x, CoordinateType const & y)
|
Constructor with x/y values. |
CoordinateType const &: x: CoordinateType const &: y: |
Function |
Description |
Parameters |
Returns |
---|---|---|---|
constexpr CoordinateType const & x()
|
Get x-value. |
||
constexpr CoordinateType const & y()
|
Get y-value. |
||
void x(CoordinateType const & v)
|
Set x-value. |
CoordinateType const &: v: |
|
void y(CoordinateType const & v)
|
Set y-value. |
CoordinateType const &: v: |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/point_xy.hpp>
Declaration and use of the Boost.Geometry model::d2::point_xy, modelling the Point Concept
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> namespace bg = boost::geometry; int main() { bg::model::d2::point_xy<double> point1; bg::model::d2::point_xy<double> point2(1.0, 2.0); bg::set<0>(point1, 1.0); point1.y(2.0); double x = bg::get<0>(point1); double y = point1.y(); std::cout << x << ", " << y << std::endl; return 0; }
Construct, assigning 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 |