public function operate($env, $op, $other) { $value = Less_Environment::operate($env, $op, $this->value, $other->value); $unit = clone $this->unit; if ($op === '+' || $op === '-') { if (!count($unit->numerator) && !count($unit->denominator)) { $unit->numerator = $other->unit->numerator; $unit->denominator = $other->unit->denominator; } elseif (!count($other->unit->numerator) && !count($other->unit->denominator)) { // do nothing } else { $other = $other->convertTo($this->unit->usedUnits()); if ($env->strictUnits && $other->unit->toString() !== $unit->toCSS()) { throw new Less_CompilerException("Incompatible units. Change the units or use the unit function. Bad units: '" . $unit->toString() . "' and " . $other->unit->toString() + "'."); } $value = Less_Environment::operate($env, $op, $this->value, $other->value); } } elseif ($op === '*') { $unit->numerator = array_merge($unit->numerator, $other->unit->numerator); $unit->denominator = array_merge($unit->denominator, $other->unit->denominator); sort($unit->numerator); sort($unit->denominator); $unit->cancel(); } elseif ($op === '/') { $unit->numerator = array_merge($unit->numerator, $other->unit->denominator); $unit->denominator = array_merge($unit->denominator, $other->unit->numerator); sort($unit->numerator); sort($unit->denominator); $unit->cancel(); } return new Less_Tree_Dimension($value, $unit); }
public function operate($env, $op, $other) { $result = array(); if (!$other instanceof Less_Tree_Color) { $other = $other->toColor(); } for ($c = 0; $c < 3; $c++) { $result[$c] = Less_Environment::operate($env, $op, $this->rgb[$c], $other->rgb[$c]); } return new Less_Tree_Color($result, $this->alpha + $other->alpha); }