2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 namespace com.google.zxing
\r
20 /// <summary> <p>Encapsulates a point of interest in an image containing a barcode. Typically, this
\r
21 /// would be the location of a finder pattern or the corner of the barcode, for example.</p>
\r
24 /// <author> Sean Owen
\r
26 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
29 public class ResultPoint
\r
31 virtual public float X
\r
39 virtual public float Y
\r
48 //UPGRADE_NOTE: Final was removed from the declaration of 'x '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
50 //UPGRADE_NOTE: Final was removed from the declaration of 'y '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
53 public ResultPoint(float x, float y)
\r
59 public override bool Equals(System.Object other)
\r
61 if (other is ResultPoint)
\r
63 ResultPoint otherPoint = (ResultPoint) other;
\r
64 return x == otherPoint.x && y == otherPoint.y;
\r
69 public override int GetHashCode()
\r
71 // Redivivus.in Java to c# Porting update
\r
73 // Commented function body
\r
75 //return 31 * Float.floatToIntBits(x) + Float.floatToIntBits(y);
\r
79 public override System.String ToString()
\r
81 System.Text.StringBuilder result = new System.Text.StringBuilder(25);
\r
87 return result.ToString();
\r
90 /// <summary> <p>Orders an array of three ResultPoints in an order [A,B,C] such that AB < AC and
\r
91 /// BC < AC and the angle between BC and BA is less than 180 degrees.
\r
93 public static void orderBestPatterns(ResultPoint[] patterns)
\r
96 // Find distances between pattern centers
\r
97 float zeroOneDistance = distance(patterns[0], patterns[1]);
\r
98 float oneTwoDistance = distance(patterns[1], patterns[2]);
\r
99 float zeroTwoDistance = distance(patterns[0], patterns[2]);
\r
101 ResultPoint pointA, pointB, pointC;
\r
102 // Assume one closest to other two is B; A and C will just be guesses at first
\r
103 if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)
\r
105 pointB = patterns[0];
\r
106 pointA = patterns[1];
\r
107 pointC = patterns[2];
\r
109 else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)
\r
111 pointB = patterns[1];
\r
112 pointA = patterns[0];
\r
113 pointC = patterns[2];
\r
117 pointB = patterns[2];
\r
118 pointA = patterns[0];
\r
119 pointC = patterns[1];
\r
122 // Use cross product to figure out whether A and C are correct or flipped.
\r
123 // This asks whether BC x BA has a positive z component, which is the arrangement
\r
124 // we want for A, B, C. If it's negative, then we've got it flipped around and
\r
125 // should swap A and C.
\r
126 if (crossProductZ(pointA, pointB, pointC) < 0.0f)
\r
128 ResultPoint temp = pointA;
\r
133 patterns[0] = pointA;
\r
134 patterns[1] = pointB;
\r
135 patterns[2] = pointC;
\r
139 /// <returns> distance between two points
\r
141 public static float distance(ResultPoint pattern1, ResultPoint pattern2)
\r
143 float xDiff = pattern1.X - pattern2.X;
\r
144 float yDiff = pattern1.Y - pattern2.Y;
\r
145 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
\r
146 return (float) System.Math.Sqrt((double) (xDiff * xDiff + yDiff * yDiff));
\r
149 /// <summary> Returns the z component of the cross product between vectors BC and BA.</summary>
\r
150 private static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC)
\r
152 float bX = pointB.x;
\r
153 float bY = pointB.y;
\r
154 return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));
\r