1 | /******************************************************************************* |
---|---|
2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. |
3 | The use of this software is governed by the LICENSE file. |
4 | *******************************************************************************/ |
5 | |
6 | #pragma once |
7 | |
8 | #include "taichi/common/core.h" |
9 | #include "geometry_util.h" |
10 | #include "array.h" |
11 | #include "linalg.h" |
12 | |
13 | namespace taichi { |
14 | |
15 | namespace math { |
16 | template <typename T> |
17 | TI_FORCE_INLINE T degrees(T rad) { |
18 | return rad * (type::element<T>(180) / pi); |
19 | } |
20 | |
21 | template <typename T> |
22 | TI_FORCE_INLINE T radians(T deg) { |
23 | return deg * (pi / type::element<T>(180)); |
24 | } |
25 | |
26 | template <typename T> |
27 | TI_FORCE_INLINE |
28 | typename std::enable_if_t<!std::is_floating_point<T>::value, bool> |
29 | equal(const T &A, const T &B, float64 tolerance) { |
30 | return maximum(abs(A - B)) <= tolerance; |
31 | } |
32 | |
33 | template <typename T> |
34 | TI_FORCE_INLINE |
35 | typename std::enable_if_t<std::is_floating_point<T>::value, bool> |
36 | equal(const T &A, const T &B, float64 tolerance) { |
37 | return std::abs(A - B) <= tolerance; |
38 | } |
39 | |
40 | } // namespace math |
41 | |
42 | } // namespace taichi |
43 |