This example shows how GGL can be used to adapt a pointer-to-a-point, used e.g. in a linestring
#include <iostream>
#include <boost/foreach.hpp>
struct my_point
{
double x,y;
};
namespace boost { namespace geometry { namespace traits {
template<> struct tag<my_point>
{
typedef point_tag
type; };
template<> struct coordinate_type<my_point>
{ typedef double type; };
template<> struct coordinate_system<my_point>
{ typedef cs::cartesian type; };
template<> struct dimension<my_point> : boost::mpl::int_<2> {};
template<>
struct access<my_point, 0>
{
static double get(my_point const& p)
{
return p.x;
}
static void set(my_point& p,
double const& value)
{
p.x = value;
}
};
template<>
struct access<my_point, 1>
{
static double get(my_point const& p)
{
return p.y;
}
static void set(my_point& p,
double const& value)
{
p.y = value;
}
};
}}}
int main()
{
typedef std::vector<my_point*> ln;
ln myline;
for (float i = 0.0; i < 10.0; i++)
{
my_point* p = new my_point;
p->x = i;
p->y = i + 1;
myline.push_back(p);
}
box_2d cb(point_2d(1.5, 1.5), point_2d(4.5, 4.5));
std::vector<linestring_2d> clipped;
boost::geometry::detail::intersection::clip_range_with_box<linestring_2d>(cb,
BOOST_FOREACH(my_point* p, myline)
{
delete p;
}
return 0;
}