Exemplo n.º 1
0
 /**
  * Subtracts the two given vectors from each other.
  *
  * @param Vector $lft The left vector.
  * @param Vector $rgt The right vector.
  * @return Vector
  * @throws InvalidArgumentException Thrown when the given vector is of a different length.
  */
 public static function subtract(Vector $lft, Vector $rgt)
 {
     if ($lft->getSize() != $rgt->getSize()) {
         throw new InvalidArgumentException('Invalid vectors provided, should be of the same size.');
     }
     $vectorSize = $lft->getSize();
     $result = new Vector($lft);
     for ($i = 0; $i < $vectorSize; ++$i) {
         $result[$i]->subtract($rgt[$i]);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Subtracts the given vector from this vector.
  *
  * @param Vector $vector The vector to sutbract.
  * @return Vector
  * @throws InvalidArgumentException Thrown when the given vector is of a different length.
  */
 public function subtract(Vector $vector)
 {
     if ($this->getSize() != $vector->getSize()) {
         throw new InvalidArgumentException('Invalid vector provided, should be of the same size.');
     }
     foreach ($this as $index => $value) {
         $this[$index]->subtract($vector[$index]);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Initializes a new instance of this class.
  *
  * @param float $x The X-component to set.
  * @param float $y The Y-component to set.
  */
 public function __construct($x, $y)
 {
     parent::__construct(array());
     $this->setX($x);
     $this->setY($y);
 }
Exemplo n.º 4
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testSubtractInvalid()
 {
     // Arrange
     $vector1 = new Vector(array(1, 2, 3));
     $vector2 = new Vector(array(1, 2, 3, 4));
     // Act
     $vector1->subtract($vector2);
 }