PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / chillerlan / php-qrcode / src / Detector / FinderPattern.php

FinderPattern.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/chillerlan/php-qrcode/src/Detector/FinderPattern.php

83 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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