+++ /dev/null
-/*\r
-* Copyright 2008 ZXing authors\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-namespace com.google.zxing.common\r
-{\r
- using System;\r
- using System.Text;\r
-\r
- /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
- /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
- /// *\r
- /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
- /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
- /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
- /// less memory and go with bytes.\r
- /// *\r
- /// </summary>\r
- /// <author> dswitkin@google.com (Daniel Switkin)\r
- /// \r
- /// </author>\r
- public sealed class GenericResultPoint : ResultPoint\r
- { \r
- private float posX;\r
- private float posY;\r
-\r
- public GenericResultPoint(float posX, float posY) {\r
- this.posX = posX;\r
- this.posY = posY;\r
- }\r
-\r
- public float getX() {\r
- return posX;\r
- }\r
-\r
- public float getY() {\r
- return posY;\r
- }\r
-\r
- public String toString() {\r
- StringBuilder result = new StringBuilder(25);\r
- result.Append('(');\r
- result.Append(posX);\r
- result.Append(',');\r
- result.Append(posY);\r
- result.Append(')');\r
- return result.ToString();\r
- }\r
-\r
- public bool equals(Object other) {\r
- \r
- if (other.GetType() == typeof(GenericResultPoint)) {\r
- GenericResultPoint otherPoint = (GenericResultPoint) other;\r
- return posX == otherPoint.posX && posY == otherPoint.posY;\r
- }\r
- return false;\r
- }\r
-\r
- public int hashCode() {\r
- return 31 * posX.GetHashCode() + posY.GetHashCode();\r
- }\r
-\r
- /**\r
- * <p>Orders an array of three ResultPoints in an order [A,B,C] such that AB < AC and\r
- * BC < AC and the angle between BC and BA is less than 180 degrees.\r
- */\r
- public static void orderBestPatterns(ResultPoint[] patterns) {\r
-\r
- // Find distances between pattern centers\r
- float zeroOneDistance = distance(patterns[0], patterns[1]);\r
- float oneTwoDistance = distance(patterns[1], patterns[2]);\r
- float zeroTwoDistance = distance(patterns[0], patterns[2]);\r
-\r
- ResultPoint pointA, pointB, pointC;\r
- // Assume one closest to other two is B; A and C will just be guesses at first\r
- if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) {\r
- pointB = patterns[0];\r
- pointA = patterns[1];\r
- pointC = patterns[2];\r
- } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) {\r
- pointB = patterns[1];\r
- pointA = patterns[0];\r
- pointC = patterns[2];\r
- } else {\r
- pointB = patterns[2];\r
- pointA = patterns[0];\r
- pointC = patterns[1];\r
- }\r
-\r
- // Use cross product to figure out whether A and C are correct or flipped.\r
- // This asks whether BC x BA has a positive z component, which is the arrangement\r
- // we want for A, B, C. If it's negative, then we've got it flipped around and\r
- // should swap A and C.\r
- if (crossProductZ(pointA, pointB, pointC) < 0.0f) {\r
- ResultPoint temp = pointA;\r
- pointA = pointC;\r
- pointC = temp;\r
- }\r
-\r
- patterns[0] = pointA;\r
- patterns[1] = pointB;\r
- patterns[2] = pointC;\r
- }\r
-\r
-\r
- /**\r
- * @return distance between two points\r
- */\r
- public static float distance(ResultPoint pattern1, ResultPoint pattern2) {\r
- float xDiff = pattern1.getX() - pattern2.getX();\r
- float yDiff = pattern1.getY() - pattern2.getY();\r
- return (float) Math.Sqrt((double) (xDiff * xDiff + yDiff * yDiff));\r
- }\r
-\r
- /**\r
- * Returns the z component of the cross product between vectors BC and BA.\r
- */\r
- public static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC) {\r
- float bX = pointB.getX();\r
- float bY = pointB.getY();\r
- return ((pointC.getX() - bX) * (pointA.getY() - bY)) - ((pointC.getY() - bY) * (pointA.getX() - bX));\r
- } \r
- \r
- }\r
-}
\ No newline at end of file