1+ // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
2+
3+ #pragma once
4+
5+ #include < cmath>
6+ #include < glm/glm.hpp>
7+ #include < glm/gtx/compatibility.hpp>
8+ #include < type_traits>
9+
10+ namespace polyscope {
11+
12+
13+ // Base case: call the scalar version
14+ template <typename T>
15+ bool allComponentsFinite (const T& x) {
16+ return std::isfinite (x);
17+ }
18+
19+ template <>
20+ inline bool allComponentsFinite<glm::vec2>(const glm::vec2& x) {
21+ return glm::all (glm::isfinite (x));
22+ }
23+ template <>
24+ inline bool allComponentsFinite<glm::vec3>(const glm::vec3& x) {
25+ return glm::all (glm::isfinite (x));
26+ }
27+ template <>
28+ inline bool allComponentsFinite<glm::vec4>(const glm::vec4& x) {
29+ return glm::all (glm::isfinite (x));
30+ }
31+
32+ template <>
33+ inline bool allComponentsFinite<glm::uvec2>(const glm::uvec2& x) {
34+ return true ;
35+ }
36+ template <>
37+ inline bool allComponentsFinite<glm::uvec3>(const glm::uvec3& x) {
38+ return true ;
39+ }
40+ template <>
41+ inline bool allComponentsFinite<glm::uvec4>(const glm::uvec4& x) {
42+ return true ;
43+ }
44+
45+ template <>
46+ inline bool allComponentsFinite<glm::mat2x2>(const glm::mat2x2& x) {
47+ for (size_t i = 0 ; i < 2 ; i++)
48+ if (!allComponentsFinite (glm::row (x, i))) return false ;
49+ return true ;
50+ }
51+ template <>
52+ inline bool allComponentsFinite<glm::mat3x3>(const glm::mat3x3& x) {
53+ for (size_t i = 0 ; i < 3 ; i++)
54+ if (!allComponentsFinite (glm::row (x, i))) return false ;
55+ return true ;
56+ }
57+ template <>
58+ inline bool allComponentsFinite<glm::mat4x4>(const glm::mat4x4& x) {
59+ for (size_t i = 0 ; i < 4 ; i++)
60+ if (!allComponentsFinite (glm::row (x, i))) return false ;
61+ return true ;
62+ }
63+
64+ template <>
65+ inline bool allComponentsFinite<std::array<glm::vec3, 2 >>(const std::array<glm::vec3, 2 >& x) {
66+ for (size_t i = 0 ; i < x.size (); i++)
67+ if (!glm::all (glm::isfinite (x[i]))) return false ;
68+ return true ;
69+ }
70+ template <>
71+ inline bool allComponentsFinite<std::array<glm::vec3, 3 >>(const std::array<glm::vec3, 3 >& x) {
72+ for (size_t i = 0 ; i < x.size (); i++)
73+ if (!glm::all (glm::isfinite (x[i]))) return false ;
74+ return true ;
75+ }
76+ template <>
77+ inline bool allComponentsFinite<std::array<glm::vec3, 4 >>(const std::array<glm::vec3, 4 >& x) {
78+ for (size_t i = 0 ; i < x.size (); i++)
79+ if (!glm::all (glm::isfinite (x[i]))) return false ;
80+ return true ;
81+ }
82+
83+
84+ } // namespace polyscope
0 commit comments