PageRenderTime 35ms CodeModel.GetById 16ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/example/c02_custom_box_example.cpp

http://hadesmem.googlecode.com/
C++ | 78 lines | 55 code | 14 blank | 9 comment | 0 complexity | 7bdf5faa3222c2482e71d53b0bb87e13 MD5 | raw file
 1// Boost.Geometry (aka GGL, Generic Geometry Library)
 2
 3// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
 4// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
 5// Copyright (c) 2009-2011 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/util/write_dsv.hpp>
21
22struct my_point
23{
24    double x, y;
25};
26
27struct my_int_point
28{
29    int x, y;
30};
31
32struct my_box
33{
34    my_point ll, ur;
35};
36
37struct my_box_ltrb
38{
39    int left, top, right, bottom;
40};
41
42struct my_box_4
43{
44    double coors[4];
45};
46
47template <typename P>
48struct my_box_t
49{
50    P ll, ur;
51};
52
53BOOST_GEOMETRY_REGISTER_POINT_2D(my_point, double, cs::cartesian, x, y)
54BOOST_GEOMETRY_REGISTER_POINT_2D(my_int_point, int, cs::cartesian, x, y)
55BOOST_GEOMETRY_REGISTER_BOX(my_box, my_point, ll, ur)
56BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED(my_box_t, ll, ur)
57BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_ltrb, my_int_point, left, top, right, bottom)
58BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_4, my_point, coors[0], coors[1], coors[2], coors[3])
59
60int 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}