use of com.github.davidmoten.rtree2.geometry.HasGeometry in project rtree2 by davidmoten.
the class SplitterQuadratic method assignRemaining.
private <T extends HasGeometry> void assignRemaining(final List<T> group1, final List<T> group2, final List<T> remaining, final int minGroupSize) {
final Rectangle mbr1 = Util.mbr(group1);
final Rectangle mbr2 = Util.mbr(group2);
final T item1 = getBestCandidateForGroup(remaining, group1, mbr1);
final T item2 = getBestCandidateForGroup(remaining, group2, mbr2);
final boolean area1LessThanArea2 = item1.geometry().mbr().add(mbr1).area() <= item2.geometry().mbr().add(mbr2).area();
if (area1LessThanArea2 && (group2.size() + remaining.size() - 1 >= minGroupSize) || !area1LessThanArea2 && (group1.size() + remaining.size() == minGroupSize)) {
group1.add(item1);
remaining.remove(item1);
} else {
group2.add(item2);
remaining.remove(item2);
}
}
use of com.github.davidmoten.rtree2.geometry.HasGeometry in project rtree2 by davidmoten.
the class Util method mbr.
/**
* Returns the minimum bounding rectangle of a number of items. Benchmarks below
* indicate that when the number of items is >1 this method is more
* performant than one using {@link Rectangle#add(Rectangle)}.
*
* <pre>
* Benchmark Mode Samples Score Score error Units
* c.g.d.r.BenchmarksMbr.mbrList1 thrpt 10 48450492.301 436127.960 ops/s
* c.g.d.r.BenchmarksMbr.mbrList2 thrpt 10 46658242.728 987901.581 ops/s
* c.g.d.r.BenchmarksMbr.mbrList3 thrpt 10 40357809.306 937827.660 ops/s
* c.g.d.r.BenchmarksMbr.mbrList4 thrpt 10 35930532.557 605535.237 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList1 thrpt 10 55848118.198 1342997.309 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList2 thrpt 10 25171873.903 395127.918 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList3 thrpt 10 19222116.139 246965.178 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList4 thrpt 10 14891862.638 198765.157 ops/s
* </pre>
*
* @param items
* items to bound
* @return the minimum bounding rectangle containings items
*/
public static Rectangle mbr(Collection<? extends HasGeometry> items) {
Preconditions.checkArgument(!items.isEmpty());
double minX1 = Double.MAX_VALUE;
double minY1 = Double.MAX_VALUE;
double maxX2 = -Double.MAX_VALUE;
double maxY2 = -Double.MAX_VALUE;
boolean isDoublePrecision = false;
for (final HasGeometry item : items) {
Rectangle r = item.geometry().mbr();
if (r.isDoublePrecision()) {
isDoublePrecision = true;
}
if (r.x1() < minX1)
minX1 = r.x1();
if (r.y1() < minY1)
minY1 = r.y1();
if (r.x2() > maxX2)
maxX2 = r.x2();
if (r.y2() > maxY2)
maxY2 = r.y2();
}
if (isDoublePrecision) {
return Geometries.rectangle(minX1, minY1, maxX2, maxY2);
} else {
return Geometries.rectangle((float) minX1, (float) minY1, (float) maxX2, (float) maxY2);
}
}
use of com.github.davidmoten.rtree2.geometry.HasGeometry in project rtree2 by davidmoten.
the class Comparators method overlapArea.
private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
Rectangle gPlusR = g.geometry().mbr().add(r);
float m = 0;
for (HasGeometry other : list) {
if (other != g) {
m += gPlusR.intersectionArea(other.geometry().mbr());
}
}
return m;
}
Aggregations