From 64657e718d148b33737b43e9f45a586f8b7bdbca Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 27 Oct 2023 15:10:38 -0700 Subject: [PATCH] cow: utter brilliance --- src/face_crawler.rs | 8 ++++---- src/model_physics.rs | 35 ++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/face_crawler.rs b/src/face_crawler.rs index d6ad1a9..2e64cc2 100644 --- a/src/face_crawler.rs +++ b/src/face_crawler.rs @@ -34,7 +34,7 @@ impl State>{ } } //test each edge collision time, ignoring roots with zero or conflicting derivative - for &(edge_id,test_face_id) in mesh.face_edges(face_id){ + for &(edge_id,test_face_id) in mesh.face_edges(face_id).iter(){ let (n,d)=mesh.face_nd(test_face_id); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); @@ -49,7 +49,7 @@ impl State>{ }, &FEV::::Edge(edge_id)=>{ //test each face collision time, ignoring roots with zero or conflicting derivative - for &test_face_id in mesh.edge_side_faces(edge_id){ + for &test_face_id in mesh.edge_side_faces(edge_id).iter(){ let (n,d)=mesh.face_nd(test_face_id); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); @@ -61,7 +61,7 @@ impl State>{ } } //test each vertex collision time, ignoring roots with zero or conflicting derivative - for &(vert_id,test_face_id) in mesh.edge_ends(edge_id){ + for &(vert_id,test_face_id) in mesh.edge_ends(edge_id).iter(){ let (n,d)=mesh.face_nd(test_face_id); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); @@ -76,7 +76,7 @@ impl State>{ }, &FEV::::Vert(vertex_id)=>{ //test each edge collision time, ignoring roots with zero or conflicting derivative - for &(edge_id,test_face_id) in mesh.vert_edges(vertex_id){ + for &(edge_id,test_face_id) in mesh.vert_edges(vertex_id).iter(){ let (n,d)=mesh.face_nd(test_face_id); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); diff --git a/src/model_physics.rs b/src/model_physics.rs index 5428015..47ef167 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -1,4 +1,5 @@ use crate::integer::{Planar64,Planar64Vec3}; +use std::borrow::Cow; #[derive(Clone,Copy)] pub struct VertId(usize); @@ -39,14 +40,14 @@ pub struct PhysicsMesh{ vert_topology:Vec, } -pub trait MeshQuery{ +pub trait MeshQuery{ fn closest_fev(&self,point:Planar64Vec3)->FEV; fn face_nd(&self,face_id:FACE)->(Planar64Vec3,Planar64); fn vert(&self,vert_id:VERT)->Planar64Vec3; - fn face_edges(&self,face_id:FACE)->&Vec<(EDGE,FACE)>; - fn edge_side_faces(&self,edge_id:EDGE)->&[FACE;2]; - fn edge_ends(&self,edge_id:EDGE)->&[(VERT,FACE);2]; - fn vert_edges(&self,vert_id:VERT)->&Vec<(EDGE,FACE)>; + fn face_edges(&self,face_id:FACE)->Cow>; + fn edge_side_faces(&self,edge_id:EDGE)->Cow<[FACE;2]>; + fn edge_ends(&self,edge_id:EDGE)->Cow<[(VERT,FACE);2]>; + fn vert_edges(&self,vert_id:VERT)->Cow>; } impl MeshQuery for PhysicsMesh{ fn closest_fev(&self,point:Planar64Vec3)->FEV{ @@ -60,17 +61,17 @@ impl MeshQuery for PhysicsMesh{ fn vert(&self,vert_id:VertId)->Planar64Vec3{ todo!() } - fn face_edges(&self,face_id:FaceId)->&Vec<(EdgeId,FaceId)>{ - &self.face_topology[face_id.0].edges + fn face_edges(&self,face_id:FaceId)->Cow>{ + Cow::Borrowed(&self.face_topology[face_id.0].edges) } - fn edge_side_faces(&self,edge_id:EdgeId)->&[FaceId;2]{ - &self.edge_topology[edge_id.0].faces + fn edge_side_faces(&self,edge_id:EdgeId)->Cow<[FaceId;2]>{ + Cow::Borrowed(&self.edge_topology[edge_id.0].faces) } - fn edge_ends(&self,edge_id:EdgeId)->&[(VertId,FaceId);2]{ - &self.edge_topology[edge_id.0].verts + fn edge_ends(&self,edge_id:EdgeId)->Cow<[(VertId,FaceId);2]>{ + Cow::Borrowed(&self.edge_topology[edge_id.0].verts) } - fn vert_edges(&self,vert_id:VertId)->&Vec<(EdgeId,FaceId)>{ - &self.vert_topology[vert_id.0].edges + fn vert_edges(&self,vert_id:VertId)->Cow>{ + Cow::Borrowed(&self.vert_topology[vert_id.0].edges) } } @@ -134,16 +135,16 @@ impl MeshQuery for MinkowskiMesh<'_>{ fn vert(&self,vert_id:MinkowskiVert)->Planar64Vec3{ todo!() } - fn face_edges(&self,face_id:MinkowskiFace)->&Vec<(MinkowskiEdge,MinkowskiFace)>{ + fn face_edges(&self,face_id:MinkowskiFace)->Cow>{ todo!() } - fn edge_side_faces(&self,edge_id:MinkowskiEdge)->&[MinkowskiFace;2]{ + fn edge_side_faces(&self,edge_id:MinkowskiEdge)->Cow<[MinkowskiFace;2]>{ todo!() } - fn edge_ends(&self,edge_id:MinkowskiEdge)->&[(MinkowskiVert,MinkowskiFace);2]{ + fn edge_ends(&self,edge_id:MinkowskiEdge)->Cow<[(MinkowskiVert,MinkowskiFace);2]>{ todo!() } - fn vert_edges(&self,vert_id:MinkowskiVert)->&Vec<(MinkowskiEdge,MinkowskiFace)>{ + fn vert_edges(&self,vert_id:MinkowskiVert)->Cow>{ todo!() } }