minecraft-src/net/minecraft/world/phys/shapes/IndirectMerger.java
2025-07-04 01:41:11 +03:00

87 lines
2 KiB
Java

package net.minecraft.world.phys.shapes;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import it.unimi.dsi.fastutil.doubles.DoubleLists;
public class IndirectMerger implements IndexMerger {
private static final DoubleList EMPTY = DoubleLists.unmodifiable(DoubleArrayList.wrap(new double[]{0.0}));
private final double[] result;
private final int[] firstIndices;
private final int[] secondIndices;
private final int resultLength;
public IndirectMerger(DoubleList lower, DoubleList upper, boolean excludeUpper, boolean excludeLower) {
double d = Double.NaN;
int i = lower.size();
int j = upper.size();
int k = i + j;
this.result = new double[k];
this.firstIndices = new int[k];
this.secondIndices = new int[k];
boolean bl = !excludeUpper;
boolean bl2 = !excludeLower;
int l = 0;
int m = 0;
int n = 0;
while (true) {
boolean bl3 = m >= i;
boolean bl4 = n >= j;
if (bl3 && bl4) {
this.resultLength = Math.max(1, l);
return;
}
boolean bl5 = !bl3 && (bl4 || lower.getDouble(m) < upper.getDouble(n) + 1.0E-7);
if (bl5) {
m++;
if (bl && (n == 0 || bl4)) {
continue;
}
} else {
n++;
if (bl2 && (m == 0 || bl3)) {
continue;
}
}
int o = m - 1;
int p = n - 1;
double e = bl5 ? lower.getDouble(o) : upper.getDouble(p);
if (!(d >= e - 1.0E-7)) {
this.firstIndices[l] = o;
this.secondIndices[l] = p;
this.result[l] = e;
l++;
d = e;
} else {
this.firstIndices[l - 1] = o;
this.secondIndices[l - 1] = p;
}
}
}
@Override
public boolean forMergedIndexes(IndexMerger.IndexConsumer consumer) {
int i = this.resultLength - 1;
for (int j = 0; j < i; j++) {
if (!consumer.merge(this.firstIndices[j], this.secondIndices[j], j)) {
return false;
}
}
return true;
}
@Override
public int size() {
return this.resultLength;
}
@Override
public DoubleList getList() {
return (DoubleList)(this.resultLength <= 1 ? EMPTY : DoubleArrayList.wrap(this.result, this.resultLength));
}
}