oxiphysics_geometry/implicit_geometry/
sdftriangularprism_traits.rs1#[allow(unused_imports)]
12use super::functions::*;
13#[allow(unused_imports)]
14use super::functions::*;
15use super::types::SdfTriangularPrism;
16
17impl Sdf for SdfTriangularPrism {
18 fn dist(&self, p: [f64; 3]) -> f64 {
19 let h = [self.side, self.half_height];
20 let q = [p[0].abs(), p[1], p[2].abs()];
21 let k = 3.0_f64.sqrt();
22 let qx = q[0] - clamp_f(q[0] - k * q[2], 0.0, 1.0) * h[0] / 2.0;
23 let qz = q[2] - clamp_f(q[0] - k * q[2], 0.0, 1.0) * h[0] / (2.0 * k);
24 let d1 = len2([qx, qz])
25 * if q[0] - h[0] / 2.0 < 0.0 && k * q[2] - q[0] < 0.0 {
26 -1.0
27 } else {
28 1.0
29 };
30 let d2 = q[1] - h[1];
31 -((-d1).max(-d2)).min(0.0) + len2([d1.max(0.0), d2.max(0.0)])
32 }
33}