Euphoria
approx_equal.cc
Go to the documentation of this file.
1 #include "tests/approx_equal.h"
2 
3 namespace eu::tests
4 {
5  template <typename T>
6  bool
7  is_approximately_equal_xyz(T const& lhs, T const& rhs, const ApproxData& data)
8  {
9  return is_approximately_equal(lhs.x, rhs.x, data)
10  && is_approximately_equal(lhs.y, rhs.y, data)
11  && is_approximately_equal(lhs.z, rhs.z, data);
12  }
13 
14  template <>
15  bool
17  vec3f const& lhs,
18  vec3f const& rhs,
19  const ApproxData& data)
20  {
21  return is_approximately_equal_xyz(lhs, rhs, data);
22  }
23 
24  template <>
25  bool
27  vec4f const& lhs,
28  vec4f const& rhs,
29  const ApproxData& data)
30  {
31  return is_approximately_equal(lhs.x, rhs.x, data)
32  && is_approximately_equal(lhs.y, rhs.y, data)
33  && is_approximately_equal(lhs.z, rhs.z, data)
34  && is_approximately_equal(lhs.w, rhs.w, data)
35  ;
36  }
37 
38  template <>
39  bool
41  Rgb const& lhs,
42  Rgb const& rhs,
43  const ApproxData& data)
44  {
45  return is_approximately_equal(lhs.r, rhs.r, data)
46  && is_approximately_equal(lhs.g, rhs.g, data)
47  && is_approximately_equal(lhs.b, rhs.b, data);
48  }
49 
50  template <>
51  bool
53  Hsl const& lhs,
54  Hsl const& rhs,
55  const ApproxData& data)
56  {
57  return is_approximately_equal(lhs.h.as_degrees(), rhs.h.as_degrees(), data)
58  && is_approximately_equal(lhs.s * 100, rhs.s * 100, data)
59  && is_approximately_equal(lhs.l * 100, rhs.l * 100, data);
60  }
61 
62  template <>
63  bool
65  unit3f const& lhs,
66  unit3f const& rhs,
67  const ApproxData& data)
68  {
69  return is_approximately_equal_xyz(lhs, rhs, data);
70  }
71 
72  template <>
73  bool
75  Rgba const& lhs,
76  Rgba const& rhs,
77  const ApproxData& data)
78  {
79  return is_approximately_equal(lhs.r, rhs.r, data)
80  && is_approximately_equal(lhs.g, rhs.g, data)
81  && is_approximately_equal(lhs.b, rhs.b, data)
82  && is_approximately_equal(lhs.a, rhs.a, data);
83  }
84 
85 
86  template <>
87  bool
89  quatf const& lhs,
90  quatf const& rhs,
91  const ApproxData& data)
92  {
93  return is_approximately_equal(1.0f, dot(lhs, rhs), data);
94  }
95 
96  template <>
97  bool
99  AxisAngle const& lhs,
100  AxisAngle const& rhs,
101  const ApproxData& data)
102  {
104  lhs.angle.as_degrees(), rhs.angle.as_degrees(), data)
105  && is_approximately_equal(lhs.angle.as_degrees(), 0.0f, data))
106  {
107  return true; // zero rotation is always equal zero
108  }
109 
110  const bool a =
111  (
112  is_approximately_equal(rhs.axis, lhs.axis, data) &&
114  );
115  const bool inv =
116  (
117  is_approximately_equal(rhs.axis, -lhs.axis, data) &&
119  );
120  return a || inv;
121  }
122 
123 
124  template <>
125  bool
126  is_approximately_equal(mat4f const& lhs, mat4f const& rhs, const ApproxData& data)
127  {
128  for (int row_index = 0; row_index < 4; row_index += 1)
129  {
130  for (int column_index = 0; column_index < 4; column_index += 1)
131  {
132  if (is_approximately_equal(lhs.get(row_index,column_index), rhs.get(row_index, column_index), data) == false)
133  {
134  return false;
135  }
136  }
137  }
138  return true;
139  }
140 
141 }
bool is_approximately_equal_xyz(T const &lhs, T const &rhs, const ApproxData &data)
Definition: approx_equal.cc:7
bool is_approximately_equal(float const &lhs, float const &rhs, const ApproxData &data)
Definition: approx.cc:20
float dot(const quatf &lhs, const quatf &rhs)
Definition: quat.cc:363
constexpr float as_degrees() const
Definition: angle.h:44
unit3f axis
a unit-vector
Definition: axisangle.h:13
Angle angle
rotation according to right-hand rule
Definition: axisangle.h:16
Definition: rgb.h:104
Angle h
Definition: rgb.h:106
float l
Definition: rgb.h:108
float s
Definition: rgb.h:107
Definition: rgb.h:62
float b
Definition: rgb.h:65
float g
Definition: rgb.h:64
float r
Definition: rgb.h:63
Definition: rgb.h:143
float r
Definition: rgb.h:144
float a
Definition: rgb.h:147
float g
Definition: rgb.h:145
float b
Definition: rgb.h:146
Definition: mat4.h:14
float get(int row, int col) const
Definition: mat4.cc:452
Definition: quat.h:15
Definition: vec3.h:48
Definition: vec4.h:14
float w
Definition: vec4.h:18
float x
Definition: vec4.h:15
float y
Definition: vec4.h:16
float z
Definition: vec4.h:17