Skip to content

Commit fba1bba

Browse files
committed
minor tweaks
1 parent d08b511 commit fba1bba

4 files changed

Lines changed: 31 additions & 41 deletions

File tree

src/Geometry/MinMaxUtils.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Mindee\Geometry;
44

5+
use Mindee\Error\MindeeGeometryException;
6+
57
/**
68
* Utility class for MinMax.
79
*/
@@ -11,31 +13,41 @@ class MinMaxUtils
1113
* Retrieves the upper and lower bounds of the y-axis from an array of points.
1214
*
1315
* @param array $points An array of points.
14-
* @return \Mindee\Geometry\MinMax
16+
* @return MinMax
17+
* @throws MindeeGeometryException Throws if the provided array is too small.
1518
*/
1619
public static function getMinMaxY(array $points): MinMax
1720
{
21+
if (count($points) < 1) {
22+
throw new MindeeGeometryException(
23+
'The provided point array must have at least 1 point to calculate the Y bounds.'
24+
);
25+
}
1826
$yCoords = [];
1927
foreach ($points as $point) {
2028
$yCoords[] = $point->getY();
2129
}
22-
2330
return new MinMax(min($yCoords), max($yCoords));
2431
}
2532

2633
/**
2734
* Retrieves the upper and lower bounds of the x-axis from an array of points.
2835
*
2936
* @param array $points An array of points.
30-
* @return \Mindee\Geometry\MinMax
37+
* @return MinMax
38+
* @throws MindeeGeometryException Throws if the provided array is too small.
3139
*/
3240
public static function getMinMaxX(array $points): MinMax
3341
{
42+
if (count($points) < 1) {
43+
throw new MindeeGeometryException(
44+
'The provided point array must have at least 1 point to calculate the X bounds.'
45+
);
46+
}
3447
$xCoords = [];
3548
foreach ($points as $point) {
3649
$xCoords[] = $point->getX();
3750
}
38-
3951
return new MinMax(min($xCoords), max($xCoords));
4052
}
4153
}

src/Input/LocalInputSource.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
use CURLFile;
1010
use Exception;
1111
use Mindee\Error\ErrorCode;
12-
use Mindee\Error\MindeeImageException;
1312
use Mindee\Error\MindeeMimeTypeException;
1413
use Mindee\Error\MindeePDFException;
1514
use Mindee\Error\MindeeSourceException;
16-
use Mindee\Error\MindeeUnhandledException;
1715
use Mindee\Image\ImageCompressor;
18-
use Mindee\Parsing\DependencyChecker;
1916
use Mindee\PDF\PDFCompressor;
2017
use Mindee\PDF\PDFUtils;
2118
use setasign\Fpdi\Fpdi;
@@ -131,27 +128,11 @@ public function countDocPages(): int
131128
}
132129
}
133130

