PiecewiseLinearIndentationFunctorpublic class PiecewiseLinearIndentationFunctor extends StackIndentationFunctor A Functor which interpolates the stack distance linearly based on base values.
The base values are based on an interpolation between a linear function and a
quadratic function |
Fields Summary |
---|
private final ArrayList | mBaseValues | private final float | mLinearPart |
Constructors Summary |
---|
PiecewiseLinearIndentationFunctor(int maxItemsInStack, int peekSize, int distanceToPeekStart, float linearPart)
super(maxItemsInStack, peekSize, distanceToPeekStart);
mBaseValues = new ArrayList<Float>(maxItemsInStack+1);
initBaseValues();
mLinearPart = linearPart;
|
Methods Summary |
---|
private int | getSumOfSquares(int n)Get the sum of squares up to and including n, i.e sum(i * i, 1, n)
return n * (n + 1) * (2 * n + 1) / 6;
| public float | getValue(float itemsBefore)
if (mStackStartsAtPeek) {
// We directly start at the stack, so no initial interpolation.
itemsBefore++;
}
if (itemsBefore < 0) {
return 0;
} else if (itemsBefore >= mMaxItemsInStack) {
return mTotalTransitionDistance;
}
int below = (int) itemsBefore;
float partialIn = itemsBefore - below;
if (below == 0) {
return mDistanceToPeekStart * partialIn;
} else {
float result = mDistanceToPeekStart;
float progress = mBaseValues.get(below - 1) * (1 - partialIn)
+ mBaseValues.get(below) * partialIn;
result += (progress * (1 - mLinearPart)
+ (itemsBefore - 1) / (mMaxItemsInStack - 1) * mLinearPart) * mPeekSize;
return result;
}
| private void | initBaseValues()
int sumOfSquares = getSumOfSquares(mMaxItemsInStack-1);
int totalWeight = 0;
mBaseValues.add(0.0f);
for (int i = 0; i < mMaxItemsInStack - 1; i++) {
totalWeight += (mMaxItemsInStack - i - 1) * (mMaxItemsInStack - i - 1);
mBaseValues.add((float) totalWeight / sumOfSquares);
}
|
|