예제 #1
0
 /**
  * @param CartesianCoordinates $min
  * @param CartesianCoordinates $size
  */
 public function __construct($min, $size)
 {
     $this->min = $min;
     $this->size = $size;
     $this->max = $min->add($size);
 }
예제 #2
0
        return "(" . $this->x . ", " . $this->y . ")";
    }
    public function add(Coordinates $other)
    {
        return new self($this->x + $other->x, $this->y + $other->y);
    }
    public function scale($factor)
    {
        return new self($this->x * $factor, $this->y * $factor);
    }
    public function length()
    {
        return abs($this->x) + abs($this->y);
    }
    public function getUniqueIndex()
    {
        return $this->__toString();
    }
}
if (!debug_backtrace()) {
    $a = new CartesianCoordinates(20, 10);
    $b = $a->scale(0.1);
    $c = $a->add($b->scale(-1));
    $d = $a->subtract($b);
    echo $a;
    echo $b;
    echo $c;
    echo $d;
    echo $d->length();
    var_dump($a->getNeighbors());
}