| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class FinderPattern |
| 5 |
* |
| 6 |
* @created 17.01.2021 |
| 7 |
* @author ZXing Authors |
| 8 |
* @author Smiley <[email protected]> |
| 9 |
* @copyright 2021 Smiley |
| 10 |
* @license Apache-2.0 |
| 11 |
*/ |
| 12 |
namespace WCPOS\Vendor\chillerlan\QRCode\Detector; |
| 13 |
|
| 14 |
use function sqrt; |
| 15 |
/** |
| 16 |
* Encapsulates a finder pattern, which are the three square patterns found in |
| 17 |
* the corners of QR Codes. It also encapsulates a count of similar finder patterns, |
| 18 |
* as a convenience to the finder's bookkeeping. |
| 19 |
* |
| 20 |
* @author Sean Owen |
| 21 |
*/ |
| 22 |
final class FinderPattern extends ResultPoint |
| 23 |
{ |
| 24 |
private int $count; |
| 25 |
/** |
| 26 |
* |
| 27 |
*/ |
| 28 |
public function __construct(float $posX, float $posY, float $estimatedModuleSize, ?int $count = null) |
| 29 |
{ |
| 30 |
parent::__construct($posX, $posY, $estimatedModuleSize); |
| 31 |
$this->count = $count ?? 1; |
| 32 |
} |
| 33 |
/** |
| 34 |
* |
| 35 |
*/ |
| 36 |
public function getCount() : int |
| 37 |
{ |
| 38 |
return $this->count; |
| 39 |
} |
| 40 |
/** |
| 41 |
* @param \chillerlan\QRCode\Detector\FinderPattern $b second pattern |
| 42 |
* |
| 43 |
* @return float distance between two points |
| 44 |
*/ |
| 45 |
public function getDistance(FinderPattern $b) : float |
| 46 |
{ |
| 47 |
return self::distance($this->x, $this->y, $b->x, $b->y); |
| 48 |
} |
| 49 |
/** |
| 50 |
* Get square of distance between a and b. |
| 51 |
*/ |
| 52 |
public function getSquaredDistance(FinderPattern $b) : float |
| 53 |
{ |
| 54 |
return self::squaredDistance($this->x, $this->y, $b->x, $b->y); |
| 55 |
} |
| 56 |
/** |
| 57 |
* Combines this object's current estimate of a finder pattern position and module size |
| 58 |
* with a new estimate. It returns a new FinderPattern containing a weighted average |
| 59 |
* based on count. |
| 60 |
*/ |
| 61 |
public function combineEstimate(float $i, float $j, float $newModuleSize) : self |
| 62 |
{ |
| 63 |
$combinedCount = $this->count + 1; |
| 64 |
return new self(($this->count * $this->x + $j) / $combinedCount, ($this->count * $this->y + $i) / $combinedCount, ($this->count * $this->estimatedModuleSize + $newModuleSize) / $combinedCount, $combinedCount); |
| 65 |
} |
| 66 |
/** |
| 67 |
* |
| 68 |
*/ |
| 69 |
private static function squaredDistance(float $aX, float $aY, float $bX, float $bY) : float |
| 70 |
{ |
| 71 |
$xDiff = $aX - $bX; |
| 72 |
$yDiff = $aY - $bY; |
| 73 |
return $xDiff * $xDiff + $yDiff * $yDiff; |
| 74 |
} |
| 75 |
/** |
| 76 |
* |
| 77 |
*/ |
| 78 |
public static function distance(float $aX, float $aY, float $bX, float $bY) : float |
| 79 |
{ |
| 80 |
return sqrt(self::squaredDistance($aX, $aY, $bX, $bY)); |
| 81 |
} |
| 82 |
} |
| 83 |
|