Passed
Push — v5 ( 93618e...84eb31 )
by smiley
01:52
created

FinderPattern::getCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Class FinderPattern
4
 *
5
 * @created      17.01.2021
6
 * @author       ZXing Authors
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2021 Smiley
9
 * @license      Apache-2.0
10
 */
11
12
namespace chillerlan\QRCode\Detector;
13
14
use function chillerlan\QRCode\Common\{distance, squaredDistance};
0 ignored issues
show
Bug introduced by
The type chillerlan\QRCode\Common\distance was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type chillerlan\QRCode\Common\squaredDistance was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * <p>Encapsulates a finder pattern, which are the three square patterns found in
18
 * the corners of QR Codes. It also encapsulates a count of similar finder patterns,
19
 * as a convenience to the finder's bookkeeping.</p>
20
 *
21
 * @author Sean Owen
22
 */
23
final class FinderPattern extends ResultPoint{
24
25
	private int $count;
26
27
	public function __construct(float $posX, float $posY, float $estimatedModuleSize, int $count = 1){
28
		parent::__construct($posX, $posY, $estimatedModuleSize);
29
30
		$this->count = $count;
31
	}
32
33
	public function getCount():int{
34
		return $this->count;
35
	}
36
37
	/**
38
	 * @param \chillerlan\QRCode\Detector\FinderPattern $b second pattern
39
	 *
40
	 * @return float distance between two points
41
	 */
42
	public function distance(FinderPattern $b):float{
43
		return distance($this->getX(), $this->getY(), $b->getX(), $b->getY());
44
	}
45
46
	/**
47
	 * Get square of distance between a and b.
48
	 */
49
	public function squaredDistance(FinderPattern $b):float{
50
		return squaredDistance($this->getX(), $this->getY(), $b->getX(), $b->getY());
51
	}
52
53
	/**
54
	 * Combines this object's current estimate of a finder pattern position and module size
55
	 * with a new estimate. It returns a new {@code FinderPattern} containing a weighted average
56
	 * based on count.
57
	 */
58
	public function combineEstimate(float $i, float $j, float $newModuleSize):FinderPattern{
59
		$combinedCount = $this->count + 1;
60
61
		return new self(
62
			($this->count * $this->x + $j) / $combinedCount,
63
			($this->count * $this->y + $i) / $combinedCount,
64
			($this->count * $this->estimatedModuleSize + $newModuleSize) / $combinedCount,
65
			$combinedCount
66
		);
67
	}
68
69
}
70