summaryrefslogtreecommitdiff
path: root/libs/canvas/canvas/lookup_table.h
blob: 18b357f657bc55d2c59fdb88e1577e1a9f711e97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
 * Copyright (C) 2013-2015 Paul Davis <paul@linuxaudiosystems.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __CANVAS_LOOKUP_TABLE_H__
#define __CANVAS_LOOKUP_TABLE_H__

#include <vector>
#include <boost/multi_array.hpp>

#include "canvas/visibility.h"
#include "canvas/types.h"

class OptimizingLookupTableTest;

namespace ArdourCanvas {

class Item;

class LIBCANVAS_API LookupTable
{
public:
    LookupTable (Item const &);
    virtual ~LookupTable ();

    virtual std::vector<Item*> get (Rect const &) = 0;
    virtual std::vector<Item*> items_at_point (Duple const &) const = 0;
    virtual bool has_item_at_point (Duple const & point) const = 0;

protected:

    Item const & _item;
};

class LIBCANVAS_API DumbLookupTable : public LookupTable
{
public:
	DumbLookupTable (Item const &);

    std::vector<Item*> get (Rect const &);
    std::vector<Item*> items_at_point (Duple const &) const;
    bool has_item_at_point (Duple const & point) const;
};

class LIBCANVAS_API OptimizingLookupTable : public LookupTable
{
public:
    OptimizingLookupTable (Item const &, int);
    ~OptimizingLookupTable ();
    std::vector<Item*> get (Rect const &);
    std::vector<Item*> items_at_point (Duple const &) const;
    bool has_item_at_point (Duple const & point) const;

    static int default_items_per_cell;

  private:

    void area_to_indices (Rect const &, int &, int &, int &, int &) const;
    void point_to_indices (Duple, int &, int &) const;

    friend class ::OptimizingLookupTableTest;

    typedef std::vector<Item*> Cell;
    int _items_per_cell;
    int _dimension;
    Duple _cell_size;
    Duple _offset;
    Cell** _cells;
    bool _added;
};

}

#endif