This sample demonstrates that custom points can be made as well. This sample contains many points, derived from boost::tuple, created from scratch, read only points, legacy points, etc.
#include <iostream>
#include <boost/geometry/io/dsv/write.hpp>
struct my_color_point
{
double red, green, blue;
};
struct my_array_point
{
int c[3];
};
struct my_2d
{
float x,y;
};
class my_class_ro
{
public:
my_class_ro(double x, double y) : m_x(x), m_y(y) {}
double x() const { return m_x; }
double y() const { return m_y; }
private:
double m_x, m_y;
};
class my_class_rw
{
public:
const double& x() const { return m_x; }
const double& y() const { return m_y; }
double& x() { return m_x; }
double& y() { return m_y; }
private:
double m_x, m_y;
};
class my_class_gs
{
public:
const double get_x() const { return m_x; }
const double get_y() const { return m_y; }
void set_x(double v) { m_x = v; }
void set_y(double v) { m_y = v; }
private:
double m_x, m_y;
};
namespace my
{
struct my_namespaced_point
{
double x, y;
};
}
int main()
{
my_color_point c1 = boost::geometry::make<my_color_point>(255, 3, 233);
my_color_point c2 = boost::geometry::make<my_color_point>(0, 50, 200);
std::cout << "color distance "
<< boost::geometry::dsv(c1) << " to "
<< boost::geometry::dsv(c2) << " is "
my_array_point a1 = {{0}};
my_array_point a2 = {{0}};
std::cout << "color distance "
<< boost::geometry::dsv(a1) << " to "
<< boost::geometry::dsv(a2) << " is "
my_2d p1 = {1, 5};
my_2d p2 = {3, 4};
std::cout << "float distance "
<< boost::geometry::dsv(p1) << " to "
<< boost::geometry::dsv(p2) << " is "
my_class_ro cro1(1, 2);
my_class_ro cro2(3, 4);
std::cout << "class ro distance "
<< boost::geometry::dsv(cro1) << " to "
<< boost::geometry::dsv(cro2) << " is "
my_class_rw crw1;
my_class_rw crw2;
std::cout << "class r/w distance "
<< boost::geometry::dsv(crw1) << " to "
<< boost::geometry::dsv(crw2) << " is "
my_class_gs cgs1;
my_class_gs cgs2;
std::cout << "class g/s distance "
<< boost::geometry::dsv(crw1) << " to "
<< boost::geometry::dsv(crw2) << " is "
my::my_namespaced_point nsp1 = boost::geometry::make<my::my_namespaced_point>(1, 2);
my::my_namespaced_point nsp2 = boost::geometry::make<my::my_namespaced_point>(3, 4);
std::cout << "namespaced distance "
<< boost::geometry::dsv(nsp1) << " to "
<< boost::geometry::dsv(nsp2) << " is "
return 0;
}