You are here

public function TimezonePolygon::isInside in Geo Time Zone 8.3

Same name and namespace in other branches
  1. 8 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()
  2. 8.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()
  3. 6.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()
  4. 6 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()
  5. 7.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()
  6. 7 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon::isInside()

Determine if points are inside the polygon.

Parameters

float $y:

float $x:

Return value

bool

File

src/TimezonePolygon.php, line 36
Contains \Drupal\geotimezone\TimezonePolygon.

Class

TimezonePolygon
Computes if given coordinates are inside the time zone polygon.

Namespace

Drupal\geotimezone

Code

public function isInside($y, $x) {
  $numPoints = count($this->points);
  $jY = $this->points[$numPoints - 2];
  $jX = $this->points[$numPoints - 1];
  $inside = FALSE;
  for ($i = 0; $i < $numPoints;) {
    $iY = $this->points[$i++];
    $iX = $this->points[$i++];
    if ($iY > $y != $jY > $y && $x < ($jX - $iX) * ($y - $iY) / ($jY - $iY) + $iX - 0.0001) {
      $inside = !$inside;
    }
    $jX = $iX;
    $jY = $iY;
  }
  return $inside;
}