/** * 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; }
/** * 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; }