Committed C# port from Mohamad
[zxing.git] / csharp / qrcode / detector / FinderPattern.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 com.google.zxing;\r
18 using com.google.zxing.common;\r
19 \r
20 namespace com.google.zxing.qrcode.detector\r
21 {\r
22     public sealed class FinderPattern : ResultPoint\r
23     { \r
24           private  float posX;\r
25           private  float posY;\r
26           private  float estimatedModuleSize;\r
27           private int count;\r
28 \r
29           public FinderPattern(float posX, float posY, float estimatedModuleSize) {\r
30             this.posX = posX;\r
31             this.posY = posY;\r
32             this.estimatedModuleSize = estimatedModuleSize;\r
33             this.count = 1;\r
34           }\r
35 \r
36           public float getX() {\r
37             return posX;\r
38           }\r
39 \r
40           public float getY() {\r
41             return posY;\r
42           }\r
43 \r
44           public float getEstimatedModuleSize()\r
45           {\r
46             return estimatedModuleSize;\r
47           }\r
48 \r
49           public int getCount()\r
50           {\r
51             return count;\r
52           }\r
53 \r
54           public void incrementCount()\r
55           {\r
56             this.count++;\r
57           }\r
58 \r
59           /**\r
60            * <p>Determines if this finder pattern "about equals" a finder pattern at the stated\r
61            * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>\r
62            */\r
63           public bool aboutEquals(float moduleSize, float i, float j) {\r
64             return Math.Abs(i - posY) <= moduleSize &&\r
65                 Math.Abs(j - posX) <= moduleSize &&\r
66                 (Math.Abs(moduleSize - estimatedModuleSize) <= 1.0f ||\r
67                     Math.Abs(moduleSize - estimatedModuleSize) / estimatedModuleSize <= 0.1f);\r
68           }\r
69     \r
70     }\r
71 }