-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObstuctionDetector.php
49 lines (38 loc) · 1.4 KB
/
ObstuctionDetector.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
<?php
class ObstuctionDetector
{
public static int|float $speed;
public static array $point_a;
public static array $point_b;
public function __construct(int|float $speed, array $point_a, array $point_b)
{
// Set the speed and distance for the current object instance.
self::$speed = $speed;
self::$point_a = $point_a;
self::$point_b = $point_b;
}
public static function getDistance(): float|int
{
// calculate the distance between two points and return the result in miles
$result = sqrt(pow(self::$point_b[0] - self::$point_a[0], 2) + pow(self::$point_b[1] - self::$point_b[1], 2));
return $result;
}
public static function getExpectedTime(float|int $distance): float|int
{
// Calculate the expected time to get from point A to Point B
// Expected time = distance/speed.
$result = $distance/self::$speed;
return $result;
}
public static function isPenetrable(int|float $timeDuration): bool
{
$distance = self::getDistance();
$expectedTime = self::getExpectedTime($distance);
// Check if obstruction is penetrable or not and return boolean result
// Obstuction is mpenetrable if timeDuration if greater than expected time by 60Mins
if ($timeDuration > ($expectedTime + 60)) {
return false;
}
return true;
}
}