1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-15 10:23:59 +02:00

Implement IteratorAggregate for Point::class

This commit is contained in:
Oliver Vogel
2025-03-05 16:27:47 +01:00
parent ebbb711871
commit 78e290ae97
2 changed files with 26 additions and 1 deletions

View File

@@ -4,9 +4,15 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry;
use ArrayIterator;
use Intervention\Image\Interfaces\PointInterface;
use IteratorAggregate;
use Traversable;
class Point implements PointInterface
/**
* @implements IteratorAggregate<int>
*/
class Point implements PointInterface, IteratorAggregate
{
/**
* Create new point instance
@@ -19,6 +25,17 @@ class Point implements PointInterface
protected int $x = 0,
protected int $y = 0
) {
//
}
/**
* {@inheritdoc}
*
* @see IteratorAggregate::getIterator()
*/
public function getIterator(): Traversable
{
return new ArrayIterator([$this->x, $this->y]);
}
/**

View File

@@ -27,6 +27,14 @@ final class PointTest extends BaseTestCase
$this->assertEquals(50, $point->y());
}
public function testIteration(): void
{
$point = new Point(40, 50);
foreach ($point as $value) {
$this->assertIsInt($value);
}
}
public function testGetSetX(): void
{
$point = new Point(0, 0);