Committed C# port from Mohamad
[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 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 AlignmentPattern : ResultPoint\r
23     {\r
24           private  float posX;\r
25           private  float posY;\r
26           private  float estimatedModuleSize;\r
27 \r
28           public AlignmentPattern(float posX, float posY, float estimatedModuleSize) {\r
29             this.posX = posX;\r
30             this.posY = posY;\r
31             this.estimatedModuleSize = estimatedModuleSize;\r
32           }\r
33 \r
34           public float getX() {\r
35             return posX;\r
36           }\r
37 \r
38           public float getY() {\r
39             return posY;\r
40           }\r
41 \r
42           /**\r
43            * <p>Determines if this alignment pattern "about equals" an alignment pattern at the stated\r
44            * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>\r
45            */\r
46           public bool aboutEquals(float moduleSize, float i, float j) {\r
47             return\r
48                 Math.Abs(i - posY) <= moduleSize &&\r
49                     Math.Abs(j - posX) <= moduleSize &&\r
50                     (Math.Abs(moduleSize - estimatedModuleSize) <= 1.0f ||\r
51                         Math.Abs(moduleSize - estimatedModuleSize) / estimatedModuleSize <= 0.1f);\r
52           }\r
53     }\r
54     \r
55 \r
56 }