/** * @param string $op */ public function operate($op, $other) { $rgb = array(); $alpha = $this->alpha * (1 - $other->alpha) + $other->alpha; for ($c = 0; $c < 3; $c++) { $rgb[$c] = Less_Functions::operate($op, $this->rgb[$c], $other->rgb[$c]); } return new Less_Tree_Color($rgb, $alpha); $result = array(); if (!$other instanceof Less_Tree_Color) { $other = $other->toColor(); } for ($c = 0; $c < 3; $c++) { $result[$c] = Less_Functions::operate($op, $this->rgb[$c], $other->rgb[$c]); } return new Less_Tree_Color($result, $this->alpha + $other->alpha); }
/** * @param string $op */ public function operate($op, $other) { $value = Less_Functions::operate($op, $this->value, $other->value); $unit = clone $this->unit; if ($op === '+' || $op === '-') { if (!$unit->numerator && !$unit->denominator) { $unit->numerator = $other->unit->numerator; $unit->denominator = $other->unit->denominator; } elseif (!$other->unit->numerator && !$other->unit->denominator) { // do nothing } else { $other = $other->convertTo($this->unit->usedUnits()); if (Less_Parser::$options['strictUnits'] && $other->unit->toString() !== $unit->toCSS()) { throw new Less_Exception_Compiler("Incompatible units. Change the units or use the unit function. Bad units: '" . $unit->toString() . "' and " . $other->unit->toString() + "'."); } $value = Less_Functions::operate($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); }
/** * @param string $op */ public function operate($op, $other) { $rgb = array(); $alpha = $this->alpha * (1 - $other->alpha) + $other->alpha; for ($c = 0; $c < 3; $c++) { $rgb[$c] = Less_Functions::operate($op, $this->rgb[$c], $other->rgb[$c]); } return new Less_Tree_Color($rgb, $alpha); }