| <?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; |
| } |
| } |
|
|