32 auto const le = std::less_equal<double>();
33 auto const ge = std::greater_equal<double>();
34 auto const lt = std::less<double>();
35 auto const gt = std::greater<double>();
43 auto const a_dot_bxc = m_a * bxc;
44 auto const b_dot_axc = m_b * axc;
45 auto const c_dot_axb = m_c * axb;
47 auto const dpos =
pos - m_pos;
52 auto const corner = [
this, &vec, &dist,
a = bxc / a_dot_bxc,
54 c = axb / c_dot_axb](
auto op1,
auto op2,
auto op3,
61 if (op1(A, 0) and op2(B, 0) and op3(C, 0)) {
63 dist = m_direction * vec.
norm();
70 corner(le, le, le, dpos) ||
72 corner(ge, le, le, dpos - m_a) ||
74 corner(le, ge, le, dpos - m_b) ||
76 corner(le, le, ge, dpos - m_c) ||
78 corner(ge, ge, le, dpos - m_a - m_b) ||
80 corner(ge, le, ge, dpos - m_a - m_c) ||
82 corner(le, ge, ge, dpos - m_b - m_c) ||
84 corner(ge, ge, ge, dpos - m_a - m_b - m_c))
87 auto const edge = [
this, &vec, &dist](
auto op1,
auto op2,
90 double const dir1_dot_axis1,
92 double const dir2_dot_axis2,
94 auto const A = (d * axis1) / dir1_dot_axis1;
95 auto const B = (d * axis2) / dir2_dot_axis2;
96 if (op1(A, 0) and op2(B, 0)) {
97 auto const tmp = (d * edge) / edge.norm2();
99 dist = m_direction * vec.
norm();
106 edge(le, le, dpos, axc, b_dot_axc, axb, c_dot_axb, m_a) ||
108 edge(le, le, dpos, bxc, a_dot_bxc, axb, c_dot_axb, m_b) ||
110 edge(le, le, dpos, bxc, a_dot_bxc, axc, b_dot_axc, m_c) ||
112 edge(ge, le, dpos - m_a, bxc, a_dot_bxc, axb, c_dot_axb, m_b) ||
114 edge(ge, le, dpos - m_a, bxc, a_dot_bxc, axc, b_dot_axc, m_c) ||
116 edge(le, ge, dpos - m_b - m_c, bxc, a_dot_bxc, axc, b_dot_axc, m_c) ||
118 edge(le, ge, dpos - m_b - m_c, bxc, a_dot_bxc, axb, c_dot_axb, m_b) ||
120 edge(ge, ge, dpos - m_b - m_c, axc, b_dot_axc, axb, c_dot_axb, m_a) ||
122 edge(ge, le, dpos - m_a - m_b, axc, b_dot_axc, axb, c_dot_axb, m_a) ||
124 edge(ge, ge, dpos - m_a - m_b, bxc, a_dot_bxc, axc, b_dot_axc, m_c) ||
126 edge(le, ge, dpos - m_a - m_c, axc, b_dot_axc, axb, c_dot_axb, m_a) ||
128 edge(ge, ge, dpos - m_a - m_c, bxc, a_dot_bxc, axb, c_dot_axb, m_b))
131 auto const face_outside =
132 [
this, &vec, &dist](
auto op1,
auto op2,
Utils::Vector3d const &distance,
134 double const dir_dot_axis,
int sign) {
135 auto d = distance * axis;
136 if (op1(dir_dot_axis, 0)) {
140 auto const tmp = axis.norm();
142 dist = d * m_direction;
143 if (op2(dir_dot_axis, 0)) {
146 vec = (sign * d / tmp) * axis;
153 face_outside(gt, lt, dpos, axb, c_dot_axb, -1) ||
155 face_outside(gt, gt, dpos, axc, b_dot_axc, +1) ||
157 face_outside(gt, lt, dpos, bxc, a_dot_bxc, -1) ||
159 face_outside(lt, lt, dpos - m_a - m_b - m_c, axb, c_dot_axb, +1) ||
161 face_outside(lt, gt, dpos - m_a - m_b - m_c, axc, b_dot_axc, -1) ||
163 face_outside(lt, lt, dpos - m_a - m_b - m_c, bxc, a_dot_bxc, +1))
172 if (c_dot_axb > 0.0) {
175 auto const tmp = axb.
norm();
177 dist = d * m_direction;
178 if (c_dot_axb < 0.0) {
181 vec = (-d / tmp) * axb;
184 auto const face_inside =
185 [
this, &vec, &dist](
auto op1,
auto op2,
Utils::Vector3d const &distance,
187 double const dir_dot_axis,
int sign) {
188 auto d = distance * axis;
189 if (op1(dir_dot_axis, 0)) {
192 auto const tmp = axis.
norm();
194 if (std::abs(d) < std::abs(dist)) {
195 dist = d * m_direction;
196 if (op2(dir_dot_axis, 0)) {
199 vec = (sign * d / tmp) * axis;
204 face_inside(gt, gt, dpos, axc, b_dot_axc, +1);
206 face_inside(gt, lt, dpos, bxc, a_dot_bxc, -1);
208 face_inside(lt, lt, dpos - m_a - m_b - m_c, axb, c_dot_axb, +1);
210 face_inside(lt, gt, dpos - m_a - m_b - m_c, axc, b_dot_axc, -1);
212 face_inside(lt, lt, dpos - m_a - m_b - m_c, bxc, a_dot_bxc, +1);