Skip to content

Commit 0e3939d

Browse files
committed
use double arithmetic in SplitterRStar lowestMarginSum, initialize with Double.POSITIVE_INFINITY, ensures pairs is non-null at exit of SplitterRStar.split
1 parent 7cf78aa commit 0e3939d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/com/github/davidmoten/rtree/SplitterRStar.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ public <T extends HasGeometry> ListPair<T> split(List<T> items, int minSize) {
4040
// the list with the least S is then used to find minimum overlap
4141

4242
List<ListPair<T>> pairs = null;
43-
float lowestMarginSum = Float.MAX_VALUE;
43+
double lowestMarginSum = Double.POSITIVE_INFINITY;
4444
List<T> list = null;
4545
for (SortType sortType : SortType.values()) {
4646
if (list == null) {
4747
list = new ArrayList<T>(items);
4848
}
4949
Collections.sort(list, comparator(sortType));
5050
List<ListPair<T>> p = getPairs(minSize, list);
51-
float marginSum = marginValueSum(p);
52-
if (marginSum < lowestMarginSum) {
51+
double marginSum = marginValueSum(p);
52+
if (marginSum <= lowestMarginSum) {
5353
lowestMarginSum = marginSum;
5454
pairs = p;
5555
// because p uses subViews of list we need to create a new one
@@ -79,8 +79,8 @@ private enum SortType {
7979
X_LOWER, X_UPPER, Y_LOWER, Y_UPPER;
8080
}
8181

82-
private static <T extends HasGeometry> float marginValueSum(List<ListPair<T>> list) {
83-
float sum = 0;
82+
private static <T extends HasGeometry> double marginValueSum(List<ListPair<T>> list) {
83+
double sum = 0;
8484
for (ListPair<T> p : list)
8585
sum += p.marginSum();
8686
return sum;

0 commit comments

Comments
 (0)