diff --git a/src/model_physics.rs b/src/model_physics.rs index 112f521..e6c9f42 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -239,8 +239,47 @@ pub struct TransformedMesh<'a>{ } impl MeshQuery for TransformedMesh<'_>{ fn closest_fev(&self,point:Planar64Vec3)->FEV{ - //put some genius code right here - todo!() + //TODO: put some genius code right here + + //brute force for now + let mut best_distance_squared=Planar64::MAX; + //make something up as default ret + //hopefully empty meshes don't make their way through here + let mut best_fev=FEV::::Vert(VertId(0)); + //check each vert + for i in 0..self.mesh.verts.len(){ + let v=self.vert(VertId(i)); + let d=(v-point).dot(v-point); + if d::Vert(VertId(i)); + } + } + //check each edge + for (i,e) in self.mesh.edge_topology.iter().enumerate(){ + let v0=self.vert(e.verts[0]); + let v1=self.vert(e.verts[1]); + let n=v1-v0; + //n.cross(point-v0)=sin(t)*n*dis + let d=n.dot(point-v0); + if d::Edge(EdgeId(i)); + } + } + } + let face_dots:Vec=self.mesh.faces.iter().map(|f|(*self.normal_transform*f.normal).dot(point)).collect(); + //check each face + for (i,f) in self.mesh.face_topology.iter().enumerate(){ + if face_dots[i]::Face(FaceId(i)); + } + } + best_fev } fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){ let (n,d)=self.mesh.face_nd(face_id);