summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/geometry/geometry_util.h
blob: eb89fa1a25188a6d47d85a4149cdd0de8b2cdb28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_GEOMETRY_GEOMETRY_UTIL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_GEOMETRY_GEOMETRY_UTIL_H_

#include <algorithm>
#include <cmath>
#include <limits>

namespace blink {

namespace geometry_util {

// Returns the minimum of |a| and |b|. If either operand is NaN, then NaN is
// returned, consistent with Math.min() in JavaScript.
inline double NanSafeMin(double a, double b) {
  if (std::isnan(a) || std::isnan(b)) {
    return std::numeric_limits<double>::quiet_NaN();
  }
  return std::min(a, b);
}

// Returns the maximum of |a| and |b|. If either operand is NaN, then NaN is
// returned, consistent with Math.max() in JavaScript.
inline double NanSafeMax(double a, double b) {
  if (std::isnan(a) || std::isnan(b)) {
    return std::numeric_limits<double>::quiet_NaN();
  }
  return std::max(a, b);
}

}  // namespace geometry_util

}  // namespace blink

#endif