This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNode.cs
189 lines (170 loc) · 5.52 KB
/
RNode.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Node.java
// Java Spatial Index Library
// Copyright (C) 2002 Infomatiq Limited
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Ported to C# By Dror Gluska, April 9th, 2009
namespace SolucionAlumno
{
//import com.infomatiq.jsi.Rectangle;
/**
* <p>Used by RTree. There are no public methods in this class.</p>
*
* @author [email protected]
* @version 1.0b2p1
*/
public class RNode<T>
{
internal int nodeId = 0;
internal RRectangle mbr = null;
internal RRectangle[] entries = null;
internal int[] ids = null;
internal int level;
internal int entryCount;
public RNode(int nodeId, int level, int maxNodeEntries)
{
this.nodeId = nodeId;
this.level = level;
entries = new RRectangle[maxNodeEntries];
ids = new int[maxNodeEntries];
}
internal void addEntry(RRectangle r, int id)
{
ids[entryCount] = id;
entries[entryCount] = r.copy();
entryCount++;
if (mbr == null)
{
mbr = r.copy();
}
else
{
mbr.add(r);
}
}
internal void addEntryNoCopy(RRectangle r, int id)
{
ids[entryCount] = id;
entries[entryCount] = r;
entryCount++;
if (mbr == null)
{
mbr = r.copy();
}
else
{
mbr.add(r);
}
}
// Return the index of the found entry, or -1 if not found
internal int findEntry(RRectangle r, int id)
{
for (int i = 0; i < entryCount; i++)
{
if (id == ids[i] && r.Equals(entries[i]))
{
return i;
}
}
return -1;
}
// delete entry. This is done by setting it to null and copying the last entry into its space.
internal void deleteEntry(int i, int minNodeEntries)
{
int lastIndex = entryCount - 1;
RRectangle deletedRectangle = entries[i];
entries[i] = null;
if (i != lastIndex)
{
entries[i] = entries[lastIndex];
ids[i] = ids[lastIndex];
entries[lastIndex] = null;
}
entryCount--;
// if there are at least minNodeEntries, adjust the MBR.
// otherwise, don't bother, as the Node<T> will be
// eliminated anyway.
if (entryCount >= minNodeEntries)
{
recalculateMBR(deletedRectangle);
}
}
// oldRectangle is a rectangle that has just been deleted or made smaller.
// Thus, the MBR is only recalculated if the OldRectangle influenced the old MBR
internal void recalculateMBR(RRectangle deletedRectangle)
{
if (mbr.edgeOverlaps(deletedRectangle))
{
mbr.set(entries[0].min, entries[0].max);
for (int i = 1; i < entryCount; i++)
{
mbr.add(entries[i]);
}
}
}
public int getEntryCount()
{
return entryCount;
}
public RRectangle getEntry(int index)
{
if (index < entryCount)
{
return entries[index];
}
return null;
}
public int getId(int index)
{
if (index < entryCount)
{
return ids[index];
}
return -1;
}
/**
* eliminate null entries, move all entries to the start of the source node
*/
internal void reorganize(RTree<T> rtree)
{
int countdownIndex = rtree.maxNodeEntries - 1;
for (int index = 0; index < entryCount; index++)
{
if (entries[index] == null)
{
while (entries[countdownIndex] == null && countdownIndex > index)
{
countdownIndex--;
}
entries[index] = entries[countdownIndex];
ids[index] = ids[countdownIndex];
entries[countdownIndex] = null;
}
}
}
internal bool isLeaf()
{
return (level == 1);
}
public int getLevel()
{
return level;
}
public RRectangle getMBR()
{
return mbr;
}
}
}