hypot static method
Creates a hypot()
calculation with the given arguments
.
Each argument must be either a SassNumber, a SassCalculation, an unquoted SassString, or a CalculationOperation. It must be passed at least one argument.
This automatically simplifies the calculation, so it may return a SassNumber rather than a SassCalculation. It throws an exception if it can determine that the calculation will definitely produce invalid CSS.
Implementation
static Value hypot(Iterable<Object> arguments) {
var args = _simplifyArguments(arguments);
if (args.isEmpty) {
throw ArgumentError("hypot() must have at least one argument.");
}
_verifyCompatibleNumbers(args);
var subtotal = 0.0;
var first = args.first;
if (first is! SassNumber || first.hasUnit('%')) {
return SassCalculation._("hypot", args);
}
for (var i = 0; i < args.length; i++) {
var number = args.elementAt(i);
if (number is! SassNumber || !number.hasCompatibleUnits(first)) {
return SassCalculation._("hypot", args);
}
var value =
number.convertValueToMatch(first, "numbers[${i + 1}]", "numbers[1]");
subtotal += value * value;
}
return SassNumber.withUnits(math.sqrt(subtotal),
numeratorUnits: first.numeratorUnits,
denominatorUnits: first.denominatorUnits);
}