More precisely, if the pseudoCyclicTruncation argument is false, returns the following value: shift = {@link #coord(int) coord(0)} +{@link #coord(int) coord(1)}*dim0 + {@link #coord(int) coord(2)}*dim0*dim1 + ... + {@link #coord(int) coord(n-1)}*dim0*dim1*...*dimn-2 (n = {@link #coordCount()}, where dimi=i>=dimensions.length?1:dimensions[i]. If pseudoCyclicTruncation is true, returns the positive remainder of division of this value by the product of all dimensions:
shift%product >= 0 ? shift%product : shift%product + product,product = dim0*dim1*...*dimn-1. (In the special case product==0, if pseudoCyclicTruncation is true, this method returns 0 and does not throw "division by zero" exception.)
All elements of dimensions array must be positive or zero. All point coordinates are always used, regardless of the length of dimensions array.
If pseudoCyclicTruncation is true and the product of all dimensions product = dim0*dim1*...*dimn-1 is not greater than Long.MAX_VALUE, then all calculations are performed absolutely precisely, even in a case when the direct calculation according the formulas above leads to overflow (because some of values in these formulas are out of Long.MIN_VALUE..Long.MAX_VALUE range). However, if product>Long.MAX_VALUE, the results will be probably incorrect due to overflow.
If pseudoCyclicTruncation is false, the result is calculated by the traditional Horner scheme without any overflow checks, using standard Java long arithmetic:
(...( {@link #coord(int) coord(n-1)}*dimn-2+ {@link #coord(int) coord(n-2)})*dimn-3+...)*dim0+ {@link #coord(int) coord(0)}So, the result can be incorrect in a case of overflow. @param dimensions the dimensions of some n-dimensional matrix, stored in the one-dimensionalarray. @param pseudoCyclicTruncation if true, the result is replaced with the positive remainder of divisionby the product of all dimensions. @return the index in this array, corresponding the position in the matrix,describing by this point. @throws NullPointerException if dimensions argument is null. @throws IllegalArgumentException if some elements of dimensions array are negative(however note, that this method does not check elements, indexes of which are >= {@link #coordCount()})
|
|