public static function in($areaDatas,$point) {
$areaArrs = [];
if (!empty($areaDatas)) {
foreach ($areaDatas as $pos) {
$areaArrs[] = [$pos['lng'], $pos['lat']];
}
}
$count = count($areaArrs);
$vertx = [];
$verty = [];
foreach ($areaArrs as $r) {
$vertx[] = $r[0];
$verty[] = $r[1];
}
$cols = [
'count' => $count,
'vertx' => $vertx,
'verty' => $verty
];
$nvert = $cols['count'];
$vertx = $cols['vertx'];
$verty = $cols['verty'];
$testx = $point[0];
$testy = $point[1];
$i = $j = $c = 0;
for ($i = 0, $j = $nvert - 1; $i < $nvert; $j = $i++) {
try{
if (( ($verty[$i] > $testy) != ($verty[$j] > $testy) ) &&
($testx < ($vertx[$j] - $vertx[$i]) * ($testy - $verty[$i]) / ($verty[$j] - $verty[$i]) + $vertx[$i]))
$c = !$c;
}catch (\Throwable $throwable){
$c = false;
}
}
return $c;
}
|