Skip to content

Instantly share code, notes, and snippets.

@Zvax
Created June 13, 2018 19:33
Show Gist options
  • Save Zvax/cb9dee0e823e0001f03b4440938a366f to your computer and use it in GitHub Desktop.
Save Zvax/cb9dee0e823e0001f03b4440938a366f to your computer and use it in GitHub Desktop.
CoordinatesFactory.php
<?php declare(strict_types=1);
namespace Mapping;
class CoordinatesFactory
{
private static $coordinates = [];
public static function make(int $x, int $y, int $z = null): Coordinates {
if ($z === null) {
if (!isset(self::$coordinates[$x][$y])) {
self::$coordinates[$x][$y] = new Coordinates2d($x, $y);
}
return self::$coordinates[$x][$y];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment