ResultPoint.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Class ResultPoint
  4. *
  5. * @created 17.01.2021
  6. * @author ZXing Authors
  7. * @author Smiley <smiley@chillerlan.net>
  8. * @copyright 2021 Smiley
  9. * @license Apache-2.0
  10. */
  11. declare(strict_types=1);
  12. namespace chillerlan\QRCode\Detector;
  13. use function abs;
  14. /**
  15. * Encapsulates a point of interest in an image containing a barcode. Typically, this
  16. * would be the location of a finder pattern or the corner of the barcode, for example.
  17. *
  18. * @author Sean Owen
  19. */
  20. abstract class ResultPoint{
  21. protected float $x;
  22. protected float $y;
  23. protected float $estimatedModuleSize;
  24. public function __construct(float $x, float $y, float $estimatedModuleSize){
  25. $this->x = $x;
  26. $this->y = $y;
  27. $this->estimatedModuleSize = $estimatedModuleSize;
  28. }
  29. public function getX():float{
  30. return $this->x;
  31. }
  32. public function getY():float{
  33. return $this->y;
  34. }
  35. public function getEstimatedModuleSize():float{
  36. return $this->estimatedModuleSize;
  37. }
  38. /**
  39. * Determines if this finder pattern "about equals" a finder pattern at the stated
  40. * position and size -- meaning, it is at nearly the same center with nearly the same size.
  41. */
  42. public function aboutEquals(float $moduleSize, float $i, float $j):bool{
  43. if(abs($i - $this->y) <= $moduleSize && abs($j - $this->x) <= $moduleSize){
  44. $moduleSizeDiff = abs($moduleSize - $this->estimatedModuleSize);
  45. return $moduleSizeDiff <= 1.0 || $moduleSizeDiff <= $this->estimatedModuleSize;
  46. }
  47. return false;
  48. }
  49. }