You are here

class TimezonePolygon in Geo Time Zone 8.3

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

Computes if given coordinates are inside the time zone polygon.

@package Drupal\geotimezone

Hierarchy

Expanded class hierarchy of TimezonePolygon

File

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

Namespace

Drupal\geotimezone
View source
class TimezonePolygon {

  /**
   * @var array $points
   */
  private $points = [];

  /**
   * TimezonePolygon constructor.
   */
  public function __construct() {
    $this->points = func_get_args();
  }

  /**
   * Determine if points are inside the polygon.
   *
   * @param float $y
   * @param float $x
   *
   * @return bool
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TimezonePolygon::$points private property
TimezonePolygon::isInside public function Determine if points are inside the polygon.
TimezonePolygon::__construct public function TimezonePolygon constructor.