123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
-
-
- namespace Zxing;
-
- use Zxing\Common\Detector\MathUtils;
-
-
- class ResultPoint
- {
- private $x;
- private $y;
-
- public function __construct($x, $y)
- {
- $this->x = (float)($x);
- $this->y = (float)($y);
- }
-
-
-
- public static function orderBestPatterns($patterns)
- {
-
-
- $zeroOneDistance = self::distance($patterns[0], $patterns[1]);
- $oneTwoDistance = self::distance($patterns[1], $patterns[2]);
- $zeroTwoDistance = self::distance($patterns[0], $patterns[2]);
-
- $pointA = '';
- $pointB = '';
- $pointC = '';
-
- if ($oneTwoDistance >= $zeroOneDistance && $oneTwoDistance >= $zeroTwoDistance) {
- $pointB = $patterns[0];
- $pointA = $patterns[1];
- $pointC = $patterns[2];
- } else if ($zeroTwoDistance >= $oneTwoDistance && $zeroTwoDistance >= $zeroOneDistance) {
- $pointB = $patterns[1];
- $pointA = $patterns[0];
- $pointC = $patterns[2];
- } else {
- $pointB = $patterns[2];
- $pointA = $patterns[0];
- $pointC = $patterns[1];
- }
-
-
-
-
-
- if (self::crossProductZ($pointA, $pointB, $pointC) < 0.0) {
- $temp = $pointA;
- $pointA = $pointC;
- $pointC = $temp;
- }
-
- $patterns[0] = $pointA;
- $patterns[1] = $pointB;
- $patterns[2] = $pointC;
-
- return $patterns;
- }
-
-
-
- public static function distance($pattern1, $pattern2)
- {
- return MathUtils::distance($pattern1->x, $pattern1->y, $pattern2->x, $pattern2->y);
- }
-
-
-
-
-
- private static function crossProductZ($pointA,
- $pointB,
- $pointC)
- {
- $bX = $pointB->x;
- $bY = $pointB->y;
-
- return (($pointC->x - $bX) * ($pointA->y - $bY)) - (($pointC->y - $bY) * ($pointA->x - $bX));
- }
-
-
-
- public final function getX()
- {
- return (float)($this->x);
- }
-
-
-
- public final function getY()
- {
- return (float)($this->y);
- }
-
- public final function equals($other)
- {
- if ($other instanceof ResultPoint) {
- $otherPoint = $other;
-
- return $this->x == $otherPoint->x && $this->y == $otherPoint->y;
- }
-
- return false;
- }
-
- public final function hashCode()
- {
- return 31 * floatToIntBits($this->x) + floatToIntBits($this->y);
- }
-
- public final function toString()
- {
- $result = '';
- $result .= ('(');
- $result .= ($this->x);
- $result .= (',');
- $result .= ($this->y);
- $result .= (')');
-
- return $result;
- }
- }
|