2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __CANVAS_LOOKUP_TABLE_H__
21 #define __CANVAS_LOOKUP_TABLE_H__
24 #include <boost/multi_array.hpp>
26 #include "canvas/visibility.h"
27 #include "canvas/types.h"
29 class OptimizingLookupTableTest;
31 namespace ArdourCanvas {
35 class LIBCANVAS_API LookupTable
38 LookupTable (Item const &);
39 virtual ~LookupTable ();
41 virtual std::vector<Item*> get (Rect const &) = 0;
42 virtual std::vector<Item*> items_at_point (Duple const &) const = 0;
43 virtual bool has_item_at_point (Duple const & point) const = 0;
50 class LIBCANVAS_API DumbLookupTable : public LookupTable
53 DumbLookupTable (Item const &);
55 std::vector<Item*> get (Rect const &);
56 std::vector<Item*> items_at_point (Duple const &) const;
57 bool has_item_at_point (Duple const & point) const;
60 class LIBCANVAS_API OptimizingLookupTable : public LookupTable
63 OptimizingLookupTable (Item const &, int);
64 ~OptimizingLookupTable ();
65 std::vector<Item*> get (Rect const &);
66 std::vector<Item*> items_at_point (Duple const &) const;
67 bool has_item_at_point (Duple const & point) const;
69 static int default_items_per_cell;
73 void area_to_indices (Rect const &, int &, int &, int &, int &) const;
74 void point_to_indices (Duple, int &, int &) const;
76 friend class ::OptimizingLookupTableTest;
78 typedef std::vector<Item*> Cell;