1<?php
2
3namespace Facebook\WebDriver;
4
5/**
6 * Represent a point.
7 */
8class WebDriverPoint
9{
10    private $x;
11    private $y;
12
13    public function __construct($x, $y)
14    {
15        $this->x = $x;
16        $this->y = $y;
17    }
18
19    /**
20     * Get the x-coordinate.
21     *
22     * @return int The x-coordinate of the point.
23     */
24    public function getX()
25    {
26        return (int) $this->x;
27    }
28
29    /**
30     * Get the y-coordinate.
31     *
32     * @return int The y-coordinate of the point.
33     */
34    public function getY()
35    {
36        return (int) $this->y;
37    }
38
39    /**
40     * Set the point to a new position.
41     *
42     * @param int $new_x
43     * @param int $new_y
44     * @return WebDriverPoint The same instance with updated coordinates.
45     */
46    public function move($new_x, $new_y)
47    {
48        $this->x = $new_x;
49        $this->y = $new_y;
50
51        return $this;
52    }
53
54    /**
55     * Move the current by offsets.
56     *
57     * @param int $x_offset
58     * @param int $y_offset
59     * @return WebDriverPoint The same instance with updated coordinates.
60     */
61    public function moveBy($x_offset, $y_offset)
62    {
63        $this->x += $x_offset;
64        $this->y += $y_offset;
65
66        return $this;
67    }
68
69    /**
70     * Check whether the given point is the same as the instance.
71     *
72     * @param WebDriverPoint $point The point to be compared with.
73     * @return bool Whether the x and y coordinates are the same as the instance.
74     */
75    public function equals(self $point)
76    {
77        return $this->x === $point->getX() &&
78        $this->y === $point->getY();
79    }
80}
81