678 lines
19 KiB
Java
678 lines
19 KiB
Java
package androidx.constraintlayout.solver;
|
|
|
|
import androidx.constraintlayout.solver.SolverVariable;
|
|
import androidx.constraintlayout.solver.widgets.ConstraintAnchor;
|
|
import androidx.constraintlayout.solver.widgets.ConstraintWidget;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class LinearSystem {
|
|
private static int p = 1000;
|
|
public static Metrics q;
|
|
private Row c;
|
|
private int e;
|
|
ArrayRow[] f;
|
|
public boolean g;
|
|
private boolean[] h;
|
|
int i;
|
|
int j;
|
|
private int k;
|
|
final Cache l;
|
|
private SolverVariable[] m;
|
|
private int n;
|
|
private final Row o;
|
|
int a = 0;
|
|
private HashMap<String, SolverVariable> b = null;
|
|
private int d = 32;
|
|
|
|
interface Row {
|
|
SolverVariable a(LinearSystem linearSystem, boolean[] zArr);
|
|
|
|
void a(Row row);
|
|
|
|
void a(SolverVariable solverVariable);
|
|
|
|
void clear();
|
|
|
|
SolverVariable getKey();
|
|
}
|
|
|
|
public LinearSystem() {
|
|
int i = this.d;
|
|
this.e = i;
|
|
this.f = null;
|
|
this.g = false;
|
|
this.h = new boolean[i];
|
|
this.i = 1;
|
|
this.j = 0;
|
|
this.k = i;
|
|
this.m = new SolverVariable[p];
|
|
this.n = 0;
|
|
ArrayRow[] arrayRowArr = new ArrayRow[i];
|
|
this.f = new ArrayRow[i];
|
|
j();
|
|
this.l = new Cache();
|
|
this.c = new GoalRow(this.l);
|
|
this.o = new ArrayRow(this.l);
|
|
}
|
|
|
|
private final void d(ArrayRow arrayRow) {
|
|
if (this.j > 0) {
|
|
arrayRow.d.a(arrayRow, this.f);
|
|
if (arrayRow.d.a == 0) {
|
|
arrayRow.e = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void g() {
|
|
for (int i = 0; i < this.j; i++) {
|
|
ArrayRow arrayRow = this.f[i];
|
|
arrayRow.a.e = arrayRow.b;
|
|
}
|
|
}
|
|
|
|
public static Metrics h() {
|
|
return q;
|
|
}
|
|
|
|
private void i() {
|
|
this.d *= 2;
|
|
this.f = (ArrayRow[]) Arrays.copyOf(this.f, this.d);
|
|
Cache cache = this.l;
|
|
cache.c = (SolverVariable[]) Arrays.copyOf(cache.c, this.d);
|
|
int i = this.d;
|
|
this.h = new boolean[i];
|
|
this.e = i;
|
|
this.k = i;
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.d++;
|
|
metrics.o = Math.max(metrics.o, i);
|
|
Metrics metrics2 = q;
|
|
metrics2.A = metrics2.o;
|
|
}
|
|
}
|
|
|
|
private void j() {
|
|
int i = 0;
|
|
while (true) {
|
|
ArrayRow[] arrayRowArr = this.f;
|
|
if (i >= arrayRowArr.length) {
|
|
return;
|
|
}
|
|
ArrayRow arrayRow = arrayRowArr[i];
|
|
if (arrayRow != null) {
|
|
this.l.a.a(arrayRow);
|
|
}
|
|
this.f[i] = null;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public SolverVariable a(Object obj) {
|
|
SolverVariable solverVariable = null;
|
|
if (obj == null) {
|
|
return null;
|
|
}
|
|
if (this.i + 1 >= this.e) {
|
|
i();
|
|
}
|
|
if (obj instanceof ConstraintAnchor) {
|
|
ConstraintAnchor constraintAnchor = (ConstraintAnchor) obj;
|
|
solverVariable = constraintAnchor.e();
|
|
if (solverVariable == null) {
|
|
constraintAnchor.a(this.l);
|
|
solverVariable = constraintAnchor.e();
|
|
}
|
|
int i = solverVariable.b;
|
|
if (i == -1 || i > this.a || this.l.c[i] == null) {
|
|
if (solverVariable.b != -1) {
|
|
solverVariable.a();
|
|
}
|
|
this.a++;
|
|
this.i++;
|
|
int i2 = this.a;
|
|
solverVariable.b = i2;
|
|
solverVariable.g = SolverVariable.Type.UNRESTRICTED;
|
|
this.l.c[i2] = solverVariable;
|
|
}
|
|
}
|
|
return solverVariable;
|
|
}
|
|
|
|
public ArrayRow b() {
|
|
ArrayRow a = this.l.a.a();
|
|
if (a == null) {
|
|
a = new ArrayRow(this.l);
|
|
} else {
|
|
a.d();
|
|
}
|
|
SolverVariable.b();
|
|
return a;
|
|
}
|
|
|
|
public SolverVariable c() {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.m++;
|
|
}
|
|
if (this.i + 1 >= this.e) {
|
|
i();
|
|
}
|
|
SolverVariable a = a(SolverVariable.Type.SLACK, (String) null);
|
|
this.a++;
|
|
this.i++;
|
|
int i = this.a;
|
|
a.b = i;
|
|
this.l.c[i] = a;
|
|
return a;
|
|
}
|
|
|
|
public void e() throws Exception {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.e++;
|
|
}
|
|
if (!this.g) {
|
|
a(this.c);
|
|
return;
|
|
}
|
|
Metrics metrics2 = q;
|
|
if (metrics2 != null) {
|
|
metrics2.q++;
|
|
}
|
|
boolean z = false;
|
|
int i = 0;
|
|
while (true) {
|
|
if (i >= this.j) {
|
|
z = true;
|
|
break;
|
|
} else if (!this.f[i].e) {
|
|
break;
|
|
} else {
|
|
i++;
|
|
}
|
|
}
|
|
if (!z) {
|
|
a(this.c);
|
|
return;
|
|
}
|
|
Metrics metrics3 = q;
|
|
if (metrics3 != null) {
|
|
metrics3.p++;
|
|
}
|
|
g();
|
|
}
|
|
|
|
public void f() {
|
|
Cache cache;
|
|
int i = 0;
|
|
while (true) {
|
|
cache = this.l;
|
|
SolverVariable[] solverVariableArr = cache.c;
|
|
if (i >= solverVariableArr.length) {
|
|
break;
|
|
}
|
|
SolverVariable solverVariable = solverVariableArr[i];
|
|
if (solverVariable != null) {
|
|
solverVariable.a();
|
|
}
|
|
i++;
|
|
}
|
|
cache.b.a(this.m, this.n);
|
|
this.n = 0;
|
|
Arrays.fill(this.l.c, (Object) null);
|
|
HashMap<String, SolverVariable> hashMap = this.b;
|
|
if (hashMap != null) {
|
|
hashMap.clear();
|
|
}
|
|
this.a = 0;
|
|
this.c.clear();
|
|
this.i = 1;
|
|
for (int i2 = 0; i2 < this.j; i2++) {
|
|
this.f[i2].c = false;
|
|
}
|
|
j();
|
|
this.j = 0;
|
|
}
|
|
|
|
private void b(ArrayRow arrayRow) {
|
|
arrayRow.a(this, 0);
|
|
}
|
|
|
|
public Cache d() {
|
|
return this.l;
|
|
}
|
|
|
|
public int b(Object obj) {
|
|
SolverVariable e = ((ConstraintAnchor) obj).e();
|
|
if (e != null) {
|
|
return (int) (e.e + 0.5f);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private int b(Row row) throws Exception {
|
|
float f;
|
|
boolean z;
|
|
int i = 0;
|
|
while (true) {
|
|
f = 0.0f;
|
|
if (i >= this.j) {
|
|
z = false;
|
|
break;
|
|
}
|
|
ArrayRow[] arrayRowArr = this.f;
|
|
if (arrayRowArr[i].a.g != SolverVariable.Type.UNRESTRICTED && arrayRowArr[i].b < 0.0f) {
|
|
z = true;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if (!z) {
|
|
return 0;
|
|
}
|
|
boolean z2 = false;
|
|
int i2 = 0;
|
|
while (!z2) {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.k++;
|
|
}
|
|
i2++;
|
|
int i3 = 0;
|
|
int i4 = -1;
|
|
int i5 = -1;
|
|
float f2 = Float.MAX_VALUE;
|
|
int i6 = 0;
|
|
while (i3 < this.j) {
|
|
ArrayRow arrayRow = this.f[i3];
|
|
if (arrayRow.a.g != SolverVariable.Type.UNRESTRICTED && !arrayRow.e && arrayRow.b < f) {
|
|
int i7 = 1;
|
|
while (i7 < this.i) {
|
|
SolverVariable solverVariable = this.l.c[i7];
|
|
float b = arrayRow.d.b(solverVariable);
|
|
if (b > f) {
|
|
int i8 = i6;
|
|
float f3 = f2;
|
|
int i9 = i5;
|
|
int i10 = i4;
|
|
for (int i11 = 0; i11 < 7; i11++) {
|
|
float f4 = solverVariable.f[i11] / b;
|
|
if ((f4 < f3 && i11 == i8) || i11 > i8) {
|
|
i9 = i7;
|
|
i10 = i3;
|
|
f3 = f4;
|
|
i8 = i11;
|
|
}
|
|
}
|
|
i4 = i10;
|
|
i5 = i9;
|
|
f2 = f3;
|
|
i6 = i8;
|
|
}
|
|
i7++;
|
|
f = 0.0f;
|
|
}
|
|
}
|
|
i3++;
|
|
f = 0.0f;
|
|
}
|
|
if (i4 != -1) {
|
|
ArrayRow arrayRow2 = this.f[i4];
|
|
arrayRow2.a.c = -1;
|
|
Metrics metrics2 = q;
|
|
if (metrics2 != null) {
|
|
metrics2.j++;
|
|
}
|
|
arrayRow2.d(this.l.c[i5]);
|
|
SolverVariable solverVariable2 = arrayRow2.a;
|
|
solverVariable2.c = i4;
|
|
solverVariable2.c(arrayRow2);
|
|
} else {
|
|
z2 = true;
|
|
}
|
|
if (i2 > this.i / 2) {
|
|
z2 = true;
|
|
}
|
|
f = 0.0f;
|
|
}
|
|
return i2;
|
|
}
|
|
|
|
private final void c(ArrayRow arrayRow) {
|
|
ArrayRow[] arrayRowArr = this.f;
|
|
int i = this.j;
|
|
if (arrayRowArr[i] != null) {
|
|
this.l.a.a(arrayRowArr[i]);
|
|
}
|
|
ArrayRow[] arrayRowArr2 = this.f;
|
|
int i2 = this.j;
|
|
arrayRowArr2[i2] = arrayRow;
|
|
SolverVariable solverVariable = arrayRow.a;
|
|
solverVariable.c = i2;
|
|
this.j = i2 + 1;
|
|
solverVariable.c(arrayRow);
|
|
}
|
|
|
|
public SolverVariable a() {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.n++;
|
|
}
|
|
if (this.i + 1 >= this.e) {
|
|
i();
|
|
}
|
|
SolverVariable a = a(SolverVariable.Type.SLACK, (String) null);
|
|
this.a++;
|
|
this.i++;
|
|
int i = this.a;
|
|
a.b = i;
|
|
this.l.c[i] = a;
|
|
return a;
|
|
}
|
|
|
|
public void c(SolverVariable solverVariable, SolverVariable solverVariable2, int i, int i2) {
|
|
ArrayRow b = b();
|
|
SolverVariable c = c();
|
|
c.d = 0;
|
|
b.b(solverVariable, solverVariable2, c, i);
|
|
if (i2 != 6) {
|
|
a(b, (int) (b.d.b(c) * (-1.0f)), i2);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
void a(ArrayRow arrayRow, int i, int i2) {
|
|
arrayRow.a(a(i2, (String) null), i);
|
|
}
|
|
|
|
public SolverVariable a(int i, String str) {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.l++;
|
|
}
|
|
if (this.i + 1 >= this.e) {
|
|
i();
|
|
}
|
|
SolverVariable a = a(SolverVariable.Type.ERROR, str);
|
|
this.a++;
|
|
this.i++;
|
|
int i2 = this.a;
|
|
a.b = i2;
|
|
a.d = i;
|
|
this.l.c[i2] = a;
|
|
this.c.a(a);
|
|
return a;
|
|
}
|
|
|
|
public void b(SolverVariable solverVariable, SolverVariable solverVariable2, int i, int i2) {
|
|
ArrayRow b = b();
|
|
SolverVariable c = c();
|
|
c.d = 0;
|
|
b.a(solverVariable, solverVariable2, c, i);
|
|
if (i2 != 6) {
|
|
a(b, (int) (b.d.b(c) * (-1.0f)), i2);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
private SolverVariable a(SolverVariable.Type type, String str) {
|
|
SolverVariable a = this.l.b.a();
|
|
if (a == null) {
|
|
a = new SolverVariable(type, str);
|
|
a.a(type, str);
|
|
} else {
|
|
a.a();
|
|
a.a(type, str);
|
|
}
|
|
int i = this.n;
|
|
int i2 = p;
|
|
if (i >= i2) {
|
|
p = i2 * 2;
|
|
this.m = (SolverVariable[]) Arrays.copyOf(this.m, p);
|
|
}
|
|
SolverVariable[] solverVariableArr = this.m;
|
|
int i3 = this.n;
|
|
this.n = i3 + 1;
|
|
solverVariableArr[i3] = a;
|
|
return a;
|
|
}
|
|
|
|
public void b(SolverVariable solverVariable, SolverVariable solverVariable2, boolean z) {
|
|
ArrayRow b = b();
|
|
SolverVariable c = c();
|
|
c.d = 0;
|
|
b.b(solverVariable, solverVariable2, c, 0);
|
|
if (z) {
|
|
a(b, (int) (b.d.b(c) * (-1.0f)), 1);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
void a(Row row) throws Exception {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.s++;
|
|
metrics.t = Math.max(metrics.t, this.i);
|
|
Metrics metrics2 = q;
|
|
metrics2.u = Math.max(metrics2.u, this.j);
|
|
}
|
|
d((ArrayRow) row);
|
|
b(row);
|
|
a(row, false);
|
|
g();
|
|
}
|
|
|
|
public void a(ArrayRow arrayRow) {
|
|
SolverVariable c;
|
|
if (arrayRow == null) {
|
|
return;
|
|
}
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.f++;
|
|
if (arrayRow.e) {
|
|
metrics.g++;
|
|
}
|
|
}
|
|
if (this.j + 1 >= this.k || this.i + 1 >= this.e) {
|
|
i();
|
|
}
|
|
boolean z = false;
|
|
if (!arrayRow.e) {
|
|
d(arrayRow);
|
|
if (arrayRow.c()) {
|
|
return;
|
|
}
|
|
arrayRow.a();
|
|
if (arrayRow.a(this)) {
|
|
SolverVariable a = a();
|
|
arrayRow.a = a;
|
|
c(arrayRow);
|
|
this.o.a(arrayRow);
|
|
a(this.o, true);
|
|
if (a.c == -1) {
|
|
if (arrayRow.a == a && (c = arrayRow.c(a)) != null) {
|
|
Metrics metrics2 = q;
|
|
if (metrics2 != null) {
|
|
metrics2.j++;
|
|
}
|
|
arrayRow.d(c);
|
|
}
|
|
if (!arrayRow.e) {
|
|
arrayRow.a.c(arrayRow);
|
|
}
|
|
this.j--;
|
|
}
|
|
z = true;
|
|
}
|
|
if (!arrayRow.b()) {
|
|
return;
|
|
}
|
|
}
|
|
if (z) {
|
|
return;
|
|
}
|
|
c(arrayRow);
|
|
}
|
|
|
|
private final int a(Row row, boolean z) {
|
|
Metrics metrics = q;
|
|
if (metrics != null) {
|
|
metrics.h++;
|
|
}
|
|
for (int i = 0; i < this.i; i++) {
|
|
this.h[i] = false;
|
|
}
|
|
boolean z2 = false;
|
|
int i2 = 0;
|
|
while (!z2) {
|
|
Metrics metrics2 = q;
|
|
if (metrics2 != null) {
|
|
metrics2.i++;
|
|
}
|
|
i2++;
|
|
if (i2 >= this.i * 2) {
|
|
return i2;
|
|
}
|
|
if (row.getKey() != null) {
|
|
this.h[row.getKey().b] = true;
|
|
}
|
|
SolverVariable a = row.a(this, this.h);
|
|
if (a != null) {
|
|
boolean[] zArr = this.h;
|
|
int i3 = a.b;
|
|
if (zArr[i3]) {
|
|
return i2;
|
|
}
|
|
zArr[i3] = true;
|
|
}
|
|
if (a != null) {
|
|
int i4 = -1;
|
|
float f = Float.MAX_VALUE;
|
|
for (int i5 = 0; i5 < this.j; i5++) {
|
|
ArrayRow arrayRow = this.f[i5];
|
|
if (arrayRow.a.g != SolverVariable.Type.UNRESTRICTED && !arrayRow.e && arrayRow.b(a)) {
|
|
float b = arrayRow.d.b(a);
|
|
if (b < 0.0f) {
|
|
float f2 = (-arrayRow.b) / b;
|
|
if (f2 < f) {
|
|
i4 = i5;
|
|
f = f2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (i4 > -1) {
|
|
ArrayRow arrayRow2 = this.f[i4];
|
|
arrayRow2.a.c = -1;
|
|
Metrics metrics3 = q;
|
|
if (metrics3 != null) {
|
|
metrics3.j++;
|
|
}
|
|
arrayRow2.d(a);
|
|
SolverVariable solverVariable = arrayRow2.a;
|
|
solverVariable.c = i4;
|
|
solverVariable.c(arrayRow2);
|
|
}
|
|
}
|
|
z2 = true;
|
|
}
|
|
return i2;
|
|
}
|
|
|
|
public void a(SolverVariable solverVariable, SolverVariable solverVariable2, boolean z) {
|
|
ArrayRow b = b();
|
|
SolverVariable c = c();
|
|
c.d = 0;
|
|
b.a(solverVariable, solverVariable2, c, 0);
|
|
if (z) {
|
|
a(b, (int) (b.d.b(c) * (-1.0f)), 1);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
public void a(SolverVariable solverVariable, SolverVariable solverVariable2, int i, float f, SolverVariable solverVariable3, SolverVariable solverVariable4, int i2, int i3) {
|
|
ArrayRow b = b();
|
|
b.a(solverVariable, solverVariable2, i, f, solverVariable3, solverVariable4, i2);
|
|
if (i3 != 6) {
|
|
b.a(this, i3);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
public void a(SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, SolverVariable solverVariable4, float f, int i) {
|
|
ArrayRow b = b();
|
|
b.a(solverVariable, solverVariable2, solverVariable3, solverVariable4, f);
|
|
if (i != 6) {
|
|
b.a(this, i);
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
public ArrayRow a(SolverVariable solverVariable, SolverVariable solverVariable2, int i, int i2) {
|
|
ArrayRow b = b();
|
|
b.a(solverVariable, solverVariable2, i);
|
|
if (i2 != 6) {
|
|
b.a(this, i2);
|
|
}
|
|
a(b);
|
|
return b;
|
|
}
|
|
|
|
public void a(SolverVariable solverVariable, int i) {
|
|
int i2 = solverVariable.c;
|
|
if (i2 != -1) {
|
|
ArrayRow arrayRow = this.f[i2];
|
|
if (arrayRow.e) {
|
|
arrayRow.b = i;
|
|
return;
|
|
}
|
|
if (arrayRow.d.a == 0) {
|
|
arrayRow.e = true;
|
|
arrayRow.b = i;
|
|
return;
|
|
} else {
|
|
ArrayRow b = b();
|
|
b.c(solverVariable, i);
|
|
a(b);
|
|
return;
|
|
}
|
|
}
|
|
ArrayRow b2 = b();
|
|
b2.b(solverVariable, i);
|
|
a(b2);
|
|
}
|
|
|
|
public static ArrayRow a(LinearSystem linearSystem, SolverVariable solverVariable, SolverVariable solverVariable2, SolverVariable solverVariable3, float f, boolean z) {
|
|
ArrayRow b = linearSystem.b();
|
|
if (z) {
|
|
linearSystem.b(b);
|
|
}
|
|
b.a(solverVariable, solverVariable2, solverVariable3, f);
|
|
return b;
|
|
}
|
|
|
|
public void a(ConstraintWidget constraintWidget, ConstraintWidget constraintWidget2, float f, int i) {
|
|
SolverVariable a = a(constraintWidget.a(ConstraintAnchor.Type.LEFT));
|
|
SolverVariable a2 = a(constraintWidget.a(ConstraintAnchor.Type.TOP));
|
|
SolverVariable a3 = a(constraintWidget.a(ConstraintAnchor.Type.RIGHT));
|
|
SolverVariable a4 = a(constraintWidget.a(ConstraintAnchor.Type.BOTTOM));
|
|
SolverVariable a5 = a(constraintWidget2.a(ConstraintAnchor.Type.LEFT));
|
|
SolverVariable a6 = a(constraintWidget2.a(ConstraintAnchor.Type.TOP));
|
|
SolverVariable a7 = a(constraintWidget2.a(ConstraintAnchor.Type.RIGHT));
|
|
SolverVariable a8 = a(constraintWidget2.a(ConstraintAnchor.Type.BOTTOM));
|
|
ArrayRow b = b();
|
|
double d = f;
|
|
double d2 = i;
|
|
b.b(a2, a4, a6, a8, (float) (Math.sin(d) * d2));
|
|
a(b);
|
|
ArrayRow b2 = b();
|
|
b2.b(a, a3, a5, a7, (float) (Math.cos(d) * d2));
|
|
a(b2);
|
|
}
|
|
}
|