45 #include "../src/BV/OBB.h"
56 a = extentNorm * Vec3s::Random().cwiseAbs().normalized();
57 b = extentNorm * Vec3s::Random().cwiseAbs().normalized();
70 T = (Vec3s::Random() / sqrt(3)) * 1.5 * N;
74 q.coeffs().setRandom();
80 #define MANUAL_PRODUCT 1
83 #define PRODUCT(M33, v3) \
84 (M33.col(0) * v3[0] + M33.col(1) * v3[1] + M33.col(2) * v3[2])
86 #define PRODUCT(M33, v3) (M33 * v3)
92 const char*
sep =
",\t";
95 const Eigen::IOFormat
py_fmt(Eigen::FullPrecision, 0,
109 Box ba(2 *
a), bb(2 *
b);
113 bool compute_penetration =
true;
115 gjk.shapeDistance(ba, tfa, bb, tfb, compute_penetration,
p1, p2, normal);
116 return (
distance >
gjk.getDistancePrecision(compute_penetration));
127 AABB_corner.noalias() = T.cwiseAbs() -
a;
128 AABB_corner.noalias() -= Bf.col(0) *
b[0];
129 AABB_corner.noalias() -= Bf.col(1) *
b[1];
130 AABB_corner.noalias() -= Bf.col(2) *
b[2];
132 AABB_corner.noalias() = T.cwiseAbs() - Bf *
b -
a;
135 return AABB_corner.array().max(
CoalScalar(0)).matrix().squaredNorm();
148 s = std::abs(
B.col(0).dot(T)) - Bf.col(0).dot(
a) -
b[0];
149 if (s > 0)
t += s * s;
150 s = std::abs(
B.col(1).dot(T)) - Bf.col(1).dot(
a) -
b[1];
151 if (s > 0)
t += s * s;
152 s = std::abs(
B.col(2).dot(T)) - Bf.col(2).dot(
a) -
b[2];
153 if (s > 0)
t += s * s;
156 Vec3s AABB_corner((
B.transpose() * T).cwiseAbs() - Bf.transpose() *
a -
b);
157 return AABB_corner.array().max(
CoalScalar(0)).matrix().squaredNorm();
171 if (squaredLowerBoundDistance > breakDistance2)
return id;
176 if (squaredLowerBoundDistance > breakDistance2)
return id;
179 int ja = 1, ka = 2, jb = 1, kb = 2;
180 for (
int ia = 0; ia < 3; ++ia) {
181 for (
int ib = 0; ib < 3; ++ib) {
182 const CoalScalar s = T[ka] *
B(ja, ib) - T[ja] *
B(ka, ib);
185 fabs(s) - (
a[ja] * Bf(ka, ib) +
a[ka] * Bf(ja, ib) +
186 b[jb] * Bf(ia, kb) +
b[kb] * Bf(ia, jb));
190 CoalScalar sinus2 = 1 - Bf(ia, ib) * Bf(ia, ib);
192 squaredLowerBoundDistance = diff * diff / sinus2;
193 if (squaredLowerBoundDistance > breakDistance2) {
226 if (squaredLowerBoundDistance > breakDistance2)
return true;
230 if (squaredLowerBoundDistance > breakDistance2)
return true;
232 int ja = 1, ka = 2, jb = 1, kb = 2;
233 for (
int ia = 0; ia < 3; ++ia) {
234 for (
int ib = 0; ib < 3; ++ib) {
235 const CoalScalar s = T[ka] *
B(ja, ib) - T[ja] *
B(ka, ib);
238 fabs(s) - (
a[ja] * Bf(ka, ib) +
a[ka] * Bf(ja, ib) +
239 b[jb] * Bf(ia, kb) +
b[kb] * Bf(ia, jb));
243 CoalScalar sinus2 = 1 - Bf(ia, ib) * Bf(ia, ib);
245 squaredLowerBoundDistance = diff * diff / sinus2;
246 if (squaredLowerBoundDistance > breakDistance2) {
283 Vec3s AABB_corner(T.cwiseAbs() - Bf *
b);
284 Vec3s diff3(AABB_corner -
a);
285 diff3 = diff3.cwiseMax(Vec3s::Zero());
288 squaredLowerBoundDistance = diff3.squaredNorm();
289 if (squaredLowerBoundDistance > breakDistance2)
return true;
291 AABB_corner = (
B.transpose() * T).cwiseAbs() - Bf.transpose() *
a;
293 diff3 = AABB_corner -
b;
294 diff3 = diff3.cwiseMax(Vec3s::Zero());
295 squaredLowerBoundDistance = diff3.squaredNorm();
297 if (squaredLowerBoundDistance > breakDistance2)
return true;
300 s = T[2] *
B(1, 0) - T[1] *
B(2, 0);
301 t = ((s < 0.0) ? -s : s);
302 assert(
t == fabs(s));
305 diff =
t - (
a[1] * Bf(2, 0) +
a[2] * Bf(1, 0) +
b[1] * Bf(0, 2) +
312 sinus2 = 1 - Bf(0, 0) * Bf(0, 0);
314 squaredLowerBoundDistance = diff * diff / sinus2;
315 if (squaredLowerBoundDistance > breakDistance2) {
322 s = T[2] *
B(1, 1) - T[1] *
B(2, 1);
323 t = ((s < 0.0) ? -s : s);
324 assert(
t == fabs(s));
326 diff =
t - (
a[1] * Bf(2, 1) +
a[2] * Bf(1, 1) +
b[0] * Bf(0, 2) +
329 sinus2 = 1 - Bf(0, 1) * Bf(0, 1);
331 squaredLowerBoundDistance = diff * diff / sinus2;
332 if (squaredLowerBoundDistance > breakDistance2) {
339 s = T[2] *
B(1, 2) - T[1] *
B(2, 2);
340 t = ((s < 0.0) ? -s : s);
341 assert(
t == fabs(s));
343 diff =
t - (
a[1] * Bf(2, 2) +
a[2] * Bf(1, 2) +
b[0] * Bf(0, 1) +
346 sinus2 = 1 - Bf(0, 2) * Bf(0, 2);
348 squaredLowerBoundDistance = diff * diff / sinus2;
349 if (squaredLowerBoundDistance > breakDistance2) {
356 s = T[0] *
B(2, 0) - T[2] *
B(0, 0);
357 t = ((s < 0.0) ? -s : s);
358 assert(
t == fabs(s));
360 diff =
t - (
a[0] * Bf(2, 0) +
a[2] * Bf(0, 0) +
b[1] * Bf(1, 2) +
363 sinus2 = 1 - Bf(1, 0) * Bf(1, 0);
365 squaredLowerBoundDistance = diff * diff / sinus2;
366 if (squaredLowerBoundDistance > breakDistance2) {
373 s = T[0] *
B(2, 1) - T[2] *
B(0, 1);
374 t = ((s < 0.0) ? -s : s);
375 assert(
t == fabs(s));
377 diff =
t - (
a[0] * Bf(2, 1) +
a[2] * Bf(0, 1) +
b[0] * Bf(1, 2) +
380 sinus2 = 1 - Bf(1, 1) * Bf(1, 1);
382 squaredLowerBoundDistance = diff * diff / sinus2;
383 if (squaredLowerBoundDistance > breakDistance2) {
390 s = T[0] *
B(2, 2) - T[2] *
B(0, 2);
391 t = ((s < 0.0) ? -s : s);
392 assert(
t == fabs(s));
394 diff =
t - (
a[0] * Bf(2, 2) +
a[2] * Bf(0, 2) +
b[0] * Bf(1, 1) +
397 sinus2 = 1 - Bf(1, 2) * Bf(1, 2);
399 squaredLowerBoundDistance = diff * diff / sinus2;
400 if (squaredLowerBoundDistance > breakDistance2) {
407 s = T[1] *
B(0, 0) - T[0] *
B(1, 0);
408 t = ((s < 0.0) ? -s : s);
409 assert(
t == fabs(s));
411 diff =
t - (
a[0] * Bf(1, 0) +
a[1] * Bf(0, 0) +
b[1] * Bf(2, 2) +
414 sinus2 = 1 - Bf(2, 0) * Bf(2, 0);
416 squaredLowerBoundDistance = diff * diff / sinus2;
417 if (squaredLowerBoundDistance > breakDistance2) {
424 s = T[1] *
B(0, 1) - T[0] *
B(1, 1);
425 t = ((s < 0.0) ? -s : s);
426 assert(
t == fabs(s));
428 diff =
t - (
a[0] * Bf(1, 1) +
a[1] * Bf(0, 1) +
b[0] * Bf(2, 2) +
431 sinus2 = 1 - Bf(2, 1) * Bf(2, 1);
433 squaredLowerBoundDistance = diff * diff / sinus2;
434 if (squaredLowerBoundDistance > breakDistance2) {
441 s = T[1] *
B(0, 2) - T[0] *
B(1, 2);
442 t = ((s < 0.0) ? -s : s);
443 assert(
t == fabs(s));
445 diff =
t - (
a[0] * Bf(1, 2) +
a[1] * Bf(0, 2) +
b[0] * Bf(2, 1) +
448 sinus2 = 1 - Bf(2, 2) * Bf(2, 2);
450 squaredLowerBoundDistance = diff * diff / sinus2;
451 if (squaredLowerBoundDistance > breakDistance2) {
469 if (squaredLowerBoundDistance > breakDistance2)
return true;
472 if (squaredLowerBoundDistance > breakDistance2)
return true;
476 s = T[2] *
B(1, 0) - T[1] *
B(2, 0);
477 t = ((s < 0.0) ? -s : s);
478 assert(
t == fabs(s));
482 diff =
t - (
a[1] * Bf(2, 0) +
a[2] * Bf(1, 0) +
b[1] * Bf(0, 2) +
489 sinus2 = 1 - Bf(0, 0) * Bf(0, 0);
491 squaredLowerBoundDistance = diff * diff / sinus2;
492 if (squaredLowerBoundDistance > breakDistance2) {
499 s = T[2] *
B(1, 1) - T[1] *
B(2, 1);
500 t = ((s < 0.0) ? -s : s);
501 assert(
t == fabs(s));
503 diff =
t - (
a[1] * Bf(2, 1) +
a[2] * Bf(1, 1) +
b[0] * Bf(0, 2) +
506 sinus2 = 1 - Bf(0, 1) * Bf(0, 1);
508 squaredLowerBoundDistance = diff * diff / sinus2;
509 if (squaredLowerBoundDistance > breakDistance2) {
516 s = T[2] *
B(1, 2) - T[1] *
B(2, 2);
517 t = ((s < 0.0) ? -s : s);
518 assert(
t == fabs(s));
520 diff =
t - (
a[1] * Bf(2, 2) +
a[2] * Bf(1, 2) +
b[0] * Bf(0, 1) +
523 sinus2 = 1 - Bf(0, 2) * Bf(0, 2);
525 squaredLowerBoundDistance = diff * diff / sinus2;
526 if (squaredLowerBoundDistance > breakDistance2) {
533 s = T[0] *
B(2, 0) - T[2] *
B(0, 0);
534 t = ((s < 0.0) ? -s : s);
535 assert(
t == fabs(s));
537 diff =
t - (
a[0] * Bf(2, 0) +
a[2] * Bf(0, 0) +
b[1] * Bf(1, 2) +
540 sinus2 = 1 - Bf(1, 0) * Bf(1, 0);
542 squaredLowerBoundDistance = diff * diff / sinus2;
543 if (squaredLowerBoundDistance > breakDistance2) {
550 s = T[0] *
B(2, 1) - T[2] *
B(0, 1);
551 t = ((s < 0.0) ? -s : s);
552 assert(
t == fabs(s));
554 diff =
t - (
a[0] * Bf(2, 1) +
a[2] * Bf(0, 1) +
b[0] * Bf(1, 2) +
557 sinus2 = 1 - Bf(1, 1) * Bf(1, 1);
559 squaredLowerBoundDistance = diff * diff / sinus2;
560 if (squaredLowerBoundDistance > breakDistance2) {
567 s = T[0] *
B(2, 2) - T[2] *
B(0, 2);
568 t = ((s < 0.0) ? -s : s);
569 assert(
t == fabs(s));
571 diff =
t - (
a[0] * Bf(2, 2) +
a[2] * Bf(0, 2) +
b[0] * Bf(1, 1) +
574 sinus2 = 1 - Bf(1, 2) * Bf(1, 2);
576 squaredLowerBoundDistance = diff * diff / sinus2;
577 if (squaredLowerBoundDistance > breakDistance2) {
584 s = T[1] *
B(0, 0) - T[0] *
B(1, 0);
585 t = ((s < 0.0) ? -s : s);
586 assert(
t == fabs(s));
588 diff =
t - (
a[0] * Bf(1, 0) +
a[1] * Bf(0, 0) +
b[1] * Bf(2, 2) +
591 sinus2 = 1 - Bf(2, 0) * Bf(2, 0);
593 squaredLowerBoundDistance = diff * diff / sinus2;
594 if (squaredLowerBoundDistance > breakDistance2) {
601 s = T[1] *
B(0, 1) - T[0] *
B(1, 1);
602 t = ((s < 0.0) ? -s : s);
603 assert(
t == fabs(s));
605 diff =
t - (
a[0] * Bf(1, 1) +
a[1] * Bf(0, 1) +
b[0] * Bf(2, 2) +
608 sinus2 = 1 - Bf(2, 1) * Bf(2, 1);
610 squaredLowerBoundDistance = diff * diff / sinus2;
611 if (squaredLowerBoundDistance > breakDistance2) {
618 s = T[1] *
B(0, 2) - T[0] *
B(1, 2);
619 t = ((s < 0.0) ? -s : s);
620 assert(
t == fabs(s));
622 diff =
t - (
a[0] * Bf(1, 2) +
a[1] * Bf(0, 2) +
b[0] * Bf(2, 1) +
625 sinus2 = 1 - Bf(2, 2) * Bf(2, 2);
627 squaredLowerBoundDistance = diff * diff / sinus2;
628 if (squaredLowerBoundDistance > breakDistance2) {
638 template <
int ia,
int ib,
int ja = (ia + 1) % 3,
int ka = (ia + 2) % 3,
639 int jb = (ib + 1) % 3,
int kb = (ib + 2) % 3>
645 const CoalScalar s = T[ka] *
B(ja, ib) - T[ja] *
B(ka, ib);
647 const CoalScalar diff = fabs(s) - (
a[ja] * Bf(ka, ib) +
a[ka] * Bf(ja, ib) +
648 b[jb] * Bf(ia, kb) +
b[kb] * Bf(ia, jb));
652 CoalScalar sinus2 = 1 - Bf(ia, ib) * Bf(ia, ib);
654 squaredLowerBoundDistance = diff * diff / sinus2;
655 if (squaredLowerBoundDistance > breakDistance2) {
680 if (squaredLowerBoundDistance > breakDistance2)
return true;
683 if (squaredLowerBoundDistance > breakDistance2)
return true;
687 squaredLowerBoundDistance))
690 squaredLowerBoundDistance))
693 squaredLowerBoundDistance))
696 squaredLowerBoundDistance))
699 squaredLowerBoundDistance))
702 squaredLowerBoundDistance))
705 squaredLowerBoundDistance))
708 squaredLowerBoundDistance))
711 squaredLowerBoundDistance))
719 template <
int ib,
int jb = (ib + 1) % 3,
int kb = (ib + 2) % 3>
725 const CoalScalar s = T[ka] *
B(ja, ib) - T[ja] *
B(ka, ib);
727 const CoalScalar diff = fabs(s) - (
a[ja] * Bf(ka, ib) +
a[ka] * Bf(ja, ib) +
728 b[jb] * Bf(ia, kb) +
b[kb] * Bf(ia, jb));
732 CoalScalar sinus2 = 1 - Bf(ia, ib) * Bf(ia, ib);
734 squaredLowerBoundDistance = diff * diff / sinus2;
735 if (squaredLowerBoundDistance > breakDistance2) {
760 if (squaredLowerBoundDistance > breakDistance2)
return true;
763 if (squaredLowerBoundDistance > breakDistance2)
return true;
767 for (
int ia = 0; ia < 3; ++ia) {
769 squaredLowerBoundDistance))
772 squaredLowerBoundDistance))
775 squaredLowerBoundDistance))
792 squaredLowerBoundDistance = 0;
797 t = ((T[0] < 0.0) ? -T[0] : T[0]);
799 diff =
t - (
a[0] + Bf.row(0).dot(
b));
801 squaredLowerBoundDistance = diff * diff;
805 t = ((T[1] < 0.0) ? -T[1] : T[1]);
807 diff =
t - (
a[1] + Bf.row(1).dot(
b));
809 squaredLowerBoundDistance += diff * diff;
813 t = ((T[2] < 0.0) ? -T[2] : T[2]);
815 diff =
t - (
a[2] + Bf.row(2).dot(
b));
817 squaredLowerBoundDistance += diff * diff;
820 if (squaredLowerBoundDistance > breakDistance2)
return true;
822 squaredLowerBoundDistance = 0;
826 t = ((s < 0.0) ? -s : s);
828 diff =
t - (
b[0] + Bf.col(0).dot(
a));
830 squaredLowerBoundDistance += diff * diff;
835 t = ((s < 0.0) ? -s : s);
837 diff =
t - (
b[1] + Bf.col(1).dot(
a));
839 squaredLowerBoundDistance += diff * diff;
844 t = ((s < 0.0) ? -s : s);
846 diff =
t - (
b[2] + Bf.col(2).dot(
a));
848 squaredLowerBoundDistance += diff * diff;
851 if (squaredLowerBoundDistance > breakDistance2)
return true;
854 s = T[2] *
B(1, 0) - T[1] *
B(2, 0);
855 t = ((s < 0.0) ? -s : s);
858 diff =
t - (
a[1] * Bf(2, 0) +
a[2] * Bf(1, 0) +
b[1] * Bf(0, 2) +
865 sinus2 = 1 - Bf(0, 0) * Bf(0, 0);
867 squaredLowerBoundDistance = diff * diff / sinus2;
868 if (squaredLowerBoundDistance > breakDistance2) {
875 s = T[2] *
B(1, 1) - T[1] *
B(2, 1);
876 t = ((s < 0.0) ? -s : s);
878 diff =
t - (
a[1] * Bf(2, 1) +
a[2] * Bf(1, 1) +
b[0] * Bf(0, 2) +
881 sinus2 = 1 - Bf(0, 1) * Bf(0, 1);
883 squaredLowerBoundDistance = diff * diff / sinus2;
884 if (squaredLowerBoundDistance > breakDistance2) {
891 s = T[2] *
B(1, 2) - T[1] *
B(2, 2);
892 t = ((s < 0.0) ? -s : s);
894 diff =
t - (
a[1] * Bf(2, 2) +
a[2] * Bf(1, 2) +
b[0] * Bf(0, 1) +
897 sinus2 = 1 - Bf(0, 2) * Bf(0, 2);
899 squaredLowerBoundDistance = diff * diff / sinus2;
900 if (squaredLowerBoundDistance > breakDistance2) {
907 s = T[0] *
B(2, 0) - T[2] *
B(0, 0);
908 t = ((s < 0.0) ? -s : s);
910 diff =
t - (
a[0] * Bf(2, 0) +
a[2] * Bf(0, 0) +
b[1] * Bf(1, 2) +
913 sinus2 = 1 - Bf(1, 0) * Bf(1, 0);
915 squaredLowerBoundDistance = diff * diff / sinus2;
916 if (squaredLowerBoundDistance > breakDistance2) {
923 s = T[0] *
B(2, 1) - T[2] *
B(0, 1);
924 t = ((s < 0.0) ? -s : s);
926 diff =
t - (
a[0] * Bf(2, 1) +
a[2] * Bf(0, 1) +
b[0] * Bf(1, 2) +
929 sinus2 = 1 - Bf(1, 1) * Bf(1, 1);
931 squaredLowerBoundDistance = diff * diff / sinus2;
932 if (squaredLowerBoundDistance > breakDistance2) {
939 s = T[0] *
B(2, 2) - T[2] *
B(0, 2);
940 t = ((s < 0.0) ? -s : s);
942 diff =
t - (
a[0] * Bf(2, 2) +
a[2] * Bf(0, 2) +
b[0] * Bf(1, 1) +
945 sinus2 = 1 - Bf(1, 2) * Bf(1, 2);
947 squaredLowerBoundDistance = diff * diff / sinus2;
948 if (squaredLowerBoundDistance > breakDistance2) {
955 s = T[1] *
B(0, 0) - T[0] *
B(1, 0);
956 t = ((s < 0.0) ? -s : s);
958 diff =
t - (
a[0] * Bf(1, 0) +
a[1] * Bf(0, 0) +
b[1] * Bf(2, 2) +
961 sinus2 = 1 - Bf(2, 0) * Bf(2, 0);
963 squaredLowerBoundDistance = diff * diff / sinus2;
964 if (squaredLowerBoundDistance > breakDistance2) {
971 s = T[1] *
B(0, 1) - T[0] *
B(1, 1);
972 t = ((s < 0.0) ? -s : s);
974 diff =
t - (
a[0] * Bf(1, 1) +
a[1] * Bf(0, 1) +
b[0] * Bf(2, 2) +
977 sinus2 = 1 - Bf(2, 1) * Bf(2, 1);
979 squaredLowerBoundDistance = diff * diff / sinus2;
980 if (squaredLowerBoundDistance > breakDistance2) {
987 s = T[1] *
B(0, 2) - T[0] *
B(1, 2);
988 t = ((s < 0.0) ? -s : s);
990 diff =
t - (
a[0] * Bf(1, 2) +
a[1] * Bf(0, 2) +
b[0] * Bf(2, 1) +
993 sinus2 = 1 - Bf(2, 2) * Bf(2, 2);
995 squaredLowerBoundDistance = diff * diff / sinus2;
996 if (squaredLowerBoundDistance > breakDistance2) {
1012 squaredLowerBoundDistance = 0;
1020 t = ((T[0] < 0.0) ? -T[0] : T[0]);
1023 if (
t > (
a[0] + Bf.row(0).dot(
b)))
return true;
1027 s =
B.col(0).dot(T);
1028 t = ((s < 0.0) ? -s : s);
1031 if (
t > (
b[0] + Bf.col(0).dot(
a)))
return true;
1034 t = ((T[1] < 0.0) ? -T[1] : T[1]);
1037 if (
t > (
a[1] + Bf.row(1).dot(
b)))
return true;
1040 t = ((T[2] < 0.0) ? -T[2] : T[2]);
1043 if (
t > (
a[2] + Bf.row(2).dot(
b)))
return true;
1047 s =
B.col(1).dot(T);
1048 t = ((s < 0.0) ? -s : s);
1051 if (
t > (
b[1] + Bf.col(1).dot(
a)))
return true;
1055 s =
B.col(2).dot(T);
1056 t = ((s < 0.0) ? -s : s);
1059 if (
t > (
b[2] + Bf.col(2).dot(
a)))
return true;
1062 s = T[2] *
B(1, 0) - T[1] *
B(2, 0);
1063 t = ((s < 0.0) ? -s : s);
1066 (
a[1] * Bf(2, 0) +
a[2] * Bf(1, 0) +
b[1] * Bf(0, 2) +
b[2] * Bf(0, 1)))
1070 s = T[2] *
B(1, 1) - T[1] *
B(2, 1);
1071 t = ((s < 0.0) ? -s : s);
1074 (
a[1] * Bf(2, 1) +
a[2] * Bf(1, 1) +
b[0] * Bf(0, 2) +
b[2] * Bf(0, 0)))
1078 s = T[2] *
B(1, 2) - T[1] *
B(2, 2);
1079 t = ((s < 0.0) ? -s : s);
1082 (
a[1] * Bf(2, 2) +
a[2] * Bf(1, 2) +
b[0] * Bf(0, 1) +
b[1] * Bf(0, 0)))
1086 s = T[0] *
B(2, 0) - T[2] *
B(0, 0);
1087 t = ((s < 0.0) ? -s : s);
1090 (
a[0] * Bf(2, 0) +
a[2] * Bf(0, 0) +
b[1] * Bf(1, 2) +
b[2] * Bf(1, 1)))
1094 s = T[0] *
B(2, 1) - T[2] *
B(0, 1);
1095 t = ((s < 0.0) ? -s : s);
1098 (
a[0] * Bf(2, 1) +
a[2] * Bf(0, 1) +
b[0] * Bf(1, 2) +
b[2] * Bf(1, 0)))
1102 s = T[0] *
B(2, 2) - T[2] *
B(0, 2);
1103 t = ((s < 0.0) ? -s : s);
1106 (
a[0] * Bf(2, 2) +
a[2] * Bf(0, 2) +
b[0] * Bf(1, 1) +
b[1] * Bf(1, 0)))
1110 s = T[1] *
B(0, 0) - T[0] *
B(1, 0);
1111 t = ((s < 0.0) ? -s : s);
1114 (
a[0] * Bf(1, 0) +
a[1] * Bf(0, 0) +
b[1] * Bf(2, 2) +
b[2] * Bf(2, 1)))
1118 s = T[1] *
B(0, 1) - T[0] *
B(1, 1);
1119 t = ((s < 0.0) ? -s : s);
1122 (
a[0] * Bf(1, 1) +
a[1] * Bf(0, 1) +
b[0] * Bf(2, 2) +
b[2] * Bf(2, 0)))
1126 s = T[1] *
B(0, 2) - T[0] *
B(1, 2);
1127 t = ((s < 0.0) ? -s : s);
1130 (
a[0] * Bf(1, 2) +
a[1] * Bf(0, 2) +
b[0] * Bf(2, 1) +
b[1] * Bf(2, 0)))
1148 const std::string unit =
" (us)";
1149 os <<
"separating axis" <<
sep <<
"distance lower bound" <<
sep
1150 <<
"distance" <<
sep <<
"failure" <<
sep <<
"Runtime Loop" << unit <<
sep
1151 <<
"Manual Loop Unrolling 1" << unit <<
sep <<
"Manual Loop Unrolling 2"
1152 << unit <<
sep <<
"Template Unrolling" << unit <<
sep
1153 <<
"Partial Template Unrolling" << unit <<
sep <<
"Original (LowerBound)"
1154 << unit <<
sep <<
"Original (NoLowerBound)" << unit;
1158 std::ostream&
print(std::ostream& os)
const {
1159 os << ifId <<
sep << std::sqrt(squaredLowerBoundDistance) <<
sep <<
distance
1163 <<
static_cast<double>(
1164 std::chrono::duration_cast<std::chrono::nanoseconds>(
1173 return br.
print(os);
1182 const CoalScalar breakDistance2 = breakDistance * breakDistance;
1189 assert(0 <= result.
ifId && result.
ifId <= 11);
1196 std::cerr <<
"Failure: negative distance for disjoint OBBs.";
1198 std::cerr <<
"Failure: negative distance lower bound.";
1201 std::cerr <<
"Failure: distance is inferior to its lower bound (diff = "
1205 std::cerr <<
"Failure: overlapping test and distance query mismatch.";
1207 std::cerr <<
"Failure: positive distance for overlapping OBBs.";
1212 std::cerr <<
"\nR = " <<
Quatf(
B).coeffs().transpose().format(
py_fmt)
1213 <<
"\nT = " << T.transpose().format(
py_fmt)
1214 <<
"\na = " <<
a.transpose().format(
py_fmt)
1215 <<
"\nb = " <<
b.transpose().format(
py_fmt)
1216 <<
"\nresult = " << result <<
'\n'
1222 clock_type::time_point start, end;
1225 start = clock_type::now();
1226 for (std::size_t i = 0; i < N; ++i)
1228 end = clock_type::now();
1229 result.
duration[0] = (end - start) / N;
1232 start = clock_type::now();
1233 for (std::size_t i = 0; i < N; ++i)
1236 end = clock_type::now();
1237 result.
duration[1] = (end - start) / N;
1240 start = clock_type::now();
1241 for (std::size_t i = 0; i < N; ++i)
1244 end = clock_type::now();
1245 result.
duration[2] = (end - start) / N;
1248 start = clock_type::now();
1249 for (std::size_t i = 0; i < N; ++i)
1252 end = clock_type::now();
1253 result.
duration[3] = (end - start) / N;
1256 start = clock_type::now();
1257 for (std::size_t i = 0; i < N; ++i)
1259 breakDistance2, tmp);
1260 end = clock_type::now();
1261 result.
duration[4] = (end - start) / N;
1264 start = clock_type::now();
1265 for (std::size_t i = 0; i < N; ++i)
1267 end = clock_type::now();
1268 result.
duration[5] = (end - start) / N;
1271 start = clock_type::now();
1273 for (std::size_t i = 0; i < N; ++i)
1276 end = clock_type::now();
1277 result.
duration[6] = (end - start) / N;
1283 std::size_t nbFailure = 0;
1291 #ifndef NDEBUG // if debug mode
1292 static const size_t nbRandomOBB = 10;
1293 static const size_t nbTransformPerOBB = 10;
1294 static const size_t nbRunForTimeMeas = 10;
1296 static const size_t nbRandomOBB = 100;
1297 static const size_t nbTransformPerOBB = 100;
1298 static const size_t nbRunForTimeMeas = 1000;
1305 for (std::size_t iobb = 0; iobb < nbRandomOBB; ++iobb) {
1307 for (std::size_t itf = 0; itf < nbTransformPerOBB; ++itf) {
1310 if (output != NULL) *output << result <<
'\n';
1311 if (result.failure) nbFailure++;
1318 std::ostream* output = NULL;
1319 if (argc > 1 && strcmp(argv[1],
"--generate-output") == 0) {
1320 output = &std::cout;
1323 std::cout <<
"The benchmark real time measurements may be noisy and "
1324 "will incur extra overhead."
1325 "\nUse the following commands to turn ON:"
1326 "\n\tsudo cpufreq-set --governor performance"
1328 "\n\tsudo cpufreq-set --governor powersave"
1332 if (nbFailure > INT_MAX)
return INT_MAX;
1333 return (
int)nbFailure;