mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 01:47:17 +01:00
173 lines
6.8 KiB
Java
173 lines
6.8 KiB
Java
package androidx.dynamicanimation.animation;
|
|
|
|
import androidx.annotation.FloatRange;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.dynamicanimation.animation.DynamicAnimation;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes14.dex */
|
|
public final class SpringForce implements Force {
|
|
public static final float DAMPING_RATIO_HIGH_BOUNCY = 0.2f;
|
|
public static final float DAMPING_RATIO_LOW_BOUNCY = 0.75f;
|
|
public static final float DAMPING_RATIO_MEDIUM_BOUNCY = 0.5f;
|
|
public static final float DAMPING_RATIO_NO_BOUNCY = 1.0f;
|
|
public static final float STIFFNESS_HIGH = 10000.0f;
|
|
public static final float STIFFNESS_LOW = 200.0f;
|
|
public static final float STIFFNESS_MEDIUM = 1500.0f;
|
|
public static final float STIFFNESS_VERY_LOW = 50.0f;
|
|
private static final double UNSET = Double.MAX_VALUE;
|
|
private static final double VELOCITY_THRESHOLD_MULTIPLIER = 62.5d;
|
|
private double mDampedFreq;
|
|
double mDampingRatio;
|
|
private double mFinalPosition;
|
|
private double mGammaMinus;
|
|
private double mGammaPlus;
|
|
private boolean mInitialized;
|
|
private final DynamicAnimation.MassState mMassState;
|
|
double mNaturalFreq;
|
|
private double mValueThreshold;
|
|
private double mVelocityThreshold;
|
|
|
|
public SpringForce(float f) {
|
|
this.mNaturalFreq = Math.sqrt(1500.0d);
|
|
this.mDampingRatio = 0.5d;
|
|
this.mInitialized = false;
|
|
this.mFinalPosition = Double.MAX_VALUE;
|
|
this.mMassState = new DynamicAnimation.MassState();
|
|
this.mFinalPosition = f;
|
|
}
|
|
|
|
private void init() {
|
|
if (this.mInitialized) {
|
|
return;
|
|
}
|
|
if (this.mFinalPosition == Double.MAX_VALUE) {
|
|
Single$$ExternalSyntheticBUOutline0.m$2("Error: Final position of the spring must be set before the animation starts");
|
|
return;
|
|
}
|
|
double d = this.mDampingRatio;
|
|
if (d > 1.0d) {
|
|
double d2 = this.mNaturalFreq;
|
|
this.mGammaPlus = (Math.sqrt((d * d) - 1.0d) * d2) + ((-d) * d2);
|
|
double d3 = this.mDampingRatio;
|
|
double d4 = this.mNaturalFreq;
|
|
this.mGammaMinus = ((-d3) * d4) - (Math.sqrt((d3 * d3) - 1.0d) * d4);
|
|
} else if (d >= 0.0d && d < 1.0d) {
|
|
this.mDampedFreq = Math.sqrt(1.0d - (d * d)) * this.mNaturalFreq;
|
|
}
|
|
this.mInitialized = true;
|
|
}
|
|
|
|
@Override // androidx.dynamicanimation.animation.Force
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public float getAcceleration(float f, float f2) {
|
|
float finalPosition = f - getFinalPosition();
|
|
double d = this.mNaturalFreq;
|
|
return (float) (((-(d * d)) * finalPosition) - (((d * 2.0d) * this.mDampingRatio) * f2));
|
|
}
|
|
|
|
public float getDampingRatio() {
|
|
return (float) this.mDampingRatio;
|
|
}
|
|
|
|
public float getFinalPosition() {
|
|
return (float) this.mFinalPosition;
|
|
}
|
|
|
|
public float getStiffness() {
|
|
double d = this.mNaturalFreq;
|
|
return (float) (d * d);
|
|
}
|
|
|
|
@Override // androidx.dynamicanimation.animation.Force
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public boolean isAtEquilibrium(float f, float f2) {
|
|
return ((double) Math.abs(f2)) < this.mVelocityThreshold && ((double) Math.abs(f - getFinalPosition())) < this.mValueThreshold;
|
|
}
|
|
|
|
public SpringForce setDampingRatio(@FloatRange(from = 0.0d) float f) {
|
|
if (f < 0.0f) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Damping ratio must be non-negative");
|
|
return null;
|
|
}
|
|
this.mDampingRatio = f;
|
|
this.mInitialized = false;
|
|
return this;
|
|
}
|
|
|
|
public SpringForce setFinalPosition(float f) {
|
|
this.mFinalPosition = f;
|
|
return this;
|
|
}
|
|
|
|
public SpringForce setStiffness(@FloatRange(from = 0.0d, fromInclusive = false) float f) {
|
|
if (f <= 0.0f) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Spring stiffness constant must be positive.");
|
|
return null;
|
|
}
|
|
this.mNaturalFreq = Math.sqrt(f);
|
|
this.mInitialized = false;
|
|
return this;
|
|
}
|
|
|
|
public void setValueThreshold(double d) {
|
|
double abs = Math.abs(d);
|
|
this.mValueThreshold = abs;
|
|
this.mVelocityThreshold = abs * VELOCITY_THRESHOLD_MULTIPLIER;
|
|
}
|
|
|
|
public DynamicAnimation.MassState updateValues(double d, double d2, long j) {
|
|
double sin;
|
|
double cos;
|
|
init();
|
|
double d3 = j / 1000.0d;
|
|
double d4 = d - this.mFinalPosition;
|
|
double d5 = this.mDampingRatio;
|
|
if (d5 > 1.0d) {
|
|
double d6 = this.mGammaMinus;
|
|
double d7 = this.mGammaPlus;
|
|
double d8 = d4 - (((d6 * d4) - d2) / (d6 - d7));
|
|
double d9 = ((d4 * d6) - d2) / (d6 - d7);
|
|
sin = (Math.pow(2.718281828459045d, this.mGammaPlus * d3) * d9) + (Math.pow(2.718281828459045d, d6 * d3) * d8);
|
|
double d10 = this.mGammaMinus;
|
|
double pow = Math.pow(2.718281828459045d, d10 * d3) * d8 * d10;
|
|
double d11 = this.mGammaPlus;
|
|
cos = (Math.pow(2.718281828459045d, d11 * d3) * d9 * d11) + pow;
|
|
} else if (d5 == 1.0d) {
|
|
double d12 = this.mNaturalFreq;
|
|
double d13 = (d12 * d4) + d2;
|
|
double d14 = (d13 * d3) + d4;
|
|
double pow2 = Math.pow(2.718281828459045d, (-d12) * d3) * d14;
|
|
double pow3 = Math.pow(2.718281828459045d, (-this.mNaturalFreq) * d3) * d14;
|
|
double d15 = this.mNaturalFreq;
|
|
cos = (Math.pow(2.718281828459045d, (-d15) * d3) * d13) + (pow3 * (-d15));
|
|
sin = pow2;
|
|
} else {
|
|
double d16 = 1.0d / this.mDampedFreq;
|
|
double d17 = this.mNaturalFreq;
|
|
double d18 = ((d5 * d17 * d4) + d2) * d16;
|
|
sin = ((Math.sin(this.mDampedFreq * d3) * d18) + (Math.cos(this.mDampedFreq * d3) * d4)) * Math.pow(2.718281828459045d, (-d5) * d17 * d3);
|
|
double d19 = this.mNaturalFreq;
|
|
double d20 = this.mDampingRatio;
|
|
double d21 = (-d19) * sin * d20;
|
|
double pow4 = Math.pow(2.718281828459045d, (-d20) * d19 * d3);
|
|
double d22 = this.mDampedFreq;
|
|
double sin2 = Math.sin(d22 * d3) * (-d22) * d4;
|
|
double d23 = this.mDampedFreq;
|
|
cos = (((Math.cos(d23 * d3) * d18 * d23) + sin2) * pow4) + d21;
|
|
}
|
|
DynamicAnimation.MassState massState = this.mMassState;
|
|
massState.mValue = (float) (sin + this.mFinalPosition);
|
|
massState.mVelocity = (float) cos;
|
|
return massState;
|
|
}
|
|
|
|
public SpringForce() {
|
|
this.mNaturalFreq = Math.sqrt(1500.0d);
|
|
this.mDampingRatio = 0.5d;
|
|
this.mInitialized = false;
|
|
this.mFinalPosition = Double.MAX_VALUE;
|
|
this.mMassState = new DynamicAnimation.MassState();
|
|
}
|
|
}
|