mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 05:24:02 +00:00
[geometry] changes in examples w.r.t. custom pointer types
[SVN r79370]
This commit is contained in:
parent
8f67363fa8
commit
c506c476dd
@ -35,42 +35,42 @@ struct my_point
|
|||||||
|
|
||||||
namespace boost { namespace geometry { namespace traits {
|
namespace boost { namespace geometry { namespace traits {
|
||||||
|
|
||||||
template<> struct tag<my_point*>
|
template<> struct tag<my_point>
|
||||||
{ typedef point_tag type; };
|
{ typedef point_tag type; };
|
||||||
|
|
||||||
template<> struct coordinate_type<my_point*>
|
template<> struct coordinate_type<my_point>
|
||||||
{ typedef double type; };
|
{ typedef double type; };
|
||||||
|
|
||||||
template<> struct coordinate_system<my_point*>
|
template<> struct coordinate_system<my_point>
|
||||||
{ typedef cs::cartesian type; };
|
{ typedef cs::cartesian type; };
|
||||||
|
|
||||||
template<> struct dimension<my_point*> : boost::mpl::int_<2> {};
|
template<> struct dimension<my_point> : boost::mpl::int_<2> {};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct access<my_point*, 0>
|
struct access<my_point, 0>
|
||||||
{
|
{
|
||||||
static double get(my_point const* p)
|
static double get(my_point const& p)
|
||||||
{
|
{
|
||||||
return p->x;
|
return p.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(my_point* p, double const& value)
|
static void set(my_point& p, double const& value)
|
||||||
{
|
{
|
||||||
p->x = value;
|
p.x = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct access<my_point*, 1>
|
struct access<my_point, 1>
|
||||||
{
|
{
|
||||||
static double get(my_point const* p)
|
static double get(my_point const& p)
|
||||||
{
|
{
|
||||||
return p->y;
|
return p.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(my_point* p, double const& value)
|
static void set(my_point& p, double const& value)
|
||||||
{
|
{
|
||||||
p->y = value;
|
p.y = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include <boost/geometry/geometry.hpp>
|
#include <boost/geometry.hpp>
|
||||||
|
#include <boost/geometry/geometries/geometries.hpp>
|
||||||
|
#include <boost/geometry/geometries/point_xy.hpp>
|
||||||
#include <boost/geometry/geometries/register/ring.hpp>
|
#include <boost/geometry/geometries/register/ring.hpp>
|
||||||
|
|
||||||
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(std::vector)
|
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(std::vector)
|
||||||
@ -32,42 +34,42 @@ struct my_point
|
|||||||
|
|
||||||
namespace boost { namespace geometry { namespace traits {
|
namespace boost { namespace geometry { namespace traits {
|
||||||
|
|
||||||
template<> struct tag<my_point*>
|
template<> struct tag<my_point>
|
||||||
{ typedef point_tag type; };
|
{ typedef point_tag type; };
|
||||||
|
|
||||||
template<> struct coordinate_type<my_point*>
|
template<> struct coordinate_type<my_point>
|
||||||
{ typedef double type; };
|
{ typedef double type; };
|
||||||
|
|
||||||
template<> struct coordinate_system<my_point*>
|
template<> struct coordinate_system<my_point>
|
||||||
{ typedef cs::cartesian type; };
|
{ typedef cs::cartesian type; };
|
||||||
|
|
||||||
template<> struct dimension<my_point*> : boost::mpl::int_<2> {};
|
template<> struct dimension<my_point> : boost::mpl::int_<2> {};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct access<my_point*, 0>
|
struct access<my_point, 0>
|
||||||
{
|
{
|
||||||
static double get(my_point const* p)
|
static double get(my_point const& p)
|
||||||
{
|
{
|
||||||
return p->x;
|
return p.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(my_point* p, double const& value)
|
static void set(my_point& p, double const& value)
|
||||||
{
|
{
|
||||||
p->x = value;
|
p.x = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct access<my_point*, 1>
|
struct access<my_point, 1>
|
||||||
{
|
{
|
||||||
static double get(my_point const* p)
|
static double get(my_point const& p)
|
||||||
{
|
{
|
||||||
return p->y;
|
return p.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(my_point* p, double const& value)
|
static void set(my_point& p, double const& value)
|
||||||
{
|
{
|
||||||
p->y = value;
|
p.y = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,30 +103,33 @@ int main()
|
|||||||
//std::vector<ring_type> unioned;
|
//std::vector<ring_type> unioned;
|
||||||
//boost::geometry::union<ring_type>(a, b, unioned);
|
//boost::geometry::union<ring_type>(a, b, unioned);
|
||||||
|
|
||||||
/* This once worked, using pointers, but has to be fixed or deprecated
|
// BEGIN TODO
|
||||||
typedef boost::geometry::model::ring<boost::geometry::model::d2::point_xy<double> > ring_2d;
|
// This compiles (and once worked) using pointers, but has to be fixed or deprecated
|
||||||
std::vector<ring_2d> unioned;
|
// The problem is now the cart_intersect/side where a temporary point is generated
|
||||||
std::vector<ring_2d> intersected;
|
//typedef boost::geometry::model::ring<boost::geometry::model::d2::point_xy<double> > ring_2d;
|
||||||
|
//std::vector<ring_2d> unioned;
|
||||||
|
//std::vector<ring_2d> intersected;
|
||||||
|
|
||||||
boost::geometry::intersection(a, b, intersected);
|
//boost::geometry::intersection(a, b, intersected);
|
||||||
boost::geometry::union_(a, b, unioned);
|
//boost::geometry::union_(a, b, unioned);
|
||||||
|
|
||||||
double ai = 0, au = 0;
|
//double ai = 0, au = 0;
|
||||||
BOOST_FOREACH(ring_2d const& ring, intersected)
|
//BOOST_FOREACH(ring_2d const& ring, intersected)
|
||||||
{
|
//{
|
||||||
ai += boost::geometry::area(ring);
|
// ai += boost::geometry::area(ring);
|
||||||
}
|
//}
|
||||||
BOOST_FOREACH(ring_2d const& ring, unioned)
|
//BOOST_FOREACH(ring_2d const& ring, unioned)
|
||||||
{
|
//{
|
||||||
au += boost::geometry::area(ring);
|
// au += boost::geometry::area(ring);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
//std::cout << "a: " << aa << std::endl;
|
||||||
|
//std::cout << "b: " << ab << std::endl;
|
||||||
|
//std::cout << "a & b: " << ai << std::endl;
|
||||||
|
//std::cout << "a | b: " << au << std::endl;
|
||||||
|
//std::cout << "a + b - (a & b): " << (aa + ab - ai) << std::endl;
|
||||||
|
// END TODO
|
||||||
|
|
||||||
std::cout << "a: " << aa << std::endl;
|
|
||||||
std::cout << "b: " << ab << std::endl;
|
|
||||||
std::cout << "a & b: " << ai << std::endl;
|
|
||||||
std::cout << "a | b: " << au << std::endl;
|
|
||||||
std::cout << "a + b - (a & b): " << (aa + ab - ai) << std::endl;
|
|
||||||
*/
|
|
||||||
|
|
||||||
// free
|
// free
|
||||||
BOOST_FOREACH(my_point* p, a)
|
BOOST_FOREACH(my_point* p, a)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user