Пример #1
0
 public function push(Point $point)
 {
     if (!isset($this->boundary[0]) || $this->boundary[0] > $point->x()) {
         $this->boundary[0] = $point->x();
     }
     if (!isset($this->boundary[1]) || $this->boundary[1] > $point->y()) {
         $this->boundary[1] = $point->y();
     }
     if (!isset($this->boundary[2]) || $this->boundary[2] < $point->x()) {
         $this->boundary[2] = $point->x();
     }
     if (!isset($this->boundary[3]) || $this->boundary[3] < $point->y()) {
         $this->boundary[3] = $point->y();
     }
     return $this;
 }
Пример #2
0
 /**
  * @return string geohash
  * @param Point $point
  * @author algorithm based on code by Alexander Songe <*****@*****.**>
  * @see https://github.com/asonge/php-geohash/issues/1
  */
 private function encodePoint($point, $precision = NULL)
 {
     if ($precision === NULL) {
         $lap = strlen($point->y()) - strpos($point->y(), ".");
         $lop = strlen($point->x()) - strpos($point->x(), ".");
         $precision = pow(10, -max($lap - 1, $lop - 1, 0)) / 2;
     }
     $minlat = -90;
     $maxlat = 90;
     $minlon = -180;
     $maxlon = 180;
     $latE = 90;
     $lonE = 180;
     $i = 0;
     $error = 180;
     $hash = '';
     while ($error >= $precision) {
         $chr = 0;
         for ($b = 4; $b >= 0; --$b) {
             if ((1 & $b) == (1 & $i)) {
                 // even char, even bit OR odd char, odd bit...a lon
                 $next = ($minlon + $maxlon) / 2;
                 if ($point->x() > $next) {
                     $chr |= pow(2, $b);
                     $minlon = $next;
                 } else {
                     $maxlon = $next;
                 }
                 $lonE /= 2;
             } else {
                 // odd char, even bit OR even char, odd bit...a lat
                 $next = ($minlat + $maxlat) / 2;
                 if ($point->y() > $next) {
                     $chr |= pow(2, $b);
                     $minlat = $next;
                 } else {
                     $maxlat = $next;
                 }
                 $latE /= 2;
             }
         }
         $hash .= $this->table[$chr];
         $i++;
         $error = min($latE, $lonE);
     }
     return $hash;
 }
Пример #3
0
 /**
  * construct point from vector (pointing towards the point).
  */
 public static function fromVector(Vector $vector)
 {
     $point = new Point();
     $point->x($vector->x);
     $point->y($vector->y);
     $point->z($vector->z);
     return $point;
 }
Пример #4
0
 /**
  * Checks whether the given point/pixel is in- or outside 
  * of this outline based on the PointPolygonTest of OpenCV.
  *
  * @see docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=pointpolygontest#pointpolygontest
  *
  * @param Point   $point  the point/pixel to check.
  *
  * @return integer        whether the point/pixel is in- (1) or oudsite (2) or on the outline (0).
  * 
  */
 public function contains(Point $point)
 {
     $intersections = 0;
     $v2 = $this->outline[$this->size - 1];
     for ($i = 0; $i < $this->size; $i++) {
         $v1 = $v2;
         $v2 = $this->outline[$i];
         if ($v1->y() <= $point->y() && $v2->y() <= $point->y() || $v1->y() > $point->y() && $v2->y() > $point->y() || $v1->x() < $point->x() && $v2->x() < $point->x()) {
             if ($point->y() == $v2->y() && ($point->x() == $v2->x() || $point->y() == $v1->y() && ($v1->x() <= $point->x() && $point->x() <= $v2->x() || $v2->x() <= $point->x() && $point->x() <= $v1->x()))) {
                 return 0;
             }
             continue;
         }
         $dist = ($point->y() - $v1->y()) * ($v2->x() - $v1->x()) - ($point->x() - $v1->x()) * ($v2->y() - $v1->y());
         if ($dist == 0) {
             return 0;
         }
         if ($v2->y() < $v1->y()) {
             $dist = -$dist;
         }
         $intersections += $dist > 0;
     }
     // If the number of edges we passed through is odd, then it's in the polygon.
     return $intersections % 2 == 0 ? -1 : 1;
 }
Пример #5
0
 public function cellAt(Point $point) : Cell
 {
     return $this->cells[$point->y()][$point->x()];
 }
 /**
  * Get set of weather alerts for the given Point
  *
  * <strong>Only Polish area</strong>
  * @param Point $point location coordinates
  * @return WeatherAlert set of weather alerts
  */
 public function getWeatherAlert(Point $point) : WeatherAlert
 {
     $dto = $this->client->ostrzezenia_pogodowe($point->y(), $point->x(), $this->apiKey);
     return (new WeatherAlert())->withAlert('frost', new Alert($dto->mroz, $dto->mroz_od_dnia, $dto->mroz_do_dnia))->withAlert('heat', new Alert($dto->upal, $dto->upal_od_dnia, $dto->upal_do_dnia))->withAlert('wind', new Alert($dto->wiatr, $dto->wiatr_od_dnia, $dto->wiatr_do_dnia))->withAlert('storm', new Alert($dto->burza, $dto->burza_od_dnia, $dto->burza_do_dnia))->withAlert('tornado', new Alert($dto->traba, $dto->traba_od_dnia, $dto->traba_do_dnia))->withAlert('precipitation', new Alert($dto->opad, $dto->opad_od_dnia, $dto->opad_do_dnia));
 }
Пример #7
0
 /**
  * @param Point $point
  * @return boolean
  */
 public function equals(Point $point)
 {
     return $this->x() == $point->x() && $this->y() == $point->y();
 }
Пример #8
0
 public static function fromPoints(Point $point_a, Point $point_b)
 {
     $vector = new Vector();
     $vector->xyz($point_b->x() - $point_a->x(), $point_b->y() - $point_a->y(), $point_b->z() - $point_a->z());
     return $vector;
 }