mirror of
https://github.com/zxing/zxing.git
synced 2025-02-21 02:55:27 -08:00
Avoid tiny Array.sort; a bottleneck
This commit is contained in:
parent
05abe0f7aa
commit
f8df5f0ca2
|
@ -624,7 +624,6 @@ public class FinderPatternFinder {
|
||||||
possibleCenters.sort(moduleComparator);
|
possibleCenters.sort(moduleComparator);
|
||||||
|
|
||||||
double distortion = Double.MAX_VALUE;
|
double distortion = Double.MAX_VALUE;
|
||||||
double[] squares = new double[3];
|
|
||||||
FinderPattern[] bestPatterns = new FinderPattern[3];
|
FinderPattern[] bestPatterns = new FinderPattern[3];
|
||||||
|
|
||||||
for (int i = 0; i < possibleCenters.size() - 2; i++) {
|
for (int i = 0; i < possibleCenters.size() - 2; i++) {
|
||||||
|
@ -643,17 +642,49 @@ public class FinderPatternFinder {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
squares[0] = squares0;
|
double a = squares0;
|
||||||
squares[1] = squaredDistance(fpj, fpk);
|
double b = squaredDistance(fpj, fpk);
|
||||||
squares[2] = squaredDistance(fpi, fpk);
|
double c = squaredDistance(fpi, fpk);
|
||||||
Arrays.sort(squares);
|
|
||||||
|
// sorts ascending - inlined
|
||||||
|
if (a < b) {
|
||||||
|
if (b > c) {
|
||||||
|
if (a < c) {
|
||||||
|
double temp = b;
|
||||||
|
b = c;
|
||||||
|
c = temp;
|
||||||
|
} else {
|
||||||
|
double temp = a;
|
||||||
|
a = c;
|
||||||
|
c = b;
|
||||||
|
b = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (b < c) {
|
||||||
|
if (a < c) {
|
||||||
|
double temp = a;
|
||||||
|
a = b;
|
||||||
|
b = temp;
|
||||||
|
} else {
|
||||||
|
double temp = a;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
c = temp;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
double temp = a;
|
||||||
|
a = c;
|
||||||
|
c = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// a^2 + b^2 = c^2 (Pythagorean theorem), and a = b (isosceles triangle).
|
// a^2 + b^2 = c^2 (Pythagorean theorem), and a = b (isosceles triangle).
|
||||||
// Since any right triangle satisfies the formula c^2 - b^2 - a^2 = 0,
|
// Since any right triangle satisfies the formula c^2 - b^2 - a^2 = 0,
|
||||||
// we need to check both two equal sides separately.
|
// we need to check both two equal sides separately.
|
||||||
// The value of |c^2 - 2 * b^2| + |c^2 - 2 * a^2| increases as dissimilarity
|
// The value of |c^2 - 2 * b^2| + |c^2 - 2 * a^2| increases as dissimilarity
|
||||||
// from isosceles right triangle.
|
// from isosceles right triangle.
|
||||||
double d = Math.abs(squares[2] - 2 * squares[1]) + Math.abs(squares[2] - 2 * squares[0]);
|
double d = Math.abs(c - 2 * b) + Math.abs(c - 2 * a);
|
||||||
if (d < distortion) {
|
if (d < distortion) {
|
||||||
distortion = d;
|
distortion = d;
|
||||||
bestPatterns[0] = fpi;
|
bestPatterns[0] = fpi;
|
||||||
|
|
Loading…
Reference in a new issue