Created
November 22, 2018 01:09
-
-
Save javymarmol/907c2af96f94fb0f7aa48a1cddd4be0b to your computer and use it in GitHub Desktop.
check point into a a polygone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function checkCoverage2(Request $request){ | |
$y = $request["lat"]; | |
$x = $request["lng"]; | |
$offices = Office::all(); | |
$inside = false; | |
foreach ($offices as $office){ | |
$zone = json_decode($office->zone); | |
$points = $zone->points; | |
if($points){ | |
$p1 = $points[0]; | |
$n = count($points); | |
$c = 0; | |
for ($i = 0; $i < count($points); $j = $i++) { | |
$p2 = $points[($i + 1) % $n]; | |
if ($x > min($p1->long, $p2->long) | |
&& $x <= max($p1->long, $p2->long) | |
&& $y <= max($p1->lat, $p2->lat) | |
&& $p1->long != $p2->long ) { | |
$x_inters = ($x - $p1->long) * ($p2->lat - $p1->lat)/($p2->long - $p1->long) + $p1->lat; | |
if ($p1->lat == $p2->lat || $y <= $x_inters) { | |
$c++; | |
} | |
} | |
$p1 = $p2; | |
} | |
if ($c%2 != 0){ | |
return response()->json(['status' => $inside,'data' =>$office]) | |
->setStatusCode(Response::HTTP_OK, Response::$statusTexts[ Response::HTTP_OK ]); | |
} | |
} | |
} | |
return response()->json(['status' => $inside,'data' => ['error' => 'no coverage', 'message' => 'No hay cobertura'], 'message' => 'No hay cobertura']) | |
->setStatusCode(Response::HTTP_OK, Response::$statusTexts[ Response::HTTP_OK ]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment