Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
scalar.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_GEOMETRY_SCALAR_H_
6#define FLUTTER_IMPELLER_GEOMETRY_SCALAR_H_
7
8#include <cfloat>
9#include <type_traits>
10#include <valarray>
11
13
14namespace impeller {
15
16// NOLINTBEGIN(google-explicit-constructor)
17
18using Scalar = float;
19
20template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
21constexpr T Absolute(const T& val) {
22 return val >= T{} ? val : -val;
23}
24
25constexpr inline bool ScalarNearlyZero(Scalar x,
26 Scalar tolerance = kEhCloseEnough) {
27 return Absolute(x) <= tolerance;
28}
29
30constexpr inline bool ScalarNearlyEqual(Scalar x,
31 Scalar y,
32 Scalar tolerance = kEhCloseEnough) {
33 return ScalarNearlyZero(x - y, tolerance);
34}
35
36struct Degrees;
37
38struct Radians {
40
41 constexpr Radians() = default;
42
43 explicit constexpr Radians(Scalar p_radians) : radians(p_radians) {}
44};
45
46struct Degrees {
48
49 constexpr Degrees() = default;
50
51 explicit constexpr Degrees(Scalar p_degrees) : degrees(p_degrees) {}
52
53 constexpr operator Radians() const {
54 return Radians{degrees * kPi / 180.0f};
55 };
56};
57
58// NOLINTEND(google-explicit-constructor)
59
60} // namespace impeller
61
62#endif // FLUTTER_IMPELLER_GEOMETRY_SCALAR_H_
double y
double x
constexpr float kPi
Definition constants.h:26
float Scalar
Definition scalar.h:18
constexpr float kEhCloseEnough
Definition constants.h:56
constexpr bool ScalarNearlyZero(Scalar x, Scalar tolerance=kEhCloseEnough)
Definition scalar.h:25
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition scalar.h:30
constexpr T Absolute(const T &val)
Definition scalar.h:21
#define T
Scalar degrees
Definition scalar.h:47
constexpr Degrees()=default
constexpr Degrees(Scalar p_degrees)
Definition scalar.h:51
constexpr Radians()=default
Scalar radians
Definition scalar.h:39
constexpr Radians(Scalar p_radians)
Definition scalar.h:43