2021-03-09 17:22:49 -05:00
|
|
|
<?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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-10 11:10:52 -05:00
|
|
|
* Create a new Point from another Point
|
2021-03-09 17:22:49 -05:00
|
|
|
*
|
|
|
|
* @param Point $pos
|
|
|
|
* @return Point
|
|
|
|
*/
|
|
|
|
public static function from(Point $pos): Point
|
|
|
|
{
|
|
|
|
return Point::new($pos->x, $pos->y);
|
|
|
|
}
|
|
|
|
}
|