@@ -26,6 +26,22 @@ namespace {
2626 assert (v.size () == 2 || v.size () == 3 );
2727 return v.size () == 2 ? Eigen::Vector3d (v.x (), v.y (), 0 ) : v.head <3 >();
2828 }
29+
30+ inline bool check_initial_distance (
31+ const double initial_distance, const double min_distance, double & toi)
32+ {
33+ if (initial_distance > min_distance) {
34+ return false ;
35+ }
36+
37+ logger ().warn (
38+ " Initial distance {} ≤ d_min={}, returning toi=0!" ,
39+ initial_distance, min_distance);
40+
41+ toi = 0 ; // Initially touching
42+
43+ return true ;
44+ }
2945} // namespace
3046
3147// / @brief Scale the distance tolerance to be at most this fraction of the initial distance.
@@ -49,11 +65,7 @@ bool ccd_strategy(
4965 const double conservative_rescaling,
5066 double& toi)
5167{
52- if (initial_distance <= min_distance) {
53- logger ().warn (
54- " Initial distance {} ≤ d_min={}, returning toi=0!" ,
55- initial_distance, min_distance);
56- toi = 0 ;
68+ if (check_initial_distance (initial_distance, min_distance, toi)) {
5769 return true ;
5870 }
5971
@@ -111,12 +123,12 @@ bool point_point_ccd_3D(
111123{
112124 assert (tmax >= 0 && tmax <= 1.0 );
113125
114- if (p0_t0 == p0_t1 && p1_t0 == p1_t1) {
115- return false ; // No motion
116- }
117-
118126 const double initial_distance = sqrt (point_point_distance (p0_t0, p1_t0));
119127
128+ if (p0_t0 == p0_t1 && p1_t0 == p1_t1) { // No motion
129+ return check_initial_distance (initial_distance, min_distance, toi);
130+ }
131+
120132 const double adjusted_tolerance = std::min (
121133 INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);
122134
@@ -182,13 +194,13 @@ bool point_edge_ccd_3D(
182194{
183195 assert (tmax >= 0 && tmax <= 1.0 );
184196
185- if (p_t0 == p_t1 && e0_t0 == e0_t1 && e1_t0 == e1_t1) {
186- return false ; // No motion
187- }
188-
189197 const double initial_distance =
190198 sqrt (point_edge_distance (p_t0, e0_t0, e1_t0));
191199
200+ if (p_t0 == p_t1 && e0_t0 == e0_t1 && e1_t0 == e1_t1) { // No motion
201+ return check_initial_distance (initial_distance, min_distance, toi);
202+ }
203+
192204 const double adjusted_tolerance = std::min (
193205 INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);
194206
@@ -244,15 +256,6 @@ bool point_edge_ccd(
244256 assert (p_t1.size () == dim);
245257 assert (e0_t0.size () == dim && e1_t0.size () == dim);
246258 assert (e0_t1.size () == dim && e1_t1.size () == dim);
247-
248- #ifndef IPC_TOOLKIT_WITH_CORRECT_CCD
249- if (dim == 2 ) {
250- return inexact_point_edge_ccd_2D (
251- p_t0, e0_t0, e1_t0, p_t1, e0_t1, e1_t1, toi,
252- conservative_rescaling);
253- }
254- #endif
255-
256259 return point_edge_ccd_3D (
257260 to_3D (p_t0), to_3D (e0_t0), to_3D (e1_t0), to_3D (p_t1), to_3D (e0_t1),
258261 to_3D (e1_t1), toi, min_distance, tmax, tolerance, max_iterations,
@@ -277,14 +280,14 @@ bool edge_edge_ccd(
277280{
278281 assert (tmax >= 0 && tmax <= 1.0 );
279282
280- if (ea0_t0 == ea0_t1 && ea1_t0 == ea1_t1 && eb0_t0 == eb0_t1
281- && eb1_t0 == eb1_t1) {
282- return false ; // No motion
283- }
284-
285283 const double initial_distance =
286284 sqrt (edge_edge_distance (ea0_t0, ea1_t0, eb0_t0, eb1_t0));
287285
286+ if (ea0_t0 == ea0_t1 && ea1_t0 == ea1_t1 && eb0_t0 == eb0_t1
287+ && eb1_t0 == eb1_t1) { // No motion
288+ return check_initial_distance (initial_distance, min_distance, toi);
289+ }
290+
288291 const double adjusted_tolerance = std::min (
289292 INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);
290293
@@ -340,13 +343,14 @@ bool point_triangle_ccd(
340343{
341344 assert (tmax >= 0 && tmax <= 1.0 );
342345
343- if (p_t0 == p_t1 && t0_t0 == t0_t1 && t1_t0 == t1_t1 && t2_t0 == t2_t1) {
344- return false ; // No motion
345- }
346-
347346 const double initial_distance =
348347 sqrt (point_triangle_distance (p_t0, t0_t0, t1_t0, t2_t0));
349348
349+ if (p_t0 == p_t1 && t0_t0 == t0_t1 && t1_t0 == t1_t1 && t2_t0 == t2_t1) {
350+ // No motion
351+ return check_initial_distance (initial_distance, min_distance, toi);
352+ }
353+
350354 const double adjusted_tolerance = std::min (
351355 INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);
352356
0 commit comments