scrollWithIndexAndRingcheck static method
void
scrollWithIndexAndRingcheck(
- CoordinateSequence seq,
- int indexOfFirstCoordinate,
- bool ensureRing
Shifts the positions of the coordinates until the coordinate at firstCoordinateIndex
is first.
@param seq the coordinate sequence to rearrange @param indexOfFirstCoordinate the index of the coordinate to make first @param ensureRing makes sure that {@code} will be a closed ring upon exit
Implementation
static void scrollWithIndexAndRingcheck(
CoordinateSequence seq, int indexOfFirstCoordinate, bool ensureRing) {
int i = indexOfFirstCoordinate;
if (i <= 0) return;
// make a copy of the sequence
CoordinateSequence copy = seq.copy();
// test if ring, determine last index
int last = ensureRing ? seq.size() - 1 : seq.size();
// fill in values
for (int j = 0; j < last; j++) {
for (int k = 0; k < seq.getDimension(); k++)
seq.setOrdinate(
j, k, copy.getOrdinate((indexOfFirstCoordinate + j) % last, k));
}
// Fix the ring (first == last)
if (ensureRing) {
for (int k = 0; k < seq.getDimension(); k++)
seq.setOrdinate(last, k, seq.getOrdinate(0, k));
}
}