2 * Copyright 2007 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.qrcode.detector;
19 import com.google.zxing.ResultPoint;
22 * <p>Encapsulates a finder pattern, which are the three square patterns found in
23 * the corners of QR Codes. It also encapsulates a count of similar finder patterns,
24 * as a convenience to the finder's bookkeeping.</p>
28 public final class FinderPattern extends ResultPoint {
30 private final float estimatedModuleSize;
33 FinderPattern(float posX, float posY, float estimatedModuleSize) {
35 this.estimatedModuleSize = estimatedModuleSize;
39 public float getEstimatedModuleSize() {
40 return estimatedModuleSize;
47 void incrementCount() {
52 * <p>Determines if this finder pattern "about equals" a finder pattern at the stated
53 * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>
55 boolean aboutEquals(float moduleSize, float i, float j) {
56 if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) {
57 float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize);
58 return moduleSizeDiff <= 1.0f || moduleSizeDiff / estimatedModuleSize <= 1.0f;