git-svn-id: http://zxing.googlecode.com/svn/trunk@6 59b500cc-1b3d-0410-9834-0bbf25fbcc57
[zxing.git] / core / src / com / google / zxing / qrcode / detector / FinderPattern.java
1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.qrcode.detector;
18
19 import com.google.zxing.ResultPoint;
20
21 /**
22  * @author srowen@google.com (Sean Owen)
23  */
24 public final class FinderPattern implements ResultPoint {
25
26   private final float posX;
27   private final float posY;
28   private final float estimatedModuleSize;
29   private int count;
30
31   FinderPattern(float posX, float posY, float estimatedModuleSize) {
32     this.posX = posX;
33     this.posY = posY;
34     this.estimatedModuleSize = estimatedModuleSize;
35     this.count = 1;
36   }
37
38   public float getX() {
39     return posX;
40   }
41
42   public float getY() {
43     return posY;
44   }
45
46   float getEstimatedModuleSize() {
47     return estimatedModuleSize;
48   }
49
50   int getCount() {
51     return count;
52   }
53
54   void incrementCount() {
55     this.count++;
56   }
57
58   boolean aboutEquals(float moduleSize, float i, float j) {
59     return Math.abs(i - posY) <= moduleSize &&
60            Math.abs(j - posX) <= moduleSize &&
61            (Math.abs(moduleSize - estimatedModuleSize) <= 1.0f ||
62             Math.abs(moduleSize - estimatedModuleSize) / estimatedModuleSize <= 0.1f);
63   }
64
65 }