mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Factor out and clarify cross product computation and its use, so it can be reused elsewhere.
git-svn-id: https://zxing.googlecode.com/svn/trunk@527 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
cebac631ac
commit
a43e928575
|
@ -92,8 +92,10 @@ public final class GenericResultPoint implements ResultPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use cross product to figure out whether A and C are correct or flipped.
|
// Use cross product to figure out whether A and C are correct or flipped.
|
||||||
if ((pointC.getY() - pointB.getY()) * (pointA.getX() - pointB.getX()) >
|
// This asks whether BC x BA has a positive z component, which is the arrangement
|
||||||
(pointC.getX() - pointB.getX()) * (pointA.getY() - pointB.getY())) {
|
// we want for A, B, C. If it's negative, then we've got it flipped around and
|
||||||
|
// should swap A and C.
|
||||||
|
if (crossProductZ(pointA, pointB, pointC) < 0.0f) {
|
||||||
ResultPoint temp = pointA;
|
ResultPoint temp = pointA;
|
||||||
pointA = pointC;
|
pointA = pointC;
|
||||||
pointC = temp;
|
pointC = temp;
|
||||||
|
@ -114,4 +116,13 @@ public final class GenericResultPoint implements ResultPoint {
|
||||||
return (float) Math.sqrt((double) (xDiff * xDiff + yDiff * yDiff));
|
return (float) Math.sqrt((double) (xDiff * xDiff + yDiff * yDiff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the z component of the cross product between vectors BC and BA.
|
||||||
|
*/
|
||||||
|
public static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC) {
|
||||||
|
float bX = pointB.getX();
|
||||||
|
float bY = pointB.getY();
|
||||||
|
return ((pointC.getX() - bX) * (pointA.getY() - bY)) - ((pointC.getY() - bY) * (pointA.getX() - bX));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue