c02_custom_box_example.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // Custom Box Example
  10. #include <iostream>
  11. #include <boost/geometry/algorithms/make.hpp>
  12. #include <boost/geometry/algorithms/within.hpp>
  13. #include <boost/geometry/geometries/register/point.hpp>
  14. #include <boost/geometry/geometries/register/box.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include <boost/geometry/io/dsv/write.hpp>
  17. struct my_point
  18. {
  19. double x, y;
  20. };
  21. struct my_int_point
  22. {
  23. int x, y;
  24. };
  25. struct my_box
  26. {
  27. my_point ll, ur;
  28. };
  29. struct my_box_ltrb
  30. {
  31. int left, top, right, bottom;
  32. };
  33. struct my_box_4
  34. {
  35. double coors[4];
  36. };
  37. template <typename P>
  38. struct my_box_t
  39. {
  40. P ll, ur;
  41. };
  42. BOOST_GEOMETRY_REGISTER_POINT_2D(my_point, double, cs::cartesian, x, y)
  43. BOOST_GEOMETRY_REGISTER_POINT_2D(my_int_point, int, cs::cartesian, x, y)
  44. BOOST_GEOMETRY_REGISTER_BOX(my_box, my_point, ll, ur)
  45. BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED(my_box_t, ll, ur)
  46. BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_ltrb, my_int_point, left, top, right, bottom)
  47. BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_4, my_point, coors[0], coors[1], coors[2], coors[3])
  48. int main()
  49. {
  50. my_point p = boost::geometry::make<my_point>(3.5, 3.5);
  51. my_box b = boost::geometry::make<my_box>(0, 0, 2, 2);
  52. my_box_ltrb b1 = boost::geometry::make<my_box_ltrb>(0, 0, 3, 3);
  53. my_box_4 b4 = boost::geometry::make<my_box_4>(0, 0, 4, 4);
  54. my_box_t<my_point> bt = boost::geometry::make<my_box_t<my_point> >(0, 0, 5, 5);
  55. std::cout << boost::geometry::dsv(p) << " IN " << boost::geometry::dsv(b)
  56. << " : " << int(boost::geometry::within(p, b)) << std::endl;
  57. std::cout << boost::geometry::dsv(p) << " IN " << boost::geometry::dsv(b1)
  58. << " : " << int(boost::geometry::within(p, b1)) << std::endl;
  59. std::cout << boost::geometry::dsv(p) << " IN " << boost::geometry::dsv(b4)
  60. << " : " << int(boost::geometry::within(p, b4)) << std::endl;
  61. std::cout << boost::geometry::dsv(p) << " IN " << boost::geometry::dsv(bt)
  62. << " : " << int(boost::geometry::within(p, bt)) << std::endl;
  63. return 0;
  64. }