• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gephi / graphstore / #504

03 Oct 2025 01:24PM UTC coverage: 91.042% (+0.2%) from 90.873%
#504

push

web-flow
Add Spliterator on NodesQuadTree (#243)

* Change default config for block size and default dict size

* Replace LinkedHashSet with arrays and implement spliterator

* Add multi-node edge iterator

* Refactoring to remove duplicate getNodes methods in quadtree

* Add edge iteration support in quadtree

* Add global quad tree edge iterator option

* Refactor to configure edge inout iterator locking and test all edges in quadtree spliterator

* Formatting

* Git ignore

* Non approximate support for global iterator and bugfix

* Add additional tests

* Quadtree versioning

* Tweak boundaries

* Documentation

* Update src/main/java/org/gephi/graph/impl/NodesQuadTree.java

Remove distinct from spliterator as edges can be returned twice

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix locking function name clash in view decorator

* Fix toArray

* Reduce memory overhead of quad node array init

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

535 of 615 new or added lines in 10 files covered. (86.99%)

1 existing line in 1 file now uncovered.

11576 of 12715 relevant lines covered (91.04%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.02
/src/main/java/org/gephi/graph/api/Rect2D.java
1
/*
2
 * Copyright 2012-2013 Gephi Consortium
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16
package org.gephi.graph.api;
17

18
import java.text.DecimalFormat;
19
import java.text.DecimalFormatSymbols;
20
import java.text.NumberFormat;
21
import java.util.Locale;
22

23
/**
24
 * Represents a 2D axis-aligned immutable rectangle.
25
 *
26
 * @author Eduardo Ramos
27
 */
28
public class Rect2D {
29

30
    public final float minX, minY;
31
    public final float maxX, maxY;
32

33
    /**
34
     * Create a new {@link Rect2D} as a copy of the given <code>source</code> .
35
     *
36
     * @param source the {@link Rect2D} to copy from
37
     */
38
    public Rect2D(Rect2D source) {
×
39
        this.minX = source.minX;
×
40
        this.minY = source.minY;
×
41
        this.maxX = source.maxX;
×
42
        this.maxY = source.maxY;
×
43
    }
×
44

45
    /**
46
     * Create a new {@link Rect2D} with the given minimum and maximum corner
47
     * coordinates.
48
     *
49
     * @param minX the x coordinate of the minimum corner
50
     * @param minY the y coordinate of the minimum corner
51
     * @param maxX the x coordinate of the maximum corner
52
     * @param maxY the y coordinate of the maximum corner
53
     */
54
    public Rect2D(float minX, float minY, float maxX, float maxY) {
1✔
55
        if (minX > maxX) {
1✔
56
            throw new IllegalArgumentException("minX > maxX");
×
57
        }
58

59
        if (minY > maxY) {
1✔
60
            throw new IllegalArgumentException("minX > maxX");
×
61
        }
62

63
        this.minX = minX;
1✔
64
        this.minY = minY;
1✔
65
        this.maxX = maxX;
1✔
66
        this.maxY = maxY;
1✔
67
    }
1✔
68

69
    /**
70
     * Return the rectangle's width.
71
     *
72
     * @return the rectangle's width
73
     */
74
    public float width() {
75
        return maxX - minX;
×
76
    }
77

78
    /**
79
     * Return the rectangle's height.
80
     *
81
     * @return the rectangle's height
82
     */
83
    public float height() {
84
        return maxY - minY;
×
85
    }
86

87
    /**
88
     * Return the rectangle's center, as an array where the first element is the x
89
     * coordinate and the second element is the y coordinate.
90
     *
91
     * @return the rectangle's center
92
     */
93
    public float[] center() {
94
        return new float[] { (maxX + minX) / 2, (maxY + minY) / 2 };
×
95
    }
96

97
    /**
98
     * Return the rectangle's radius.
99
     *
100
     * @return the rectangle's radius
101
     */
102
    public float radius() {
103
        float width = width();
×
104
        float height = height();
×
105
        return (float) Math.sqrt(width * width + height * height) / 2;
×
106
    }
107

108
    private static final DecimalFormat FORMAT = new DecimalFormat("0.###",
1✔
109
            DecimalFormatSymbols.getInstance(Locale.ENGLISH));
1✔
110

111
    @Override
112
    public String toString() {
113
        return toString(FORMAT);
×
114
    }
115

116
    private String toString(NumberFormat formatter) {
NEW
117
        return "min(x:" + formatter.format(minX) + " y:" + formatter.format(minY) + ") < " + "max(x:" + formatter
×
NEW
118
                .format(maxX) + " y:" + formatter.format(maxY) + ")";
×
119
    }
120

121
    /**
122
     * Returns true if this rectangle contains the given rectangle.
123
     *
124
     * @param rect the rectangle to check
125
     * @return true if this rectangle contains, false otherwise
126
     */
127
    public boolean contains(Rect2D rect) {
128
        if (rect == this) {
1✔
129
            return true;
×
130
        }
131

132
        return contains(rect.minX, rect.minY, rect.maxX, rect.maxY);
1✔
133
    }
134

135
    /**
136
     * Returns true if this rectangle intersects the given rectangle.
137
     *
138
     * @param rect the rectangle to check
139
     * @return true if this rectangle intersects, false otherwise
140
     */
141
    public boolean intersects(Rect2D rect) {
142
        if (rect == this) {
1✔
143
            return true;
×
144
        }
145

146
        return intersects(rect.minX, rect.minY, rect.maxX, rect.maxY);
1✔
147
    }
148

149
    /**
150
     * Returns true if this rectangle contains the given rectangle.
151
     *
152
     * @param minX the x coordinate of the minimum corner
153
     * @param minY the y coordinate of the minimum corner
154
     * @param maxX the x coordinate of the maximum corner
155
     * @param maxY the y coordinate of the maximum corner
156
     *
157
     * @return true if this rectangle contains, false otherwise
158
     */
159
    public boolean contains(float minX, float minY, float maxX, float maxY) {
160
        return this.minX <= minX && this.minY <= minY && this.maxX >= maxX && this.maxY >= maxY;
1✔
161
    }
162

163
    /**
164
     * Returns true if this rectangle intersects the given rectangle.
165
     *
166
     * @param minX the x coordinate of the minimum corner
167
     * @param minY the y coordinate of the minimum corner
168
     * @param maxX the x coordinate of the maximum corner
169
     * @param maxY the y coordinate of the maximum corner
170
     *
171
     * @return true if this rectangle intersects, false otherwise
172
     */
173
    public boolean intersects(float minX, float minY, float maxX, float maxY) {
174
        return this.minX <= maxX && minX <= this.maxX && this.maxY >= minY && maxY >= this.minY;
1✔
175
    }
176

177
    /**
178
     * Returns true if this rectangle contains or intersects with the given
179
     * rectangle. This is equivalent to checking
180
     * {@code this.contains(rect) || this.intersects(rect)} but more efficient as it
181
     * performs the check in a single operation.
182
     *
183
     * @param rect the rectangle to check
184
     * @return true if this rectangle contains or intersects with the given
185
     *         rectangle, false otherwise
186
     */
187
    public boolean containsOrIntersects(Rect2D rect) {
188
        if (rect == this) {
1✔
NEW
189
            return true;
×
190
        }
191

192
        return containsOrIntersects(rect.minX, rect.minY, rect.maxX, rect.maxY);
1✔
193
    }
194

195
    /**
196
     * Returns true if this rectangle contains or intersects with the given
197
     * rectangle. This is equivalent to checking
198
     * {@code this.contains(minX, minY, maxX, maxY) || this.intersects(minX, minY, maxX, maxY)}
199
     * but more efficient as it performs the check in a single operation.
200
     *
201
     * @param minX the x coordinate of the minimum corner
202
     * @param minY the y coordinate of the minimum corner
203
     * @param maxX the x coordinate of the maximum corner
204
     * @param maxY the y coordinate of the maximum corner
205
     *
206
     * @return true if this rectangle contains or intersects with the given
207
     *         rectangle, false otherwise
208
     */
209
    public boolean containsOrIntersects(float minX, float minY, float maxX, float maxY) {
210
        // Two rectangles have overlap if they intersect - containment is a subset of
211
        // intersection
212
        return this.minX <= maxX && minX <= this.maxX && this.maxY >= minY && maxY >= this.minY;
1✔
213
    }
214

215
    @Override
216
    public boolean equals(Object obj) {
217
        if (this == obj) {
1✔
218
            return true;
1✔
219
        }
220
        if (obj == null || getClass() != obj.getClass()) {
1✔
221
            return false;
×
222
        }
223
        Rect2D rect2D = (Rect2D) obj;
1✔
224
        return Float.compare(rect2D.minX, minX) == 0 && Float.compare(rect2D.minY, minY) == 0 && Float
1✔
225
                .compare(rect2D.maxX, maxX) == 0 && Float.compare(rect2D.maxY, maxY) == 0;
1✔
226
    }
227

228
    @Override
229
    public int hashCode() {
230
        int result = (minX != +0.0f ? Float.floatToIntBits(minX) : 0);
×
231
        result = 31 * result + (minY != +0.0f ? Float.floatToIntBits(minY) : 0);
×
232
        result = 31 * result + (maxX != +0.0f ? Float.floatToIntBits(maxX) : 0);
×
233
        result = 31 * result + (maxY != +0.0f ? Float.floatToIntBits(maxY) : 0);
×
234
        return result;
×
235
    }
236
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc