/** * Returns the dimensionless dimension. * * @return Dimension */ public static function NONE() { if (!is_object(self::$none)) { self::$none = new self(SystemOfUnits::ONE()); } return self::$none; }
public function getBaseUnits() { /** @var CompoundUnit $result */ $result = SystemOfUnits::ONE(); foreach ($this->elements as $element) { $unit = $element->unit->getBaseUnits(); $unit = $unit->pow($element->pow); $unit = $unit->root($element->root); $result = $result->times($unit); } return $result; }
public function inverse() { return CompoundBuilder::getQuotientInstance(SystemOfUnits::ONE(), $this); }
/** * Merges the given elements. * * @param CompoundElement[] $leftElements * @param CompoundElement[] $rightElements * @param string $quantity * @param string $symbol * * @return CompoundUnit */ private static function getInstance(array $leftElements, array $rightElements, $quantity = '', $symbol = '') { $result = []; foreach ($leftElements as $leftElement) { $pow1 = $leftElement->pow; $root1 = $leftElement->root; $pow2 = 0; $root2 = 1; foreach ($rightElements as $rightElement) { if ($leftElement->unit->equals($rightElement->unit)) { $pow2 = $rightElement->pow; $root2 = $rightElement->root; break; } } $pow = $pow1 * $root2 + $pow2 * $root1; $root = $root1 * $root2; if ($pow != 0) { $gcd = self::gcd(abs($pow), $root); $result[] = new CompoundElement($leftElement->unit, $pow / $gcd, $root / $gcd); } } foreach ($rightElements as $rightElement) { $hasBeenMerged = false; foreach ($leftElements as $leftElement) { if ($rightElement->unit->equals($leftElement->unit)) { $hasBeenMerged = true; break; } } if (!$hasBeenMerged) { $result[] = $rightElement; } } if (count($result) == 0) { return SystemOfUnits::ONE(); } if (count($result) == 1 && $result[0]->pow == $result[0]->root) { return $result[0]->unit; } return new CompoundUnit($result, $quantity, $symbol); }