/** * @param GridInterface $grid * @param UnitComposition $unitComposition * @param int|float $tickLength This is how much time passes per tick, in seconds. * * @throws EngineException * @throws \Exception */ public function __construct(GridInterface $grid, UnitComposition $unitComposition, $tickLength = 1) { $this->grid = $grid; $this->unitComposition = $unitComposition; if ($tickLength instanceof Time) { $this->tickLength = $tickLength; } elseif (is_numeric($tickLength)) { $this->tickLength = $this->unitComposition->getUnitClass(UnitComposition::TIME, $tickLength); } else { throw new EngineException('Invalid tick length.'); } }
public function testMomentum() { $unit = new UnitComposition(); $momentum = $unit->getUnitClass(UnitComposition::MOMENTUM); $mass = $unit->getUnitClass(UnitComposition::MASS); $velocity = $unit->getUnitClass(UnitComposition::VELOCITY); $momentum->preConvertedAdd(1); $mass->preConvertedAdd(1); $velocity->preConvertedAdd(1); $this->assertInstanceOf('Samsara\\Newton\\Units\\Mass', PhysicsProvider::momentumCalcs($momentum, $velocity)); $this->assertInstanceOf('Samsara\\Newton\\Units\\Momentum', PhysicsProvider::momentumCalcs($mass, $velocity)); $this->assertInstanceOf('Samsara\\Newton\\Units\\Velocity', PhysicsProvider::momentumCalcs($momentum, $mass)); }