]> Pileus Git - ~andy/freeotp/blob - src/com/google/zxing/qrcode/detector/AlignmentPattern.java
Add native camera support
[~andy/freeotp] / src / com / google / zxing / qrcode / detector / AlignmentPattern.java
1 /*
2  * Copyright 2007 ZXing authors
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  * <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
23  * all but the simplest QR Codes.</p>
24  *
25  * @author Sean Owen
26  */
27 public final class AlignmentPattern extends ResultPoint {
28
29   private final float estimatedModuleSize;
30
31   AlignmentPattern(float posX, float posY, float estimatedModuleSize) {
32     super(posX, posY);
33     this.estimatedModuleSize = estimatedModuleSize;
34   }
35
36   /**
37    * <p>Determines if this alignment pattern "about equals" an alignment pattern at the stated
38    * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>
39    */
40   boolean aboutEquals(float moduleSize, float i, float j) {
41     if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) {
42       float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize);
43       return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize;
44     }
45     return false;
46   }
47
48   /**
49    * Combines this object's current estimate of a finder pattern position and module size
50    * with a new estimate. It returns a new {@code FinderPattern} containing an average of the two.
51    */
52   AlignmentPattern combineEstimate(float i, float j, float newModuleSize) {
53     float combinedX = (getX() + j) / 2.0f;
54     float combinedY = (getY() + i) / 2.0f;
55     float combinedModuleSize = (estimatedModuleSize + newModuleSize) / 2.0f;
56     return new AlignmentPattern(combinedX, combinedY, combinedModuleSize);
57   }
58
59 }