Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbsptree_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QBSPTREE_P_H
6#define QBSPTREE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include <qlist.h>
21#include <qrect.h>
22
24
26{
27public:
28
29 struct Node
30 {
31 enum Type { None = 0, VerticalPlane = 1, HorizontalPlane = 2, Both = 3 };
32 inline Node() : pos(0), type(None) {}
33 int pos;
35 };
36 typedef Node::Type NodeType;
37
38 struct Data
39 {
40 Data(void *p) : ptr(p) {}
41 Data(int n) : i(n) {}
42 union {
43 void *ptr;
44 int i;
45 };
46 };
48 typedef void callback(QList<int> &leaf, const QRect &area, uint visited, QBspTreeData data);
49
50 QBspTree();
51
52 void create(int n, int d = -1);
53 void destroy();
54
55 inline void init(const QRect &area, NodeType type) { init(area, depth, type, 0); }
56
57 void climbTree(const QRect &rect, callback *function, QBspTreeData data);
58
59 inline int leafCount() const { return leaves.size(); }
60 inline QList<int> &leaf(int i) { return leaves[i]; }
61 inline void insertLeaf(const QRect &r, int i) { climbTree(r, &insert, i, 0); }
62 inline void removeLeaf(const QRect &r, int i) { climbTree(r, &remove, i, 0); }
63
64protected:
65 void init(const QRect &area, int depth, NodeType type, int index);
66 void climbTree(const QRect &rect, callback *function, QBspTreeData data, int index);
67
68 inline int parentIndex(int i) const { return (i & 1) ? ((i - 1) / 2) : ((i - 2) / 2); }
69 inline int firstChildIndex(int i) const { return ((i * 2) + 1); }
70
71 static void insert(QList<int> &leaf, const QRect &area, uint visited, QBspTreeData data);
72 static void remove(QList<int> &leaf, const QRect &area, uint visited, QBspTreeData data);
73
74private:
75 uint depth;
76 mutable uint visited;
77 QList<Node> nodes;
78 mutable QList<QList<int>> leaves; // the leaves are just indices into the items
79};
80
81QT_END_NAMESPACE
82
83#endif // QBSPTREE_P_H
static void remove(QList< int > &leaf, const QRect &area, uint visited, QBspTreeData data)
Definition qbsptree.cpp:101
Node::Type NodeType
Definition qbsptree_p.h:36
void insertLeaf(const QRect &r, int i)
Definition qbsptree_p.h:61
QBspTree::Data QBspTreeData
Definition qbsptree_p.h:47
void create(int n, int d=-1)
Definition qbsptree.cpp:11
int parentIndex(int i) const
Definition qbsptree_p.h:68
void callback(QList< int > &leaf, const QRect &area, uint visited, QBspTreeData data)
Definition qbsptree_p.h:48
void climbTree(const QRect &rect, callback *function, QBspTreeData data, int index)
Definition qbsptree.cpp:42
void destroy()
Definition qbsptree.cpp:28
int firstChildIndex(int i) const
Definition qbsptree_p.h:69
void climbTree(const QRect &rect, callback *function, QBspTreeData data)
Definition qbsptree.cpp:34
void init(const QRect &area, NodeType type)
Definition qbsptree_p.h:55
void removeLeaf(const QRect &r, int i)
Definition qbsptree_p.h:62
int leafCount() const
Definition qbsptree_p.h:59
static void insert(QList< int > &leaf, const QRect &area, uint visited, QBspTreeData data)
Definition qbsptree.cpp:96
void init(const QRect &area, int depth, NodeType type, int index)
Definition qbsptree.cpp:67
QList< int > & leaf(int i)
Definition qbsptree_p.h:60
Definition qlist.h:80
\inmodule QtCore\reentrant
Definition qrect.h:31
Data(void *p)
Definition qbsptree_p.h:40