Example #1
0
 /**
  * test using an invalid y
  **/
 public function testInvalidPointY()
 {
     $point = new Point($this->VALID_X, $this->INVALID_Y);
     // simply use the $INVALID_IP and an exception will be thrown
     $point->setX($this->VALID_X);
     $point->setY($this->INVALID_Y);
 }
Example #2
0
 protected function wgtochina_lb($wg_flag, $wg_lng, $wg_lat, $wg_heit, $wg_week, $wg_time)
 {
     $x_add;
     $y_add;
     $h_add;
     $x_l;
     $y_l;
     $casm_v;
     $t1_t2;
     $x1_x2;
     $y1_y2;
     $point = new Point();
     if ($wg_heit > 5000) {
         return $point;
     }
     $x_l = $wg_lng;
     $x_l = $x_l / 3686400.0;
     $y_l = $wg_lat;
     $y_l = $y_l / 3686400.0;
     if ($x_l < 72.004) {
         return $point;
     }
     if ($x_l > 137.8347) {
         return $point;
     }
     if ($y_l < 0.8293) {
         return $point;
     }
     if ($y_l > 55.8271) {
         return $point;
     }
     if ($wg_flag == 0) {
         $this->IniCasm($wg_time, $wg_lng, $wg_lat);
         $point = new Point();
         $point->setLatitude($wg_lng);
         $point->setLongitude($wg_lat);
         return $point;
     }
     $this->casm_t2 = $wg_time;
     $t1_t2 = ($this->casm_t2 - $this->casm_t1) / 1000.0;
     if ($t1_t2 <= 0) {
         $this->casm_t1 = $this->casm_t2;
         $this->casm_f = $this->casm_f + 1;
         $this->casm_x1 = $this->casm_x2;
         $this->casm_f = $this->casm_f + 1;
         $this->casm_y1 = $this->casm_y2;
         $this->casm_f = $this->casm_f + 1;
     } else {
         if ($t1_t2 > 120) {
             if ($this->casm_f == 3) {
                 $this->casm_f = 0;
                 $this->casm_x2 = $wg_lng;
                 $this->casm_y2 = $wg_lat;
                 $x1_x2 = $this->casm_x2 - $this->casm_x1;
                 $y1_y2 = $this->casm_y2 - $this->casm_y1;
                 $casm_v = sqrt($x1_x2 * $x1_x2 + $y1_y2 * $y1_y2) / t1_t2;
                 if ($casm_v > 3185) {
                     return $point;
                 }
             }
             $this->casm_t1 = $this->casm_t2;
             $this->casm_f = $this->casm_f + 1;
             $this->casm_x1 = $this->casm_x2;
             $this->casm_f = $this->casm_f + 1;
             $this->casm_y1 = $this->casm_y2;
             $this->casm_f = $this->casm_f + 1;
         }
     }
     $x_add = $this->Transform_yj5($x_l - 105, $y_l - 35);
     $y_add = $this->Transform_yjy5($x_l - 105, $y_l - 35);
     $h_add = $wg_heit;
     $x_add = $x_add + $h_add * 0.001 + $this->yj_sin2($wg_time * 0.0174532925199433) + $this->random_yj();
     $y_add = $y_add + $h_add * 0.001 + $this->yj_sin2($wg_time * 0.0174532925199433) + $this->random_yj();
     $point = new Point();
     $point->setX(($x_l + $this->Transform_jy5($y_l, $x_add)) * 3686400);
     $point->setY(($y_l + $this->Transform_jyj5($y_l, $y_add)) * 3686400);
     return $point;
 }
        $this->x = $Y;
    }
    public function setPoint($object)
    {
        $this->x = $object->x;
        $this->y = $object->y;
    }
    public function getDistance($obj)
    {
        return sqrt($this->getPow($obj));
    }
    private function getPow($obj)
    {
        return pow($this->x - $obj->x, 2) + pow($this->y - $obj->y, 2);
    }
    public function __toString()
    {
        return "Точка с координатам ({$this->x}, {$this->y})";
    }
    public function __destruct()
    {
        echo "<br/> Объект уничтожен";
    }
}
$point = new Point(5, 7);
echo $point . "<br/>";
$point->setX(10);
$point->setY(12);
echo $point . "<br/>";
$point_1 = new Point(9, 11);
echo $point->getDistance($point_1) . "<br/>";
Example #4
0
 /**
  * @param int
  * @throws IllegalArgumentException
  */
 public function setX($x)
 {
     $this->location->setX($x);
 }
<?php

/*КЛОНИРОВАНИЕ ОБЪЕКТОВ*/
//В старых версиях PHP и да же в 4 версии копирование объектов заключалось в том, что создавалась переменная и к ней присваивался существующий объект ($point_2 = $point_1), сейчас с версии PHP5 это не создаст новый объект, а всего лишь создаст ссылку на существующий объект.
//Ключевое слово clone - клонирует объект, создает идентичную копию объекта ($point_3 = clone $point_1)
//Метод __clone() - позволяет изменить значения свойств и методов в классе при клонировании объектов, то есть сначала клонируются объекты при использовании ключевого слово clone, а потом внутри класса меняются значения свойств и методов при помощи метода __clone()
require_once getenv("DOCUMENT_ROOT") . "/lib/config.php";
require_once "Point.php";
$point_1 = new Point(5, 2);
$point_2 = $point_1;
//так делали в старых версиях PHP
echo $point_1->getX() . "<br/>";
echo $point_1->getY() . "<br/>";
echo $point_2->getX() . "<br/>";
echo $point_2->getY() . "<br/>";
$point_2->setX(15);
echo $point_1->getX() . "<br/>";
$point_1->setX(25);
echo $point_2->getX() . "<br/>";
echo "<br/>----------------------------------<br/>";
$point_3 = clone $point_1;
echo $point_3->getX() . "<br/>";
echo $point_3->getY() . "<br/>";
echo $point_1->getX() . "<br/>";
echo $point_1->getY() . "<br/>";
$point_3->setX(17);
echo $point_1->getX() . "<br/>";
echo $point_3->getX() . "<br/>";
echo "<br/>----------------------------------<br/>";
echo $point_1->getY() . "<br/>";
echo $point_3->getY() . "<br/>";