diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index cffb8b9..f95545a 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -214,47 +214,41 @@ impl Space { .expect("Can't get outta the wall!") } + fn list_objects(&self, tfm: impl Fn(Location) -> Location) -> Vec { + self.objs.iter().map(|&Object { id, loc, r }| Object { id, loc: tfm(loc), r }).collect() + } + fn list_objects_outer(&self) -> Vec { - self.objs.iter().map(|&obj| { - match self.which_subspace(obj.loc.pos) { - Outer => obj, + self.list_objects(|loc| + match self.which_subspace(loc.pos) { + Outer => loc, Inner => { - let Vec2 { x, y } = obj.loc.pos; // в основной СК + let Vec2 { x, y } = loc.pos; // в основной СК let y = self.rect.u(y) + y.signum() * (self.rect.external_halflength - self.rect.internal_halflength); let dy = self.rect.du(y); let m = Mat2::from_cols_array(&[1.0, 0.0, 0.0, dy]); - Object { - id: obj.id, - loc: Location { - pos: vec2(x, y), // в плоском продолжении СК Outer на область Inner - rot: m * obj.loc.rot, - }, - r: obj.r, + Location { + pos: vec2(x, y), // в плоском продолжении СК Outer на область Inner + rot: m * loc.rot, } } - Boundary => panic!("Object {} was destroyed by the space curvature", obj.id), - } - }).collect() + Boundary => panic!("Object at {} was destroyed by the space curvature", loc.pos), + }) } fn list_objects_inner(&self) -> Vec { - self.objs.iter().map(|&obj| { - match self.which_subspace(obj.loc.pos) { + self.list_objects(|Location { pos, rot }| + match self.which_subspace(pos) { Inner | Outer => { // NB: не работает для частей Outer с |y| < external_halflength. Но они и не нужны. - let m = mat2(vec2(1., 0.), vec2(0., self.rect.du(obj.loc.pos.y))); - Object { - id: obj.id, - loc: Location { - pos: vec2(obj.loc.pos.x, self.rect.u(obj.loc.pos.y)), // в плоской СК для Inner или её продолжении на Outer - rot: m * obj.loc.rot, - }, - r: obj.r, + let m = mat2(vec2(1., 0.), vec2(0., self.rect.du(pos.y))); + Location { + pos: vec2(pos.x, self.rect.u(pos.y)), // в плоской СК для Inner или её продолжении на Outer + rot: m * rot, } } - Boundary => panic!("Object {} was destroyed by the space curvature", obj.id), - } - }).collect() + Boundary => panic!("Object at {} was destroyed by the space curvature", pos), + }) } fn hit_objects(objs: &[Object], ray: Ray, limit: f32, globalize: impl Fn(Vec2) -> Vec2) -> Vec {