Skip to content

Commit

Permalink
Add more specific exceptions for specific cases ("piece is cut off" a…
Browse files Browse the repository at this point in the history
…nd "no area found")
  • Loading branch information
byWulf committed Feb 5, 2023
1 parent 012bc7d commit 5612e17
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/Exception/BorderParsing/CutOffPieceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Bywulf\Jigsawlutioner\Exception\BorderParsing;

use Bywulf\Jigsawlutioner\Exception\BorderParsingException;

class CutOffPieceException extends BorderParsingException
{
public function __construct()
{
parent::__construct('Piece is cut off');
}
}
15 changes: 15 additions & 0 deletions src/Exception/BorderParsing/NoAreaFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Bywulf\Jigsawlutioner\Exception\BorderParsing;

use Bywulf\Jigsawlutioner\Exception\BorderParsingException;

class NoAreaFoundException extends BorderParsingException
{
public function __construct()
{
parent::__construct('No area found');
}
}
3 changes: 2 additions & 1 deletion src/Service/BorderFinder/ByWulfBorderFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Bywulf\Jigsawlutioner\Dto\Context\ByWulfBorderFinderContext;
use Bywulf\Jigsawlutioner\Dto\PixelMap;
use Bywulf\Jigsawlutioner\Dto\Point;
use Bywulf\Jigsawlutioner\Exception\BorderParsing\CutOffPieceException;
use Bywulf\Jigsawlutioner\Exception\BorderParsingException;
use Bywulf\Jigsawlutioner\Exception\PixelMapException;
use Bywulf\Jigsawlutioner\Service\BorderFinder\ByWulfBorderFinder\PixelManipulator;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function findPieceBorder(

// Check if piece is cut off on an edge
if ($this->hasBorderPixel($pixelMap, $biggestObjectColor)) {
throw new BorderParsingException('Piece is cut off');
throw new CutOffPieceException();
}

// Make given images transparent if wished
Expand Down
3 changes: 2 additions & 1 deletion src/Service/BorderFinder/ByWulfBorderFinder/PointParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Bywulf\Jigsawlutioner\Dto\PixelMap;
use Bywulf\Jigsawlutioner\Dto\Point;
use Bywulf\Jigsawlutioner\Exception\BorderParsing\NoAreaFoundException;
use Bywulf\Jigsawlutioner\Exception\BorderParsingException;
use Bywulf\Jigsawlutioner\Service\BorderFinder\ByWulfBorderFinder;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function getOrderedBorderPoints(PixelMap $pixelMap, int $objectColor): ar
}
}

throw new BorderParsingException('No area found');
throw new NoAreaFoundException();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Service/PuzzleSolver/ByWulfSolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setSolutionReport(SolutionReport $solutionReport): void
}

/**
* @param array<int, Piece|ReducedPiece> $pieces
* @param array<int, Piece|ReducedPiece> $pieces
* @param array<string, array<string, float>> $matchingMap
*
* @throws PuzzleSolverException
Expand Down
2 changes: 1 addition & 1 deletion src/Service/PuzzleSolver/PuzzleSolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
interface PuzzleSolverInterface
{
/**
* @param array<int, Piece|ReducedPiece> $pieces
* @param array<int, Piece|ReducedPiece> $pieces
* @param array<string, array<string, float>> $matchingMap
*/
public function findSolution(array $pieces, array $matchingMap): Solution;
Expand Down

0 comments on commit 5612e17

Please sign in to comment.