/** * Checks the presence of a point in the polygon * Returns : * 0 : Point not in polygon * 1 : Point in polygon * 2 : Point is a node of the polygon * * @see http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test */ public function includes(Point $point) { $return = 0; //Whole area check : does it include the center ? $includes_point = false; $origin = new Point(-1, -1); $airePointAKey = count($this->points) - 1; for ($airePointBKey = 0; $airePointBKey < count($this->points); $airePointBKey++) { if ($point->guid == $this->points[$airePointBKey]->guid) { $return = 2; break; } if (Point::isCrossing($origin, $point, $this->points[$airePointAKey], $this->points[$airePointBKey])) { $includes_point = !$includes_point; } $airePointAKey++; if ($airePointAKey == count($this->points)) { $airePointAKey = 0; } } if ($return == 0) { $return = (int) $includes_point; } return $return; }