Simplify code
This commit is contained in:
parent
4caa260a34
commit
2515c0a0da
|
|
@ -194,10 +194,6 @@ impl Rect {
|
|||
let t = ts.min_element();
|
||||
Some(t)
|
||||
}
|
||||
|
||||
fn visualise(&self) -> Vec<Vec2> {
|
||||
vec![vec2(-self.size.x, -self.size.y), vec2(self.size.x, -self.size.y), vec2(self.size.x, self.size.y), vec2(-self.size.x, self.size.y)]
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -234,32 +230,12 @@ struct TubeInside {
|
|||
|
||||
impl TubeInside {
|
||||
fn is_inside(&self, pos: Vec2) -> bool {
|
||||
let bnd = self.local_bounds();
|
||||
pos.cmpge(bnd.0).all() && pos.cmple(bnd.1).all()
|
||||
pos.abs().cmple(self.size()).all()
|
||||
}
|
||||
|
||||
fn to_boundary(&self, ray: Ray) -> Option<f32> {
|
||||
assert!(self.is_inside(ray.pos));
|
||||
let sgn = ray.dir.signum();
|
||||
let p = ray.pos * sgn;
|
||||
let v = ray.dir * sgn;
|
||||
let mut bnd = self.local_bounds();
|
||||
if sgn.x < 0.0 {
|
||||
(bnd.0.x, bnd.1.x) = (-bnd.1.x, -bnd.0.x);
|
||||
}
|
||||
if sgn.y < 0.0 {
|
||||
(bnd.0.y, bnd.1.y) = (-bnd.1.y, -bnd.0.y);
|
||||
}
|
||||
let t = if (bnd.1.x - p.x) * v.y <= (bnd.1.y - p.y) * v.x {
|
||||
(bnd.1.x - p.x) / v.x
|
||||
} else {
|
||||
(bnd.1.y - p.y) / v.y
|
||||
};
|
||||
if t <= 100000.0 {
|
||||
Some(t)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Rect { size: self.size() }.trace_out_of(ray)
|
||||
}
|
||||
|
||||
fn pos_to_global(&self, pos: Vec2) -> Vec2 {
|
||||
|
|
@ -284,7 +260,7 @@ impl TubeInside {
|
|||
}
|
||||
}
|
||||
|
||||
fn local_bounds(&self) -> (Vec2, Vec2) {
|
||||
(vec2(-self.tube.inner_radius, -self.tube.internal_halflength), vec2(self.tube.inner_radius, self.tube.internal_halflength))
|
||||
fn size(&self) -> Vec2 {
|
||||
vec2(self.tube.inner_radius, self.tube.internal_halflength)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user