-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a698b6
commit 7c6a8fc
Showing
7 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Geometry\Factories; | ||
|
||
class CircleFactory extends EllipseFactory | ||
{ | ||
public function radius(int $radius): self | ||
{ | ||
$this->ellipse->setSize($radius * 2, $radius * 2); | ||
|
||
return $this; | ||
} | ||
|
||
public function diameter(int $diameter): self | ||
{ | ||
$this->ellipse->setSize($diameter, $diameter); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Geometry\Factories; | ||
|
||
use Intervention\Image\Geometry\Ellipse; | ||
use Intervention\Image\Geometry\Point; | ||
|
||
class EllipseFactory | ||
{ | ||
protected Ellipse $ellipse; | ||
|
||
public function __construct(protected Point $pivot, callable|Ellipse $init) | ||
{ | ||
$this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0, $pivot); | ||
|
||
if (is_callable($init)) { | ||
$init($this); | ||
} | ||
} | ||
|
||
public function size(int $width, int $height): self | ||
{ | ||
$this->ellipse->setSize($width, $height); | ||
|
||
return $this; | ||
} | ||
|
||
public function background(mixed $color): self | ||
{ | ||
$this->ellipse->setBackgroundColor($color); | ||
|
||
return $this; | ||
} | ||
|
||
public function border(mixed $color, int $size = 1): self | ||
{ | ||
$this->ellipse->setBorder($color, $size); | ||
|
||
return $this; | ||
} | ||
|
||
public function __invoke(): Ellipse | ||
{ | ||
return $this->ellipse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Geometry\Factories; | ||
|
||
use Intervention\Image\Geometry\Point; | ||
use Intervention\Image\Geometry\Line; | ||
|
||
class LineFactory | ||
{ | ||
protected Line $line; | ||
|
||
public function __construct(callable|Line $init) | ||
{ | ||
$this->line = is_a($init, Line::class) ? $init : new Line(new Point(), new Point()); | ||
|
||
if (is_callable($init)) { | ||
$init($this); | ||
} | ||
} | ||
|
||
public function color(mixed $color): self | ||
{ | ||
$this->line->setBackgroundColor($color); | ||
$this->line->setBorderColor($color); | ||
|
||
return $this; | ||
} | ||
|
||
public function background(mixed $color): self | ||
{ | ||
$this->line->setBackgroundColor($color); | ||
$this->line->setBorderColor($color); | ||
|
||
return $this; | ||
} | ||
|
||
public function border(mixed $color, int $size = 1): self | ||
{ | ||
$this->line->setBackgroundColor($color); | ||
$this->line->setBorderColor($color); | ||
$this->line->setWidth($size); | ||
|
||
return $this; | ||
} | ||
|
||
public function width(int $size): self | ||
{ | ||
$this->line->setWidth($size); | ||
|
||
return $this; | ||
} | ||
|
||
public function from(int $x, int $y): self | ||
{ | ||
$this->line->setStart(new Point($x, $y)); | ||
|
||
return $this; | ||
} | ||
|
||
public function to(int $x, int $y): self | ||
{ | ||
$this->line->setEnd(new Point($x, $y)); | ||
|
||
return $this; | ||
} | ||
|
||
public function __invoke(): Line | ||
{ | ||
return $this->line; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Geometry\Factories; | ||
|
||
use Intervention\Image\Geometry\Point; | ||
use Intervention\Image\Geometry\Polygon; | ||
|
||
class PolygonFactory | ||
{ | ||
protected Polygon $polygon; | ||
|
||
public function __construct(callable|Polygon $init) | ||
{ | ||
$this->polygon = is_a($init, Polygon::class) ? $init : new Polygon([]); | ||
|
||
if (is_callable($init)) { | ||
$init($this); | ||
} | ||
} | ||
|
||
public function point(int $x, int $y): self | ||
{ | ||
$this->polygon->addPoint(new Point($x, $y)); | ||
|
||
return $this; | ||
} | ||
|
||
public function background(mixed $color): self | ||
{ | ||
$this->polygon->setBackgroundColor($color); | ||
|
||
return $this; | ||
} | ||
|
||
public function border(mixed $color, int $size = 1): self | ||
{ | ||
$this->polygon->setBorder($color, $size); | ||
|
||
return $this; | ||
} | ||
|
||
public function __invoke(): Polygon | ||
{ | ||
return $this->polygon; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Geometry\Factories; | ||
|
||
use Intervention\Image\Geometry\Point; | ||
use Intervention\Image\Geometry\Rectangle; | ||
|
||
class RectangleFactory | ||
{ | ||
protected Rectangle $rectangle; | ||
|
||
public function __construct(protected Point $pivot, callable|Rectangle $init) | ||
{ | ||
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot); | ||
|
||
if (is_callable($init)) { | ||
$init($this); | ||
} | ||
} | ||
|
||
public function size(int $width, int $height): self | ||
{ | ||
$this->rectangle->setSize($width, $height); | ||
|
||
return $this; | ||
} | ||
|
||
public function background(mixed $color): self | ||
{ | ||
$this->rectangle->setBackgroundColor($color); | ||
|
||
return $this; | ||
} | ||
|
||
public function border(mixed $color, int $size = 1): self | ||
{ | ||
$this->rectangle->setBorder($color, $size); | ||
|
||
return $this; | ||
} | ||
|
||
public function __invoke(): Rectangle | ||
{ | ||
return $this->rectangle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters