Created
August 17, 2013 16:00
-
-
Save ronnywang/6257596 to your computer and use it in GitHub Desktop.
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
foreach (City::search("{$x} > x_min AND {$x} < x_max AND {$y} > y_min AND {$y} < y_max") as $city) { | |
$left_node = $right_node = 0; | |
$lastx = $lasty = null; | |
foreach ($city->bounds as $bound) { | |
if (is_null($lastx)) { | |
$lastx = $bound->x; | |
$lasty = $bound->y; | |
continue; | |
} | |
if (($bound->y >= $y and $y >= $lasty) or ($lasty >= $y and $y >= $bound->y)) { | |
if ($x >= $bound->x and $x >= $lastx) { | |
$right_node ++; | |
} elseif ($x <= $bound->x and $x <= $lastx) { | |
$left_node ++; | |
} else { | |
$deltax = $bound->x - $lastx; | |
$deltay = $bound->y - $lasty; | |
$tempx = ($y - $lasty) * $deltax / $deltay + $lastx; | |
if ($x >= $deltax) { | |
$right_node ++; | |
} else { | |
$left_node ++; | |
} | |
} | |
} | |
$lastx = $bound->x; | |
$lasty = $bound->y; | |
} | |
if ($left_node % 2 == 1 && $right_node % 2 == 1){ | |
echo $city->city . ' ' . $city->sub_city; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment