Unify listing objects
This commit is contained in:
parent
cac83b9003
commit
cf425a34b6
|
|
@ -214,47 +214,41 @@ impl Space {
|
||||||
.expect("Can't get outta the wall!")
|
.expect("Can't get outta the wall!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_objects(&self, tfm: impl Fn(Location) -> Location) -> Vec<Object> {
|
||||||
|
self.objs.iter().map(|&Object { id, loc, r }| Object { id, loc: tfm(loc), r }).collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn list_objects_outer(&self) -> Vec<Object> {
|
fn list_objects_outer(&self) -> Vec<Object> {
|
||||||
self.objs.iter().map(|&obj| {
|
self.list_objects(|loc|
|
||||||
match self.which_subspace(obj.loc.pos) {
|
match self.which_subspace(loc.pos) {
|
||||||
Outer => obj,
|
Outer => loc,
|
||||||
Inner => {
|
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 y = self.rect.u(y) + y.signum() * (self.rect.external_halflength - self.rect.internal_halflength);
|
||||||
let dy = self.rect.du(y);
|
let dy = self.rect.du(y);
|
||||||
let m = Mat2::from_cols_array(&[1.0, 0.0, 0.0, dy]);
|
let m = Mat2::from_cols_array(&[1.0, 0.0, 0.0, dy]);
|
||||||
Object {
|
Location {
|
||||||
id: obj.id,
|
|
||||||
loc: Location {
|
|
||||||
pos: vec2(x, y), // в плоском продолжении СК Outer на область Inner
|
pos: vec2(x, y), // в плоском продолжении СК Outer на область Inner
|
||||||
rot: m * obj.loc.rot,
|
rot: m * loc.rot,
|
||||||
},
|
|
||||||
r: obj.r,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Boundary => panic!("Object {} was destroyed by the space curvature", obj.id),
|
Boundary => panic!("Object at {} was destroyed by the space curvature", loc.pos),
|
||||||
}
|
})
|
||||||
}).collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_objects_inner(&self) -> Vec<Object> {
|
fn list_objects_inner(&self) -> Vec<Object> {
|
||||||
self.objs.iter().map(|&obj| {
|
self.list_objects(|Location { pos, rot }|
|
||||||
match self.which_subspace(obj.loc.pos) {
|
match self.which_subspace(pos) {
|
||||||
Inner | Outer => {
|
Inner | Outer => {
|
||||||
// NB: не работает для частей Outer с |y| < external_halflength. Но они и не нужны.
|
// NB: не работает для частей Outer с |y| < external_halflength. Но они и не нужны.
|
||||||
let m = mat2(vec2(1., 0.), vec2(0., self.rect.du(obj.loc.pos.y)));
|
let m = mat2(vec2(1., 0.), vec2(0., self.rect.du(pos.y)));
|
||||||
Object {
|
Location {
|
||||||
id: obj.id,
|
pos: vec2(pos.x, self.rect.u(pos.y)), // в плоской СК для Inner или её продолжении на Outer
|
||||||
loc: Location {
|
rot: m * rot,
|
||||||
pos: vec2(obj.loc.pos.x, self.rect.u(obj.loc.pos.y)), // в плоской СК для Inner или её продолжении на Outer
|
|
||||||
rot: m * obj.loc.rot,
|
|
||||||
},
|
|
||||||
r: obj.r,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Boundary => panic!("Object {} was destroyed by the space curvature", obj.id),
|
Boundary => panic!("Object at {} was destroyed by the space curvature", pos),
|
||||||
}
|
})
|
||||||
}).collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hit_objects(objs: &[Object], ray: Ray, limit: f32, globalize: impl Fn(Vec2) -> Vec2) -> Vec<Hit> {
|
fn hit_objects(objs: &[Object], ray: Ray, limit: f32, globalize: impl Fn(Vec2) -> Vec2) -> Vec<Hit> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user