mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-06 15:42:03 +00:00
:octocat: ResultPoint: remove property getters in favor of asymmetric visibility
This commit is contained in:
+16
-16
@@ -52,14 +52,14 @@ final class Detector{
|
||||
// Anything above version 1 has an alignment pattern
|
||||
if($provisionalVersion->getAlignmentPattern() !== []){
|
||||
// Guess where a "bottom right" finder pattern would have been
|
||||
$bottomRightX = ($topRight->getX() - $topLeft->getX() + $bottomLeft->getX());
|
||||
$bottomRightY = ($topRight->getY() - $topLeft->getY() + $bottomLeft->getY());
|
||||
$bottomRightX = ($topRight->x - $topLeft->x + $bottomLeft->x);
|
||||
$bottomRightY = ($topRight->y - $topLeft->y + $bottomLeft->y);
|
||||
|
||||
// Estimate that alignment pattern is closer by 3 modules
|
||||
// from "bottom right" to known top left location
|
||||
$correctionToTopLeft = (1.0 - 3.0 / (float)($provisionalVersion->getDimension() - 7));
|
||||
$estAlignmentX = (int)($topLeft->getX() + $correctionToTopLeft * ($bottomRightX - $topLeft->getX()));
|
||||
$estAlignmentY = (int)($topLeft->getY() + $correctionToTopLeft * ($bottomRightY - $topLeft->getY()));
|
||||
$estAlignmentX = (int)($topLeft->x + $correctionToTopLeft * ($bottomRightX - $topLeft->x));
|
||||
$estAlignmentY = (int)($topLeft->y + $correctionToTopLeft * ($bottomRightY - $topLeft->y));
|
||||
|
||||
// Kind of arbitrary -- expand search radius before giving up
|
||||
for($i = 4; $i <= 16; $i <<= 1){//??????????
|
||||
@@ -104,8 +104,8 @@ final class Detector{
|
||||
*/
|
||||
private function calculateModuleSizeOneWay(FinderPattern $a, FinderPattern $b):float{
|
||||
|
||||
$moduleSizeEst1 = $this->sizeOfBlackWhiteBlackRunBothWays($a->getX(), $a->getY(), $b->getX(), $b->getY());
|
||||
$moduleSizeEst2 = $this->sizeOfBlackWhiteBlackRunBothWays($b->getX(), $b->getY(), $a->getX(), $a->getY());
|
||||
$moduleSizeEst1 = $this->sizeOfBlackWhiteBlackRunBothWays($a->x, $a->y, $b->x, $b->y);
|
||||
$moduleSizeEst2 = $this->sizeOfBlackWhiteBlackRunBothWays($b->x, $b->y, $a->x, $a->y);
|
||||
|
||||
if(is_nan($moduleSizeEst1)){
|
||||
return ($moduleSizeEst2 / 7.0);
|
||||
@@ -316,15 +316,15 @@ final class Detector{
|
||||
$dimMinusThree = ($size - 3.5);
|
||||
|
||||
if($ap instanceof AlignmentPattern){
|
||||
$bottomRightX = $ap->getX();
|
||||
$bottomRightY = $ap->getY();
|
||||
$bottomRightX = $ap->x;
|
||||
$bottomRightY = $ap->y;
|
||||
$sourceBottomRightX = ($dimMinusThree - 3.0);
|
||||
$sourceBottomRightY = $sourceBottomRightX;
|
||||
}
|
||||
else{
|
||||
// Don't have an alignment pattern, just make up the bottom-right point
|
||||
$bottomRightX = ($ne->getX() - $nw->getX() + $sw->getX());
|
||||
$bottomRightY = ($ne->getY() - $nw->getY() + $sw->getY());
|
||||
$bottomRightX = ($ne->x - $nw->x + $sw->x);
|
||||
$bottomRightY = ($ne->y - $nw->y + $sw->y);
|
||||
$sourceBottomRightX = $dimMinusThree;
|
||||
$sourceBottomRightY = $dimMinusThree;
|
||||
}
|
||||
@@ -338,14 +338,14 @@ final class Detector{
|
||||
$sourceBottomRightY,
|
||||
3.5,
|
||||
$dimMinusThree,
|
||||
$nw->getX(),
|
||||
$nw->getY(),
|
||||
$ne->getX(),
|
||||
$ne->getY(),
|
||||
$nw->x,
|
||||
$nw->y,
|
||||
$ne->x,
|
||||
$ne->y,
|
||||
$bottomRightX,
|
||||
$bottomRightY,
|
||||
$sw->getX(),
|
||||
$sw->getY(),
|
||||
$sw->x,
|
||||
$sw->y,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -572,8 +572,8 @@ final class FinderPatternFinder{
|
||||
// This is the case where you find top left last.
|
||||
$this->hasSkipped = true;
|
||||
|
||||
return (int)((abs($firstConfirmedCenter->getX() - $center->getX()) -
|
||||
abs($firstConfirmedCenter->getY() - $center->getY())) / 2);
|
||||
return (int)((abs($firstConfirmedCenter->x - $center->x) -
|
||||
abs($firstConfirmedCenter->y - $center->y)) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -594,7 +594,7 @@ final class FinderPatternFinder{
|
||||
foreach($this->possibleCenters as $pattern){
|
||||
if($pattern->count >= self::CENTER_QUORUM){
|
||||
$confirmedCount++;
|
||||
$totalModuleSize += $pattern->getEstimatedModuleSize();
|
||||
$totalModuleSize += $pattern->estimatedModuleSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,7 +609,7 @@ final class FinderPatternFinder{
|
||||
$totalDeviation = 0.0;
|
||||
|
||||
foreach($this->possibleCenters as $pattern){
|
||||
$totalDeviation += abs($pattern->getEstimatedModuleSize() - $average);
|
||||
$totalDeviation += abs($pattern->estimatedModuleSize - $average);
|
||||
}
|
||||
|
||||
return $totalDeviation <= (0.05 * $totalModuleSize);
|
||||
@@ -630,7 +630,7 @@ final class FinderPatternFinder{
|
||||
|
||||
usort(
|
||||
$this->possibleCenters,
|
||||
fn(FinderPattern $a, FinderPattern $b) => ($a->getEstimatedModuleSize() <=> $b->getEstimatedModuleSize()),
|
||||
fn(FinderPattern $a, FinderPattern $b) => ($a->estimatedModuleSize <=> $b->estimatedModuleSize),
|
||||
);
|
||||
|
||||
$distortion = PHP_FLOAT_MAX;
|
||||
@@ -638,7 +638,7 @@ final class FinderPatternFinder{
|
||||
|
||||
for($i = 0; $i < ($startSize - 2); $i++){
|
||||
$fpi = $this->possibleCenters[$i];
|
||||
$minModuleSize = $fpi->getEstimatedModuleSize();
|
||||
$minModuleSize = $fpi->estimatedModuleSize;
|
||||
|
||||
for($j = ($i + 1); $j < ($startSize - 1); $j++){
|
||||
$fpj = $this->possibleCenters[$j];
|
||||
@@ -646,7 +646,7 @@ final class FinderPatternFinder{
|
||||
|
||||
for($k = ($j + 1); $k < $startSize; $k++){
|
||||
$fpk = $this->possibleCenters[$k];
|
||||
$maxModuleSize = $fpk->getEstimatedModuleSize();
|
||||
$maxModuleSize = $fpk->estimatedModuleSize;
|
||||
|
||||
// module size is not similar
|
||||
if($maxModuleSize > ($minModuleSize * 1.4)){
|
||||
@@ -758,11 +758,8 @@ final class FinderPatternFinder{
|
||||
/**
|
||||
* Returns the z component of the cross product between vectors BC and BA.
|
||||
*/
|
||||
private function crossProductZ(FinderPattern $pointA, FinderPattern $pointB, FinderPattern $pointC):float{
|
||||
$bX = $pointB->getX();
|
||||
$bY = $pointB->getY();
|
||||
|
||||
return ((($pointC->getX() - $bX) * ($pointA->getY() - $bY)) - (($pointC->getY() - $bY) * ($pointA->getX() - $bX)));
|
||||
private function crossProductZ(FinderPattern $a, FinderPattern $b, FinderPattern $c):float{
|
||||
return ((($c->x - $b->x) * ($a->y - $b->y)) - (($c->y - $b->y) * ($a->x - $b->x)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ use function abs;
|
||||
*/
|
||||
abstract class ResultPoint{
|
||||
|
||||
protected float $x;
|
||||
protected float $y;
|
||||
protected float $estimatedModuleSize;
|
||||
protected(set) float $x;
|
||||
protected(set) float $y;
|
||||
protected(set) float $estimatedModuleSize;
|
||||
|
||||
public function __construct(float $x, float $y, float $estimatedModuleSize){
|
||||
$this->x = $x;
|
||||
@@ -32,18 +32,6 @@ abstract class ResultPoint{
|
||||
$this->estimatedModuleSize = $estimatedModuleSize;
|
||||
}
|
||||
|
||||
public function getX():float{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getY():float{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
public function getEstimatedModuleSize():float{
|
||||
return $this->estimatedModuleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this finder pattern "about equals" a finder pattern at the stated
|
||||
* position and size -- meaning, it is at nearly the same center with nearly the same size.
|
||||
|
||||
Reference in New Issue
Block a user