-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPoint.php
More file actions
115 lines (105 loc) · 2.52 KB
/
Copy pathPoint.php
File metadata and controls
115 lines (105 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Mindee\Geometry;
use ArrayAccess;
use InvalidArgumentException;
/**
* Representation of the coordinates of a point.
*/
class Point implements ArrayAccess
{
/**
* @var float X coordinate.
*/
private float $x;
/**
* @var float Y coordinate.
*/
private float $y;
/**
* @param float $x Input x coordinate.
* @param float $y Input y coordinate.
*/
public function __construct(float $x, float $y)
{
$this->x = $x;
$this->y = $y;
}
/**
* Retrieves the x coordinate.
*
* @return float
*/
public function getX(): float
{
return $this->x;
}
/**
* Retrieves the y coordinate.
*
* @return float
*/
public function getY(): float
{
return $this->y;
}
/**
* Whether an offset exists.
* @param integer|string $offset Use 0 or 1.
* @return boolean
*/
public function offsetExists($offset): bool
{
if ($offset === 0 || $offset === 1) {
return true;
}
return false;
}
/**
* Get an offset value.
* @param integer|string $offset Use 0 or 1.
* @return float
* @throws InvalidArgumentException If the offset is not 0 or 1.
*/
public function offsetGet($offset): float
{
if ($offset === 0) {
return $this->x;
} elseif ($offset === 1) {
return $this->y;
}
throw new InvalidArgumentException("Use 0 for X or 1 for Y");
}
/**
* Set an offset value.
* @param integer|string $offset Use 0 or 1.
* @param float|integer|string $value Coordinate value to set.
* @return void
* @throws InvalidArgumentException If the offset is not 0 or 1.
*/
public function offsetSet($offset, $value): void
{
if ($offset === 0) {
$this->x = $value;
} elseif ($offset === 1) {
$this->y = $value;
} else {
throw new InvalidArgumentException("Use 0 for X or 1 for Y");
}
}
/**
* Get an offset value.
* @param integer|string $offset Use 0 or 1.
* @return void
* @throws InvalidArgumentException If the offset is not 0 or 1.
*/
public function offsetUnset($offset): void
{
if ($offset === 0) {
unset($this->x);
} elseif ($offset === 1) {
unset($this->y);
} else {
throw new InvalidArgumentException("Use 0 for X or 1 for Y");
}
}
}