1<?php
2
3/**
4 * Immutable class representing a 2D point in canvas coordinates
5 */
6class Point {
7	public function __construct($x, $y) {
8		$this->x = $x;
9		$this->y = $y;
10	}
11
12	public function getX() {
13		return $this->x;
14	}
15
16	public function getY() {
17		return $this->y;
18	}
19
20	public function distanceFrom(Point $other) {
21		return sqrt((($other->x - $this->x) * ($other->x - $this->x))
22					+ (($other->y - $this->y) * ($other->y - $this->y)));
23	}
24
25	/**
26	 * Return a new Point instance that has been incremented by the
27	 * specified X and Y values
28	 */
29	public function addIncrement($x, $y) {
30		return new Point($this->x + $x, $this->Y + $y);
31	}
32
33	public function __toString() {
34		return sprintf("Point<%d, %d>", $this->x, $this->y);
35	}
36
37	private $x;
38	private $y;
39}