-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRaycast.php
More file actions
35 lines (29 loc) · 1.08 KB
/
Raycast.php
File metadata and controls
35 lines (29 loc) · 1.08 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
<?php
// we don't use objects because this is parsing the JSON as received from the firebase server.
class Raycast {
public static function isInside($point, $polygon) {
$polyCorners = count($polygon);
$j = $polyCorners - 1;
$oddNodes = false;
$x = $point['lat'];
$y = $point['long'];
for ($i = 0; $i < $polyCorners; ++$i) {
$pi = $polygon[$i];
$pj = $polygon[$j];
$polyXi = $pi['lat'];
$polyYi = $pi['long'];
$polyXj = $pj['lat'];
$polyYj = $pj['long'];
if (($polyYi < $y && $polyYj >= $y
|| $polyYj < $y && $polyYi >= $y)
&& ($polyXi <= $x || $polyXj <= $x)) {
if ($polyXi + ($y - $polyYi) / ($polyYj - $polyYi) * ($polyXj - $polyXi) < $x) {
$oddNodes = !$oddNodes;
}
}
$j = $i;
}
return $oddNodes;
}
}
?>