Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 11:00:05 +01:00
Added [g]closest(x,y,z,index,count,stride) to the expression parser.
This function reads <count> x/y/z triplets from [g]megabuf, starting at <index> and advancing <stride> elements each time. It then finds the element closest to the given coordinates.
Dieser Commit ist enthalten in:
Ursprung
613f3884d4
Commit
6c413289be
@ -309,6 +309,54 @@ public final class Functions {
|
||||
return setBufferItem(Expression.getInstance().getMegabuf(), (int) index.getValue(), value);
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static final double closest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
Expression.getInstance().getMegabuf(),
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static final double gclosest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
gmegabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
private static double findClosest(Map<Integer, double[]> megabuf, double x, double y, double z, int index, int count, int stride) {
|
||||
int closestIndex = -1;
|
||||
double minDistanceSquared = Double.MAX_VALUE;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double currentX = getBufferItem(megabuf, index+0) - x;
|
||||
double currentY = getBufferItem(megabuf, index+1) - y;
|
||||
double currentZ = getBufferItem(megabuf, index+2) - z;
|
||||
|
||||
double currentDistanceSquared = currentX*currentX + currentY*currentY + currentZ*currentZ;
|
||||
|
||||
if (currentDistanceSquared < minDistanceSquared) {
|
||||
minDistanceSquared = currentDistanceSquared;
|
||||
closestIndex = index;
|
||||
}
|
||||
|
||||
index += stride;
|
||||
}
|
||||
|
||||
return closestIndex;
|
||||
}
|
||||
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren