ResultPoint.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. namespace chillerlan\QRCode\Detector;
  12. use function abs;
  13. /**
  14. * Encapsulates a point of interest in an image containing a barcode. Typically, this
  15. * would be the location of a finder pattern or the corner of the barcode, for example.
  16. *
  17. * @author Sean Owen
  18. */
  19. abstract class ResultPoint{
  20. protected float $x;
  21. protected float $y;
  22. protected float $estimatedModuleSize;
  23. /**
  24. *
  25. */
  26. public function __construct(float $x, float $y, float $estimatedModuleSize){
  27. $this->x = $x;
  28. $this->y = $y;
  29. $this->estimatedModuleSize = $estimatedModuleSize;
  30. }
  31. /**
  32. *
  33. */
  34. public function getX():float{
  35. return $this->x;
  36. }
  37. /**
  38. *
  39. */
  40. public function getY():float{
  41. return $this->y;
  42. }
  43. /**
  44. *
  45. */
  46. public function getEstimatedModuleSize():float{
  47. return $this->estimatedModuleSize;
  48. }
  49. /**
  50. * Determines if this finder pattern "about equals" a finder pattern at the stated
  51. * position and size -- meaning, it is at nearly the same center with nearly the same size.
  52. */
  53. public function aboutEquals(float $moduleSize, float $i, float $j):bool{
  54. if(abs($i - $this->y) <= $moduleSize && abs($j - $this->x) <= $moduleSize){
  55. $moduleSizeDiff = abs($moduleSize - $this->estimatedModuleSize);
  56. return $moduleSizeDiff <= 1.0 || $moduleSizeDiff <= $this->estimatedModuleSize;
  57. }
  58. return false;
  59. }
  60. }