Exemple #1
0
 /**
  * Checks whether the two vectors are of the same vector space.
  *
  * @api
  * @param self $b The vector to check against.
  * @return bool True if the vectors are the same vector space, false otherwise.
  */
 public function isSameVectorSpace(self $b)
 {
     return array_keys($this->components()) === array_keys($b->components());
 }
Exemple #2
0
<?php

require "./vendor/nubs/vectorix/src/Vector.php";
use Nubs\Vectorix\Vector;
$v = new Vector([2, 5]);
$ary = $v->components();
print $ary[0] . "  " . $ary[1] . "\n";
$w = $v->multiplyByScalar(3);
$ary = $w->components();
print $ary[0] . "  " . $ary[1] . "\n";
Exemple #3
0
 /**
  * Verify that components() returns the same components the vector was
  * constructed with.
  *
  * In particular, this makes sure that the keys are left alone.
  *
  * @test
  * @covers ::__construct
  * @covers ::components
  */
 public function componentsMaintainStructure()
 {
     $components = [5, 2.4, 'z' => 1.773];
     $vector = new Vector($components);
     $this->assertSame($components, $vector->components());
 }