Skip to content

Commit

Permalink
CSS hypot() function sometimes returns the result squared
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=255905
rdar://108487071

Reviewed by Tim Horton.

In cases where the result is computed by CalcExpressionOperation.cpp, the result ends up being squared, because we're missing a sqrt() operation.
The result is correct for cases computed by CSSCalcOperationNode.cpp however, ideally code should be shared to prevent these types of bugs.

* LayoutTests/imported/w3c/web-platform-tests/css/css-values/hypot-pow-sqrt-computed-expected.txt:
* Source/WebCore/platform/calc/CalcExpressionOperation.cpp:
(WebCore::CalcExpressionOperation::evaluate const):

Canonical link: https://commits.webkit.org/263351@main
  • Loading branch information
nt1m committed Apr 25, 2023
1 parent e7b9c37 commit a921171
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Expand Up @@ -18,10 +18,10 @@ PASS calc(1px * hypot(10000)) should be used-value-equivalent to 10000px
PASS calc(2px * sqrt(100000000)) should be used-value-equivalent to 20000px
PASS calc(3px * pow(20, 4)) should be used-value-equivalent to 480000px
PASS calc(-2 * hypot(3px, 4px)) should be used-value-equivalent to -10px
FAIL hypot(0% + 3px, 0% + 4px) should be used-value-equivalent to 5px assert_equals: hypot(0% + 3px, 0% + 4px) and 5px serialize to the same thing in used values. expected "5px" but got "25px"
PASS hypot(0% + 3px, 0% + 4px) should be used-value-equivalent to 5px
PASS hypot(0% + 772.333px) should be used-value-equivalent to calc(0% + 772.333px)
PASS hypot(0% + 772.35px) should be used-value-equivalent to calc(0% + 772.35px)
FAIL hypot(0% + 600px, 0% + 800px) should be used-value-equivalent to 1000px assert_equals: hypot(0% + 600px, 0% + 800px) and 1000px serialize to the same thing in used values. expected "1000px" but got "1000000px"
PASS hypot(0% + 600px, 0% + 800px) should be used-value-equivalent to 1000px
PASS hypot(1px) should be used-value-equivalent to 1px
PASS hypot(1cm) should be used-value-equivalent to 1cm
PASS hypot(1mm) should be used-value-equivalent to 1mm
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/calc/CalcExpressionOperation.cpp
Expand Up @@ -117,7 +117,7 @@ float CalcExpressionOperation::evaluate(float maxValue) const
float value = child->evaluate(maxValue);
sum += (value * value);
}
return sum;
return std::sqrt(sum);
}
case CalcOperator::Sin: {
if (m_children.size() != 1)
Expand Down

0 comments on commit a921171

Please sign in to comment.