private function SassNumber::coercionFactor in Sassy 7
Same name and namespace in other branches
- 7.3 phpsass/script/literals/SassNumber.php \SassNumber::coercionFactor()
* Calculates the corecion factor to apply to the value *
Parameters
array units being converted from: * @param array units being converted to * @return float the coercion factor to apply
1 call to SassNumber::coercionFactor()
- SassNumber::coerce in phamlp/
sass/ 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. * * If this number is unitless, it will simply return itself with…
File
- phamlp/
sass/ script/ literals/ SassNumber.php, line 329
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 =…
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: '{from}' and '{to}'", array(
'{from}' => join(' * ', $fromUnits),
'{to}' => 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: '{from}' and '{to}", array(
'{from}' => join(' * ', $fromUnits),
'{to}' => join(' * ', $toUnits),
), SassScriptParser::$context->node);
}
}
return $coercionFactor;
}