what-the-bank/sources/com/kofax/kmc/ken/engines/a.java

144 lines
5.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.ken.engines;
import android.graphics.Point;
import android.graphics.Rect;
import com.kofax.kmc.ken.engines.data.BoundingTetragon;
import java.lang.reflect.Array;
/* loaded from: classes3.dex */
class a implements IBoundingRectCalculator {
@Override // com.kofax.kmc.ken.engines.IBoundingRectCalculator
public Rect calculate(BoundingTetragon boundingTetragon) {
BoundingTetragon a;
if (!a(boundingTetragon)) {
boundingTetragon = b(boundingTetragon);
}
Point point = new Point(0, 0);
double a2 = a(boundingTetragon.getBottomLeft(), boundingTetragon.getTopLeft());
if (a2 <= 0.7853981633974483d) {
a = a(boundingTetragon, point, -a2);
} else {
a = a(boundingTetragon, point, 1.5707963267948966d - a2);
}
int[] c = c(a);
return new Rect(c[0], c[1], c[2], c[3]);
}
private static boolean a(BoundingTetragon boundingTetragon) {
Point point = new Point();
point.x = boundingTetragon.getBottomLeft().x + boundingTetragon.getBottomRight().x + boundingTetragon.getTopLeft().x + boundingTetragon.getTopRight().x;
point.y = boundingTetragon.getBottomLeft().y + boundingTetragon.getBottomRight().y + boundingTetragon.getTopLeft().y + boundingTetragon.getTopRight().y;
point.x /= 4;
point.y /= 4;
double b = b(point, boundingTetragon.getBottomLeft());
return Math.abs(b - b(point, boundingTetragon.getBottomLeft())) <= 1.0d && Math.abs(b - b(point, boundingTetragon.getBottomRight())) <= 1.0d && Math.abs(b - b(point, boundingTetragon.getTopLeft())) <= 1.0d && Math.abs(b - b(point, boundingTetragon.getTopRight())) <= 1.0d;
}
private static BoundingTetragon b(BoundingTetragon boundingTetragon) {
Point[] pointArr = {boundingTetragon.getBottomLeft(), boundingTetragon.getTopLeft(), boundingTetragon.getTopRight(), boundingTetragon.getBottomRight()};
Point[] pointArr2 = new Point[4];
Point[] pointArr3 = new Point[4];
pointArr3[0] = pointArr[0];
for (int i = 1; i < 4; i++) {
pointArr3[i] = pointArr[i];
pointArr2[i] = pointArr3[i - 1];
}
pointArr2[0] = pointArr[3];
double[] dArr = new double[4];
double[] dArr2 = new double[4];
Point[][] pointArr4 = (Point[][]) Array.newInstance((Class<?>) Point.class, 4, 4);
for (int i2 = 0; i2 < 4; i2++) {
dArr[i2] = Math.atan2(pointArr3[i2].y - pointArr2[i2].y, pointArr3[i2].x - pointArr2[i2].x);
Point[] d = d(a(boundingTetragon, new Point(0, 0), -dArr[i2]));
pointArr4[i2] = d;
Point point = d[1];
Point point2 = d[3];
dArr2[i2] = (point2.x - point.x) * (point2.y - point.y);
}
double d2 = Double.MAX_VALUE;
int i3 = 0;
for (int i4 = 0; i4 < 4; i4++) {
double d3 = dArr2[i4];
if (d3 < d2) {
i3 = i4;
d2 = d3;
}
}
BoundingTetragon boundingTetragon2 = new BoundingTetragon();
boundingTetragon2.setBottomLeft(pointArr4[i3][0]);
boundingTetragon2.setTopLeft(pointArr4[i3][1]);
boundingTetragon2.setTopRight(pointArr4[i3][2]);
boundingTetragon2.setBottomRight(pointArr4[i3][3]);
return a(boundingTetragon2, new Point(0, 0), dArr[i3]);
}
private static double a(Point point, Point point2) {
return (Math.atan2(point2.y - point.y, point2.x - point.x) + 3.141592653589793d) % 1.5707963267948966d;
}
private static BoundingTetragon a(BoundingTetragon boundingTetragon, Point point, double d) {
BoundingTetragon boundingTetragon2 = new BoundingTetragon();
double sin = Math.sin(d);
double cos = Math.cos(d);
boundingTetragon2.setBottomLeft(a(boundingTetragon.getBottomLeft(), point, sin, cos));
boundingTetragon2.setBottomRight(a(boundingTetragon.getBottomRight(), point, sin, cos));
boundingTetragon2.setTopLeft(a(boundingTetragon.getTopLeft(), point, sin, cos));
boundingTetragon2.setTopRight(a(boundingTetragon.getTopRight(), point, sin, cos));
return boundingTetragon2;
}
private static int[] c(BoundingTetragon boundingTetragon) {
int[] iArr = new int[4];
Point[] pointArr = {boundingTetragon.getBottomLeft(), boundingTetragon.getBottomRight(), boundingTetragon.getTopRight(), boundingTetragon.getTopLeft()};
int i = Integer.MAX_VALUE;
int i2 = Integer.MIN_VALUE;
int i3 = Integer.MIN_VALUE;
int i4 = Integer.MAX_VALUE;
for (int i5 = 0; i5 < 4; i5++) {
if (pointArr[i5].x < i) {
i = pointArr[i5].x;
}
if (pointArr[i5].y < i4) {
i4 = pointArr[i5].y;
}
if (pointArr[i5].x > i2) {
i2 = pointArr[i5].x;
}
if (pointArr[i5].y > i3) {
i3 = pointArr[i5].y;
}
}
iArr[0] = i;
iArr[1] = i4;
iArr[2] = i2;
iArr[3] = i3;
return iArr;
}
private static Point a(Point point, Point point2, double d, double d2) {
Point point3 = new Point();
point.x -= point2.x;
point.y -= point2.y;
double d3 = point.x;
double d4 = point.y;
double d5 = point.x;
double d6 = point.y;
point3.x = (int) Math.ceil((d3 * d2) - (d4 * d));
point3.y = (int) Math.ceil((d5 * d) + (d6 * d2));
point3.x += point2.x;
point3.y += point2.y;
return point3;
}
private static double b(Point point, Point point2) {
double d = point2.x - point.x;
double d2 = point2.y - point.y;
return (d * d) + (d2 * d2);
}
private static Point[] d(BoundingTetragon boundingTetragon) {
int[] c = c(boundingTetragon);
return new Point[]{new Point(c[0], c[3]), new Point(c[0], c[1]), new Point(c[2], c[1]), new Point(c[2], c[3])};
}
}