From a359650ff83325ecaa78d3a26021fc1f30fa4df5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 2 Dec 2023 01:58:18 -0800 Subject: [PATCH] use relative position to avoid overflow --- src/face_crawler.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/face_crawler.rs b/src/face_crawler.rs index 86dee9c9..d60e11be 100644 --- a/src/face_crawler.rs +++ b/src/face_crawler.rs @@ -33,9 +33,8 @@ enum Transition{ let edge_n=mesh.directed_edge_n(directed_edge_id); let n=n.cross(edge_n); let verts=mesh.edge_verts(directed_edge_id.as_undirected()); - let d=n.dot(mesh.vert(verts[0])+mesh.vert(verts[1])); //WARNING: d is moved out of the *2 block because of adding two vertices! - for t in zeroes2(n.dot(body.position)*2-d,n.dot(body.velocity)*2,n.dot(body.acceleration)){ + for t in zeroes2(n.dot(body.position*2-(mesh.vert(verts[0])+mesh.vert(verts[1]))),n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); if time<=t&&t{ //test each face collision time, ignoring roots with zero or conflicting derivative let edge_n=mesh.edge_n(edge_id); let edge_verts=mesh.edge_verts(edge_id); - let vert_sum=mesh.vert(edge_verts[0])+mesh.vert(edge_verts[1]); + let delta_pos=body.position*2-(mesh.vert(edge_verts[0])+mesh.vert(edge_verts[1])); for (i,&edge_face_id) in mesh.edge_faces(edge_id).iter().enumerate(){ let face_n=mesh.face_nd(edge_face_id).0; //edge_n gets parity from the order of edge_faces let n=face_n.cross(edge_n)*((i as i64)*2-1); - let d=n.dot(vert_sum); //WARNING yada yada d *2 - for t in zeroes2((n.dot(body.position))*2-d,n.dot(body.velocity)*2,n.dot(body.acceleration)){ + for t in zeroes2(n.dot(delta_pos),n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); if time<=t&&t{ for (i,&vert_id) in edge_verts.iter().enumerate(){ //vertex normal gets parity from vert index let n=edge_n*(1-2*(i as i64)); - let d=n.dot(mesh.vert(vert_id)); - for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ + for t in zeroes2((n.dot(body.position-mesh.vert(vert_id)))*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); if time<=t&&t{ for &directed_edge_id in mesh.vert_edges(vert_id).iter(){ //edge is directed away from vertex, but we want the dot product to turn out negative let n=-mesh.directed_edge_n(directed_edge_id); - let d=n.dot(mesh.vert(vert_id)); - for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ + for t in zeroes2((n.dot(body.position-mesh.vert(vert_id)))*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); if time<=t&&t