New C# port from Suraj Supekar
[zxing.git] / csharp / qrcode / detector / AlignmentPattern.cs
1 /*\r
2 * Copyright 2007 ZXing authors\r
3 *\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
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\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
15 */\r
16 using System;\r
17 using ResultPoint = com.google.zxing.ResultPoint;\r
18 namespace com.google.zxing.qrcode.detector\r
19 {\r
20         \r
21         /// <summary> <p>Encapsulates an alignment pattern, which are the smaller square patterns found in\r
22         /// all but the simplest QR Codes.</p>\r
23         /// \r
24         /// </summary>\r
25         /// <author>  Sean Owen\r
26         /// </author>\r
27         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
28         /// </author>\r
29         public sealed class AlignmentPattern:ResultPoint\r
30         {\r
31                 \r
32                 //UPGRADE_NOTE: Final was removed from the declaration of 'estimatedModuleSize '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
33                 private float estimatedModuleSize;\r
34                 \r
35                 internal AlignmentPattern(float posX, float posY, float estimatedModuleSize):base(posX, posY)\r
36                 {\r
37                         this.estimatedModuleSize = estimatedModuleSize;\r
38                 }\r
39                 \r
40                 /// <summary> <p>Determines if this alignment pattern "about equals" an alignment pattern at the stated\r
41                 /// position and size -- meaning, it is at nearly the same center with nearly the same size.</p>\r
42                 /// </summary>\r
43                 internal bool aboutEquals(float moduleSize, float i, float j)\r
44                 {\r
45                         if (System.Math.Abs(i - Y) <= moduleSize && System.Math.Abs(j - X) <= moduleSize)\r
46                         {\r
47                                 float moduleSizeDiff = System.Math.Abs(moduleSize - estimatedModuleSize);\r
48                                 return moduleSizeDiff <= 1.0f || moduleSizeDiff / estimatedModuleSize <= 1.0f;\r
49                         }\r
50                         return false;\r
51                 }\r
52         }\r
53 }