Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f60a76e

Browse files
Mike KleinSkia Commit-Bot
authored andcommitted
switch SkTPin impl to pin NaN to lo
It's just much easier to remember and think about max(lo, min(x, hi)) than max(min(hi, x), lo), and both pin NaN to one of the two limits. I'm not sure if anything in Skia depends on which limit we pin to. Change-Id: Iceca36a8fffd7072180e82b8b6eb81cbdb5ac97f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327788 Commit-Queue: Chris Dalton <csmartdalton@google.com> Auto-Submit: Mike Klein <mtklein@google.com> Reviewed-by: Chris Dalton <csmartdalton@google.com>
1 parent 5f90ee0 commit f60a76e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

include/private/SkTPin.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
/** @return x pinned (clamped) between lo and hi, inclusively.
1414
1515
Unlike std::clamp(), SkTPin() always returns a value between lo and hi.
16-
If x is NaN, SkTPin() returns hi but std::clamp() returns NaN.
16+
If x is NaN, SkTPin() returns lo but std::clamp() returns NaN.
1717
*/
1818
template <typename T>
1919
static constexpr const T& SkTPin(const T& x, const T& lo, const T& hi) {
20-
// TODO: return std::max(lo, std::min(x, hi)) ? (clamps NaN to lo)
21-
return std::max(std::min(hi, x), lo);
20+
return std::max(lo, std::min(x, hi));
2221
}
2322

2423
#endif

0 commit comments

Comments
 (0)