1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
package tim.prune.function.sew;
import java.util.ArrayList;
import java.util.List;
/**
* A single segment in the sewing operation
*/
public class Segment
{
private final int _startIndex;
private final int _endIndex;
private boolean _reversed;
public Segment(int inStartIndex, int inEndIndex)
{
_startIndex = inStartIndex;
_endIndex = inEndIndex;
_reversed = false;
// TODO: Set 'alive' status if either end point has photo/audio?
}
public boolean isSingle() {
return _startIndex == _endIndex;
}
public void reverse() {
_reversed = !_reversed;
}
public int getStartIndex() {
return _reversed ? _endIndex : _startIndex;
}
public int getEndIndex() {
return _reversed ? _startIndex : _endIndex;
}
public List<Integer> getPointIndexes(boolean withFirstPoint)
{
ArrayList<Integer> result = new ArrayList<>();
boolean firstPoint = true;
int numPoints = _endIndex - _startIndex + 1;
for (int i = 0; i < numPoints; i++)
{
if (firstPoint) {
firstPoint = false;
if (!withFirstPoint) {
continue;
}
}
int indexToAdd = (_reversed ? _endIndex - i : _startIndex + i);
result.add(indexToAdd);
}
return result;
}
}
|