forked from aternosorg/hawk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
McCoordinatesFloat.php
63 lines (54 loc) · 1.55 KB
/
McCoordinatesFloat.php
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
<?php
namespace Aternos\Hawk;
class McCoordinatesFloat extends McCoordinates
{
public float $y;
public static function get3DCoordinates(McCoordinatesFloat $coordinates): McCoordinates3D
{
return new McCoordinates3D(floor($coordinates->x), floor($coordinates->y), floor($coordinates->z));
}
public function __construct(float $x, float $y, float $z)
{
parent::__construct($x, $z);
$this->y = $y;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->x . ", " . $this->y . ", " . $this->z;
}
/**
* @param McCoordinatesFloat $coordinates
* @return float
*/
public function getDelta(McCoordinatesFloat $coordinates): float
{
$delta = 0;
$delta += abs($this->x - $coordinates->x);
$delta += abs($this->y - $coordinates->y);
$delta += abs($this->z - $coordinates->z);
return $delta / 3;
}
/**
* @param McCoordinatesFloat $coordinates
* @param float $delta
* @return bool
*/
public function equals(McCoordinates $coordinates, float $delta = 0.0000000001): bool
{
return $this->getDelta($coordinates) <= $delta;
}
// /**
// * @param McCoordinates $coordinates
// * @return bool
// */
// public function equals(McCoordinates $coordinates): bool
// {
// if ($coordinates instanceof McCoordinatesFloat) {
// return parent::equals($coordinates) && $this->y === $coordinates->y;
// }
// return false;
// }
}