Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / 2geom / quadtree.h
1 /**
2  * \file
3  * \brief  \todo brief description
4  *
5  * Authors:
6  *      ? <?@?.?>
7  * 
8  * Copyright ?-?  authors
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it either under the terms of the GNU Lesser General Public
12  * License version 2.1 as published by the Free Software Foundation
13  * (the "LGPL") or, at your option, under the terms of the Mozilla
14  * Public License Version 1.1 (the "MPL"). If you do not alter this
15  * notice, a recipient may use your version of this file under either
16  * the MPL or the LGPL.
17  *
18  * You should have received a copy of the LGPL along with this library
19  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  * You should have received a copy of the MPL along with this library
22  * in the file COPYING-MPL-1.1
23  *
24  * The contents of this file are subject to the Mozilla Public License
25  * Version 1.1 (the "License"); you may not use this file except in
26  * compliance with the License. You may obtain a copy of the License at
27  * http://www.mozilla.org/MPL/
28  *
29  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31  * the specific language governing rights and limitations.
32  *
33  */
35 #include <vector>
36 #include <cassert>
38 #include <2geom/d2.h>
40 namespace Geom{
42 class Quad{
43 public:
44     Quad* children[4];
45     std::vector<int> data;
46     Quad() {
47         for(int i = 0; i < 4; i++)
48             children[i] = 0;
49     }
50     typedef std::vector<int>::iterator iterator;
51     Rect bounds(unsigned i, double x, double y, double d) {
52         double dd = d/2;
53         switch(i % 4) {
54             case 0:
55                 return Rect(Interval(x, x+dd), Interval(y, y+dd));
56             case 1:
57                 return Rect(Interval(x+dd, x+d), Interval(y, y+dd));
58             case 2:
59                 return Rect(Interval(x, x+dd), Interval(y+dd, y+d));
60             case 3:
61                 return Rect(Interval(x+dd, x+d), Interval(y+dd, y+d));
62             default: 
63                 /* just to suppress warning message
64                  * this case should be never reached */
65                 assert(false);
66         }        
67     }
68 };
70 class QuadTree{
71 public:
72     Quad* root;
73     double scale;
74     double bx0, bx1;
75     double by0, by1;
77     QuadTree() : root(0), scale(1) {}
79     Quad* search(double x0, double y0, double x1, double y1);
80     void insert(double x0, double y0, double x1, double y1, int shape);
81     Quad* search(Geom::Rect const &r);
82     void insert(Geom::Rect const &r, int shape);
83     void erase(Quad *q, int shape);
84 private:
85     bool clean_root();
86 };
88 };
90 /*
91   Local Variables:
92   mode:c++
93   c-file-style:"stroustrup"
94   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95   indent-tabs-mode:nil
96   fill-column:99
97   End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :