You are here

private function SassNumber::coercionFactor in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/literals/SassNumber.php \SassNumber::coercionFactor()

Calculates the corecion factor to apply to the value

Parameters

array units being converted from:

array units being converted to:

Return value

float the coercion factor to apply

1 call to SassNumber::coercionFactor()
SassNumber::coerce in phpsass/script/literals/SassNumber.php
Returns the value of this number converted to other units. The conversion takes into account the relationship between e.g. mm and cm, as well as between e.g. in and cm.

File

phpsass/script/literals/SassNumber.php, line 327

Class

SassNumber
SassNumber class. Provides operations and type testing for Sass numbers. Units are of the passed value are converted the those of the class value if it has units. e.g. 2cm + 20mm = 4cm while 2 + 20mm = 22mm. @package PHamlP @subpackage …

Code

private function coercionFactor($fromUnits, $toUnits) {
  $units = $this
    ->removeCommonUnits($fromUnits, $toUnits);
  $fromUnits = $units[0];
  $toUnits = $units[1];
  if (sizeof($fromUnits) !== sizeof($toUnits) || !$this
    ->areConvertable(array_merge($fromUnits, $toUnits))) {
    throw new SassNumberException("Incompatible units: '" . join(' * ', $fromUnits) . "' and '" . join(' * ', $toUnits) . "'", SassScriptParser::$context->node);
  }
  $coercionFactor = 1;
  foreach ($fromUnits as $i => $from) {
    if (array_key_exists($from) && array_key_exists($from)) {
      $coercionFactor *= self::$unitConversion[$toUnits[$i]] / self::$unitConversion[$from];
    }
    else {
      throw new SassNumberException("Incompatible units: '" . join(' * ', $fromUnits) . "' and '" . join(' * ', $toUnits) . "'", SassScriptParser::$context->node);
    }
  }
  return $coercionFactor;
}