134-
/**
135-
* Processes a PDF file.
136-
* To be implemented.
137-
*
138-
* @param string $behavior Behaviors available: KEEP_ONLY, REMOVE.
139-
* @param integer $onMinPages Minimum of pages to apply the operation.
140-
* @param array $pageIndexes Indexes of the pages to apply the operation to.
141-
* @return void
142-
* @throws MindeePDFException Throws if the operation is unknown, or if the resulting PDF can't be processed.
143-
* @deprecated Use applyPageOptions() instead.
144-
*/
145-
public function processPDF(string $behavior, int $onMinPages, array $pageIndexes)
146-
{
147-
$this->applyPageOptions(new PageOptions($pageIndexes, $behavior, $onMinPages));
148-
}
149-
150131
/**
151132
* @param string $fileBytes Raw data as bytes.
152133
* @return void
153134
*/
154-
private function saveBytesAsFile(string $fileBytes)
135+
private function saveBytesAsFile(string $fileBytes): void
155136
{
156137
$cutPdfTempFile = tempnam(sys_get_temp_dir(), 'mindee_cut_pdf_');
157138
file_put_contents($cutPdfTempFile, $fileBytes);

src/Parsing/Common/Ocr/OcrPage.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Mindee\Parsing\Common\Ocr;
44

5-
use Mindee\Geometry\MinMaxUtils;
6-
use Mindee\Geometry\PolygonUtils;
7-
85
/**
96
* OCR extraction for a single page.
107
*/
@@ -22,28 +19,28 @@ class OcrPage
2219
/**
2320
* Checks whether the words are on the same line.
2421
*
25-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $currentWord Reference word to compare.
26-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $nextWord Next word to compare.
22+
* @param OcrWord $currentWord Reference word to compare.
23+
* @param OcrWord $nextWord Next word to compare.
2724
* @return boolean
2825
*/
2926
private static function areWordsOnSameLine(OcrWord $currentWord, OcrWord $nextWord): bool
3027
{
31-
$currentInNext = PolygonUtils::isPointInPolygonY($currentWord->polygon->getCentroid(), $nextWord->polygon);
32-
$nextInCurrent = PolygonUtils::isPointInPolygonY($nextWord->polygon->getCentroid(), $currentWord->polygon);
28+
$currentInNext = $nextWord->polygon->isPointInY($currentWord->polygon->getCentroid());
29+
$nextInCurrent = $currentWord->polygon->isPointInY($nextWord->polygon->getCentroid());
3330
return $currentInNext || $nextInCurrent;
3431
}
3532

3633
/**
3734
* Compares word positions on the X axis. Returns a sort-compliant result (0;-1;1).
3835
*
39-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $word1 First word.
40-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $word2 Second word.
36+
* @param OcrWord $word1 First word.
37+
* @param OcrWord $word2 Second word.
4138
* @return integer
4239
*/
4340
public static function getMinMaxX(OcrWord $word1, OcrWord $word2): int
4441
{
45-
$word1X = MinMaxUtils::getMinMaxX($word1->polygon->getCoordinates())->getMin();
46-
$word2X = MinMaxUtils::getMinMaxX($word2->polygon->getCoordinates())->getMin();
42+
$word1X = $word1->polygon->getMinMaxX()->getMin();
43+
$word2X = $word2->polygon->getMinMaxX()->getMin();
4744
if ($word1X == $word2X) {
4845
return 0;
4946
}
@@ -53,14 +50,14 @@ public static function getMinMaxX(OcrWord $word1, OcrWord $word2): int
5350
/**
5451
* Compares word positions on the Y axis. Returns a sort-compliant result (0;-1;1).
5552
*
56-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $word1 First word.
57-
* @param \Mindee\Parsing\Common\Ocr\OcrWord $word2 Second word.
53+
* @param OcrWord $word1 First word.
54+
* @param OcrWord $word2 Second word.
5855
* @return integer
5956
*/
6057
public static function getMinMaxY(OcrWord $word1, OcrWord $word2): int
6158
{
62-
$word1Y = MinMaxUtils::getMinMaxY($word1->polygon->getCoordinates())->getMin();
63-
$word2Y = MinMaxUtils::getMinMaxY($word2->polygon->getCoordinates())->getMin();
59+
$word1Y = $word1->polygon->getMinMaxY()->getMin();
60+
$word2Y = $word2->polygon->getMinMaxY()->getMin();
6461
if ($word1Y == $word2Y) {
6562
return 0;
6663
}

src/Parsing/Standard/FieldPositionMixin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
trait FieldPositionMixin
1313
{
1414
/**
15-
* @var \Mindee\Geometry\Polygon A polygon containing the word in the document.
15+
* @var Polygon A polygon containing the word in the document.
1616
*/
1717
public Polygon $polygon;
1818
/**
19-
* @var \Mindee\Geometry\Polygon|null A right rectangle containing the word in the document.
19+
* @var Polygon|null A right rectangle containing the word in the document.
2020
*/
2121
public ?Polygon $boundingBox;
2222

0 commit comments

Comments
 (0)