use of org.apache.sis.math.Vector in project sis by apache.
the class ImageFileDirectory method extremum.
/**
* Computes the minimal or maximal values of the given vector. Those vectors do not need to have the same length.
* One of those two vector will be modified in-place.
*
* @param a the first vector, or {@code null} if none.
* @param b the new vector to combine with the existing one. Can not be null.
* @param max {@code true} for computing the maximal values, or {@code false} for the minimal value.
*/
private static Vector extremum(Vector a, Vector b, final boolean max) {
if (a != null) {
int s = b.size();
int i = a.size();
if (i > s) {
// If a vector is longer than b, swap a and b.
i = s;
final Vector t = a;
a = b;
b = t;
}
while (--i >= 0) {
// At this point, 'b' shall be the longest vector.
final double va = a.doubleValue(i);
final double vb = b.doubleValue(i);
if (Double.isNaN(vb) || (max ? va > vb : va < vb)) {
b.set(i, va);
}
}
}
return b;
}
Aggregations