class TimezonePolygon in Geo Time Zone 7
Same name and namespace in other branches
- 8.3 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
- 8 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
- 8.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
- 6.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
- 6 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
- 7.2 src/TimezonePolygon.php \Drupal\geotimezone\TimezonePolygon
Computes if given coordinates are inside the timezone polygon.
@package Drupal\geotimezone
Hierarchy
- class \Drupal\geotimezone\TimezonePolygon
Expanded class hierarchy of TimezonePolygon
File
- src/
TimezonePolygon.php, line 15 - Contains \Drupal\geotimezone\TimezonePolygon.
Namespace
Drupal\geotimezoneView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TimezonePolygon:: |
private | property | ||
TimezonePolygon:: |
public | function | Determine if points are inside the polygon. | |
TimezonePolygon:: |
public | function | TimezonePolygon constructor. |