570 lines
22 KiB
Java
570 lines
22 KiB
Java
package androidx.constraintlayout.solver;
|
|
|
|
import androidx.constraintlayout.solver.LinearSystem;
|
|
import androidx.constraintlayout.solver.SolverVariable;
|
|
import b.d.b.a.a;
|
|
import java.util.ArrayList;
|
|
public class ArrayRow implements LinearSystem.Row {
|
|
private static final boolean DEBUG = false;
|
|
private static final boolean FULL_NEW_CHECK = false;
|
|
public float constantValue = 0.0f;
|
|
public boolean isSimpleDefinition = false;
|
|
public boolean used = false;
|
|
public SolverVariable variable = null;
|
|
public ArrayRowVariables variables;
|
|
public ArrayList<SolverVariable> variablesToUpdate = new ArrayList<>();
|
|
|
|
public interface ArrayRowVariables {
|
|
void add(SolverVariable solverVariable, float f, boolean z2);
|
|
|
|
void clear();
|
|
|
|
boolean contains(SolverVariable solverVariable);
|
|
|
|
void display();
|
|
|
|
void divideByAmount(float f);
|
|
|
|
float get(SolverVariable solverVariable);
|
|
|
|
int getCurrentSize();
|
|
|
|
SolverVariable getVariable(int i);
|
|
|
|
float getVariableValue(int i);
|
|
|
|
int indexOf(SolverVariable solverVariable);
|
|
|
|
void invert();
|
|
|
|
void put(SolverVariable solverVariable, float f);
|
|
|
|
float remove(SolverVariable solverVariable, boolean z2);
|
|
|
|
int sizeInBytes();
|
|
|
|
float use(ArrayRow arrayRow, boolean z2);
|
|
}
|
|
|
|
public ArrayRow() {
|
|
}
|
|
|
|
public ArrayRow(Cache cache) {
|
|
this.variables = new ArrayLinkedVariables(this, cache);
|
|
}
|
|
|
|
private boolean isNew(SolverVariable solverVariable, LinearSystem linearSystem) {
|
|
return solverVariable.usageInRowCount <= 1;
|
|
}
|
|
|
|
private SolverVariable pickPivotInVariables(boolean[] zArr, SolverVariable solverVariable) {
|
|
SolverVariable.Type type;
|
|
int currentSize = this.variables.getCurrentSize();
|
|
SolverVariable solverVariable2 = null;
|
|
float f = 0.0f;
|
|
for (int i = 0; i < currentSize; i++) {
|
|
float variableValue = this.variables.getVariableValue(i);
|
|
if (variableValue < 0.0f) {
|
|
SolverVariable variable = this.variables.getVariable(i);
|
|
if ((zArr == null || !zArr[variable.f30id]) && variable != solverVariable && (((type = variable.mType) == SolverVariable.Type.SLACK || type == SolverVariable.Type.ERROR) && variableValue < f)) {
|
|
f = variableValue;
|
|
solverVariable2 = variable;
|
|
}
|
|
}
|
|
}
|
|
return solverVariable2;
|
|
}
|
|
|
|
public ArrayRow addError(LinearSystem linearSystem, int i) {
|
|
this.variables.put(linearSystem.createErrorVariable(i, "ep"), 1.0f);
|
|
this.variables.put(linearSystem.createErrorVariable(i, "em"), -1.0f);
|
|
return this;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void addError(SolverVariable solverVariable) {
|
|
int i = solverVariable.strength;
|
|
float f = 1.0f;
|
|
if (i != 1) {
|
|
if (i == 2) {
|
|
f = 1000.0f;
|
|
} else if (i == 3) {
|
|
f = 1000000.0f;
|
|
} else if (i == 4) {
|
|
f = 1.0E9f;
|
|
} else if (i == 5) {
|
|
f = 1.0E12f;
|
|
}
|
|
}
|
|
this.variables.put(solverVariable, f);
|
|
}
|
|
|
|
public ArrayRow addSingleError(SolverVariable solverVariable, int i) {
|
|
this.variables.put(solverVariable, (float) i);
|
|
return this;
|
|
}
|
|
|
|
public boolean chooseSubject(LinearSystem linearSystem) {
|
|
boolean z2;
|
|
SolverVariable chooseSubjectInVariables = chooseSubjectInVariables(linearSystem);
|
|
if (chooseSubjectInVariables == null) {
|
|
z2 = true;
|
|
} else {
|
|
pivot(chooseSubjectInVariables);
|
|
z2 = false;
|
|
}
|
|
if (this.variables.getCurrentSize() == 0) {
|
|
this.isSimpleDefinition = true;
|
|
}
|
|
return z2;
|
|
}
|
|
|
|
public SolverVariable chooseSubjectInVariables(LinearSystem linearSystem) {
|
|
boolean isNew;
|
|
boolean isNew2;
|
|
int currentSize = this.variables.getCurrentSize();
|
|
SolverVariable solverVariable = null;
|
|
SolverVariable solverVariable2 = null;
|
|
boolean z2 = false;
|
|
boolean z3 = false;
|
|
float f = 0.0f;
|
|
float f2 = 0.0f;
|
|
for (int i = 0; i < currentSize; i++) {
|
|
float variableValue = this.variables.getVariableValue(i);
|
|
SolverVariable variable = this.variables.getVariable(i);
|
|
if (variable.mType == SolverVariable.Type.UNRESTRICTED) {
|
|
if (solverVariable == null) {
|
|
isNew2 = isNew(variable, linearSystem);
|
|
} else if (f > variableValue) {
|
|
isNew2 = isNew(variable, linearSystem);
|
|
} else if (!z2 && isNew(variable, linearSystem)) {
|
|
f = variableValue;
|
|
solverVariable = variable;
|
|
z2 = true;
|
|
}
|
|
z2 = isNew2;
|
|
f = variableValue;
|
|
solverVariable = variable;
|
|
} else if (solverVariable == null && variableValue < 0.0f) {
|
|
if (solverVariable2 == null) {
|
|
isNew = isNew(variable, linearSystem);
|
|
} else if (f2 > variableValue) {
|
|
isNew = isNew(variable, linearSystem);
|
|
} else if (!z3 && isNew(variable, linearSystem)) {
|
|
f2 = variableValue;
|
|
solverVariable2 = variable;
|
|
z3 = true;
|
|
}
|
|
z3 = isNew;
|
|
f2 = variableValue;
|
|
solverVariable2 = variable;
|
|
}
|
|
}
|
|
return solverVariable != null ? solverVariable : solverVariable2;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void clear() {
|
|
this.variables.clear();
|
|
this.variable = null;
|
|
this.constantValue = 0.0f;
|
|
}
|
|
|
|
public ArrayRow createRowCentering(SolverVariable solverVariable, SolverVariable solverVariable2, int i, float f, SolverVariable solverVariable3, SolverVariable solverVariable4, int i2) {
|
|
if (solverVariable2 == solverVariable3) {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable4, 1.0f);
|
|
this.variables.put(solverVariable2, -2.0f);
|
|
return this;
|
|
}
|
|
if (f == 0.5f) {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable3, -1.0f);
|
|
this.variables.put(solverVariable4, 1.0f);
|
|
if (i > 0 || i2 > 0) {
|
|
this.constantValue = (float) ((-i) + i2);
|
|
}
|
|
} else if (f <= 0.0f) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, 1.0f);
|
|
this.constantValue = (float) i;
|
|
} else if (f >= 1.0f) {
|
|
this.variables.put(solverVariable4, -1.0f);
|
|
this.variables.put(solverVariable3, 1.0f);
|
|
this.constantValue = (float) (-i2);
|
|
} else {
|
|
float f2 = 1.0f - f;
|
|
this.variables.put(solverVariable, f2 * 1.0f);
|
|
this.variables.put(solverVariable2, f2 * -1.0f);
|
|
this.variables.put(solverVariable3, -1.0f * f);
|
|
this.variables.put(solverVariable4, 1.0f * f);
|
|
if (i > 0 || i2 > 0) {
|
|
this.constantValue = (((float) i2) * f) + (((float) (-i)) * f2);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowDefinition(SolverVariable solverVariable, int i) {
|
|
this.variable = solverVariable;
|
|
float f = (float) i;
|
|
solverVariable.computedValue = f;
|
|
this.constantValue = f;
|
|
this.isSimpleDefinition = true;
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowDimensionPercent(SolverVariable solverVariable, SolverVariable solverVariable2, float f) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, f);
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowDimensionRatio(SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, SolverVariable solverVariable4, float f) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, 1.0f);
|
|
this.variables.put(solverVariable3, f);
|
|
this.variables.put(solverVariable4, -f);
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowEqualDimension(float f, float f2, float f3, SolverVariable solverVariable, int i, SolverVariable solverVariable2, int i2, SolverVariable solverVariable3, int i3, SolverVariable solverVariable4, int i4) {
|
|
if (f2 == 0.0f || f == f3) {
|
|
this.constantValue = (float) (((-i) - i2) + i3 + i4);
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable4, 1.0f);
|
|
this.variables.put(solverVariable3, -1.0f);
|
|
} else {
|
|
float f4 = (f / f2) / (f3 / f2);
|
|
this.constantValue = (((float) i4) * f4) + (((float) i3) * f4) + ((float) ((-i) - i2));
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable4, f4);
|
|
this.variables.put(solverVariable3, -f4);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowEqualMatchDimensions(float f, float f2, float f3, SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, SolverVariable solverVariable4) {
|
|
this.constantValue = 0.0f;
|
|
if (f2 == 0.0f || f == f3) {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable4, 1.0f);
|
|
this.variables.put(solverVariable3, -1.0f);
|
|
} else if (f == 0.0f) {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
} else if (f3 == 0.0f) {
|
|
this.variables.put(solverVariable3, 1.0f);
|
|
this.variables.put(solverVariable4, -1.0f);
|
|
} else {
|
|
float f4 = (f / f2) / (f3 / f2);
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable4, f4);
|
|
this.variables.put(solverVariable3, -f4);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowEquals(SolverVariable solverVariable, int i) {
|
|
if (i < 0) {
|
|
this.constantValue = (float) (i * -1);
|
|
this.variables.put(solverVariable, 1.0f);
|
|
} else {
|
|
this.constantValue = (float) i;
|
|
this.variables.put(solverVariable, -1.0f);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowEquals(SolverVariable solverVariable, SolverVariable solverVariable2, int i) {
|
|
boolean z2 = false;
|
|
if (i != 0) {
|
|
if (i < 0) {
|
|
i *= -1;
|
|
z2 = true;
|
|
}
|
|
this.constantValue = (float) i;
|
|
}
|
|
if (!z2) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, 1.0f);
|
|
} else {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowGreaterThan(SolverVariable solverVariable, int i, SolverVariable solverVariable2) {
|
|
this.constantValue = (float) i;
|
|
this.variables.put(solverVariable, -1.0f);
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowGreaterThan(SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, int i) {
|
|
boolean z2 = false;
|
|
if (i != 0) {
|
|
if (i < 0) {
|
|
i *= -1;
|
|
z2 = true;
|
|
}
|
|
this.constantValue = (float) i;
|
|
}
|
|
if (!z2) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, 1.0f);
|
|
this.variables.put(solverVariable3, 1.0f);
|
|
} else {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable3, -1.0f);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowLowerThan(SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, int i) {
|
|
boolean z2 = false;
|
|
if (i != 0) {
|
|
if (i < 0) {
|
|
i *= -1;
|
|
z2 = true;
|
|
}
|
|
this.constantValue = (float) i;
|
|
}
|
|
if (!z2) {
|
|
this.variables.put(solverVariable, -1.0f);
|
|
this.variables.put(solverVariable2, 1.0f);
|
|
this.variables.put(solverVariable3, -1.0f);
|
|
} else {
|
|
this.variables.put(solverVariable, 1.0f);
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variables.put(solverVariable3, 1.0f);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ArrayRow createRowWithAngle(SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, SolverVariable solverVariable4, float f) {
|
|
this.variables.put(solverVariable3, 0.5f);
|
|
this.variables.put(solverVariable4, 0.5f);
|
|
this.variables.put(solverVariable, -0.5f);
|
|
this.variables.put(solverVariable2, -0.5f);
|
|
this.constantValue = -f;
|
|
return this;
|
|
}
|
|
|
|
public void ensurePositiveConstant() {
|
|
float f = this.constantValue;
|
|
if (f < 0.0f) {
|
|
this.constantValue = f * -1.0f;
|
|
this.variables.invert();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public SolverVariable getKey() {
|
|
return this.variable;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public SolverVariable getPivotCandidate(LinearSystem linearSystem, boolean[] zArr) {
|
|
return pickPivotInVariables(zArr, null);
|
|
}
|
|
|
|
public boolean hasKeyVariable() {
|
|
SolverVariable solverVariable = this.variable;
|
|
return solverVariable != null && (solverVariable.mType == SolverVariable.Type.UNRESTRICTED || this.constantValue >= 0.0f);
|
|
}
|
|
|
|
public boolean hasVariable(SolverVariable solverVariable) {
|
|
return this.variables.contains(solverVariable);
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void initFromRow(LinearSystem.Row row) {
|
|
if (row instanceof ArrayRow) {
|
|
ArrayRow arrayRow = (ArrayRow) row;
|
|
this.variable = null;
|
|
this.variables.clear();
|
|
for (int i = 0; i < arrayRow.variables.getCurrentSize(); i++) {
|
|
this.variables.add(arrayRow.variables.getVariable(i), arrayRow.variables.getVariableValue(i), true);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public boolean isEmpty() {
|
|
return this.variable == null && this.constantValue == 0.0f && this.variables.getCurrentSize() == 0;
|
|
}
|
|
|
|
public SolverVariable pickPivot(SolverVariable solverVariable) {
|
|
return pickPivotInVariables(null, solverVariable);
|
|
}
|
|
|
|
public void pivot(SolverVariable solverVariable) {
|
|
SolverVariable solverVariable2 = this.variable;
|
|
if (solverVariable2 != null) {
|
|
this.variables.put(solverVariable2, -1.0f);
|
|
this.variable.definitionId = -1;
|
|
this.variable = null;
|
|
}
|
|
float remove = this.variables.remove(solverVariable, true) * -1.0f;
|
|
this.variable = solverVariable;
|
|
if (remove != 1.0f) {
|
|
this.constantValue /= remove;
|
|
this.variables.divideByAmount(remove);
|
|
}
|
|
}
|
|
|
|
public void reset() {
|
|
this.variable = null;
|
|
this.variables.clear();
|
|
this.constantValue = 0.0f;
|
|
this.isSimpleDefinition = false;
|
|
}
|
|
|
|
public int sizeInBytes() {
|
|
return this.variables.sizeInBytes() + (this.variable != null ? 4 : 0) + 4 + 4;
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:25:0x007a */
|
|
/* JADX WARNING: Removed duplicated region for block: B:26:0x007f */
|
|
public String toReadableString() {
|
|
String str;
|
|
boolean z2;
|
|
float variableValue;
|
|
int i;
|
|
if (this.variable == null) {
|
|
str = "0";
|
|
} else {
|
|
StringBuilder R = a.R("");
|
|
R.append(this.variable);
|
|
str = R.toString();
|
|
}
|
|
String v = a.v(str, " = ");
|
|
if (this.constantValue != 0.0f) {
|
|
StringBuilder R2 = a.R(v);
|
|
R2.append(this.constantValue);
|
|
v = R2.toString();
|
|
z2 = true;
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
int currentSize = this.variables.getCurrentSize();
|
|
for (int i2 = 0; i2 < currentSize; i2++) {
|
|
SolverVariable variable = this.variables.getVariable(i2);
|
|
if (!(variable == null || (variableValue = this.variables.getVariableValue(i2)) == 0.0f)) {
|
|
String solverVariable = variable.toString();
|
|
if (!z2) {
|
|
if (variableValue < 0.0f) {
|
|
v = a.v(v, "- ");
|
|
}
|
|
v = variableValue == 1.0f ? a.v(v, solverVariable) : v + variableValue + " " + solverVariable;
|
|
z2 = true;
|
|
} else if (i > 0) {
|
|
v = a.v(v, " + ");
|
|
if (variableValue == 1.0f) {
|
|
}
|
|
z2 = true;
|
|
} else {
|
|
v = a.v(v, " - ");
|
|
}
|
|
variableValue *= -1.0f;
|
|
if (variableValue == 1.0f) {
|
|
}
|
|
z2 = true;
|
|
}
|
|
}
|
|
return !z2 ? a.v(v, "0.0") : v;
|
|
}
|
|
|
|
public String toString() {
|
|
return toReadableString();
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void updateFromFinalVariable(LinearSystem linearSystem, SolverVariable solverVariable, boolean z2) {
|
|
if (solverVariable.isFinalValue) {
|
|
float f = this.variables.get(solverVariable);
|
|
this.constantValue = (solverVariable.computedValue * f) + this.constantValue;
|
|
this.variables.remove(solverVariable, z2);
|
|
if (z2) {
|
|
solverVariable.removeFromRow(this);
|
|
}
|
|
if (LinearSystem.SIMPLIFY_SYNONYMS && this.variables.getCurrentSize() == 0) {
|
|
this.isSimpleDefinition = true;
|
|
linearSystem.hasSimpleDefinition = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void updateFromRow(LinearSystem linearSystem, ArrayRow arrayRow, boolean z2) {
|
|
float use = this.variables.use(arrayRow, z2);
|
|
this.constantValue = (arrayRow.constantValue * use) + this.constantValue;
|
|
if (z2) {
|
|
arrayRow.variable.removeFromRow(this);
|
|
}
|
|
if (LinearSystem.SIMPLIFY_SYNONYMS && this.variable != null && this.variables.getCurrentSize() == 0) {
|
|
this.isSimpleDefinition = true;
|
|
linearSystem.hasSimpleDefinition = true;
|
|
}
|
|
}
|
|
|
|
public void updateFromSynonymVariable(LinearSystem linearSystem, SolverVariable solverVariable, boolean z2) {
|
|
if (solverVariable.isSynonym) {
|
|
float f = this.variables.get(solverVariable);
|
|
this.constantValue = (solverVariable.synonymDelta * f) + this.constantValue;
|
|
this.variables.remove(solverVariable, z2);
|
|
if (z2) {
|
|
solverVariable.removeFromRow(this);
|
|
}
|
|
this.variables.add(linearSystem.mCache.mIndexedVariables[solverVariable.synonym], f, z2);
|
|
if (LinearSystem.SIMPLIFY_SYNONYMS && this.variables.getCurrentSize() == 0) {
|
|
this.isSimpleDefinition = true;
|
|
linearSystem.hasSimpleDefinition = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.LinearSystem.Row
|
|
public void updateFromSystem(LinearSystem linearSystem) {
|
|
if (linearSystem.mRows.length != 0) {
|
|
boolean z2 = false;
|
|
while (!z2) {
|
|
int currentSize = this.variables.getCurrentSize();
|
|
for (int i = 0; i < currentSize; i++) {
|
|
SolverVariable variable = this.variables.getVariable(i);
|
|
if (variable.definitionId != -1 || variable.isFinalValue || variable.isSynonym) {
|
|
this.variablesToUpdate.add(variable);
|
|
}
|
|
}
|
|
int size = this.variablesToUpdate.size();
|
|
if (size > 0) {
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
SolverVariable solverVariable = this.variablesToUpdate.get(i2);
|
|
if (solverVariable.isFinalValue) {
|
|
updateFromFinalVariable(linearSystem, solverVariable, true);
|
|
} else if (solverVariable.isSynonym) {
|
|
updateFromSynonymVariable(linearSystem, solverVariable, true);
|
|
} else {
|
|
updateFromRow(linearSystem, linearSystem.mRows[solverVariable.definitionId], true);
|
|
}
|
|
}
|
|
this.variablesToUpdate.clear();
|
|
} else {
|
|
z2 = true;
|
|
}
|
|
}
|
|
if (LinearSystem.SIMPLIFY_SYNONYMS && this.variable != null && this.variables.getCurrentSize() == 0) {
|
|
this.isSimpleDefinition = true;
|
|
linearSystem.hasSimpleDefinition = true;
|
|
}
|
|
}
|
|
}
|
|
}
|