php-kilo/src/Point.php

33 lines
576 B
PHP

<?php declare(strict_types=1);
namespace Aviat\Kilo;
/**
* A representation of a 2d point
*/
final class Point {
private function __construct(public int $x, public int $y) {}
/**
* Create a new Point from coordinates
*
* @param int $x
* @param int $y
* @return Point
*/
public static function new(int $x = 0, int $y = 0): Point
{
return new Point($x, $y);
}
/**
* Create a new Point from another position
*
* @param Point $pos
* @return Point
*/
public static function from(Point $pos): Point
{
return Point::new($pos->x, $pos->y);
}
}