You are here

public function AbstractUnitsMathematicalOperator::isolateOperand in Units of Measurement 7.2

Numerically isolate a certain operand of this mathematical expression.

Given result of this mathematical expression, numerically, i.e. dimensionlessly isolate a certain operand of this mathematical expression.

Parameters

\UnitsMathematicalExpression $equal_expression: Result of this mathematical expression

int $operand_to_isolate: What operand of this mathematical expression to isolate. Allowed values are:

  • 1: to isolate operand #1
  • 2: to isolate operand #2

Return value

UnitsConstantMathematicalExpression Mathematical expression to which the isolated member numerically equals

Overrides UnitsMathematicalOperatorInterface::isolateOperand

File

./units.module, line 1548
Provide API for managing and converting units of measurement.

Class

AbstractUnitsMathematicalOperator
Abstract implementation of "mathematical operator" interface.

Code

public function isolateOperand(UnitsMathematicalExpression $equal_expression, $operand_to_isolate) {
  $isolate_callback = ctools_plugin_get_function($this->operator, 'isolate operand callback');
  if ($isolate_callback) {
    list($operand1, $operand2) = $this
      ->evaluateOperands();
    if ($operand_to_isolate == 1) {
      $operand1 = $this
        ->operand1();
      $operand2 = new UnitsConstantMathematicalExpression($operand2);
    }
    else {
      $operand1 = new UnitsConstantMathematicalExpression($operand1);
      $operand2 = $this
        ->operand2();
    }
    return $isolate_callback($operand1, $operand2, $equal_expression, $operand_to_isolate);
  }
}