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