EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_AnalyticDistanceFunctions.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
34#ifndef EBGEOMETRY_ANALYTICDISTANCEFUNCTIONS_HPP
35#define EBGEOMETRY_ANALYTICDISTANCEFUNCTIONS_HPP
36
37// Std includes
38#include <algorithm>
39#include <cmath>
40#include <cstddef>
41#include <cstdint>
42#include <random>
43#include <type_traits>
44#include <utility>
45#include <vector>
46
47// Our includes
48#include "EBGeometry_Array.hpp"
52#include "EBGeometry_GPU.hpp"
53#include "EBGeometry_Macros.hpp"
54#include "EBGeometry_Math.hpp"
55#include "EBGeometry_Vec.hpp"
56
57namespace EBGeometry {
58
67template <class T>
69{
70 static_assert(std::is_floating_point_v<T>, "PlaneSDF<T>: T must be a floating-point type");
71
72public:
77
83 PlaneSDF() = default;
84
90 PlaneSDF(const Vec3T<T>& a_point, const Vec3T<T>& a_normal)
91 {
92 EBGEOMETRY_REQUIRE(std::isfinite(a_point[0]) && std::isfinite(a_point[1]) && std::isfinite(a_point[2]),
93 "PlaneSDF: the point must be finite (%g, %g, %g)",
94 double(a_point[0]),
95 double(a_point[1]),
96 double(a_point[2]));
97 EBGEOMETRY_REQUIRE(std::isfinite(a_normal[0]) && std::isfinite(a_normal[1]) && std::isfinite(a_normal[2]),
98 "PlaneSDF: the normal must be finite (%g, %g, %g)",
99 double(a_normal[0]),
100 double(a_normal[1]),
101 double(a_normal[2]));
102 EBGEOMETRY_REQUIRE(a_normal.length() > T(0),
103 "PlaneSDF: the normal must be nonzero (%g, %g, %g)",
104 double(a_normal[0]),
105 double(a_normal[1]),
106 double(a_normal[2]));
107
108 m_point = a_point;
109 m_normal = a_normal / a_normal.length();
110 }
111
115 PlaneSDF(const PlaneSDF&) = default;
116
120 PlaneSDF(PlaneSDF&&) = default;
121
126 PlaneSDF&
127 operator=(const PlaneSDF&) = default;
128
133 PlaneSDF&
134 operator=(PlaneSDF&&) = default;
135
141 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
142 T
143 signedDistance(const Vec3T<T>& a_point) const noexcept
144 {
145 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
146 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
147 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
148 EBGEOMETRY_EXPECT(std::abs(m_normal.length() - T(1)) < std::sqrt(Math::Limits<T>::epsilon()));
149
150 return dot((a_point - m_point), m_normal);
151 }
152
158 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
160 computeBoundingVolume() const noexcept
161 {
163 }
164
169 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
170 const Vec3T<T>&
171 getPoint() const noexcept
172 {
173 return m_point;
174 }
175
180 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
181 const Vec3T<T>&
182 getNormal() const noexcept
183 {
184 return m_normal;
185 }
186
187protected:
192
196 Vec3T<T> m_normal = Vec3T<T>(T(0), T(1), T(0));
197};
198
206template <class T>
208{
209 static_assert(std::is_floating_point_v<T>, "SphereSDF<T>: T must be a floating-point type");
210
211public:
216
220 SphereSDF() = default;
221
227 SphereSDF(const Vec3T<T>& a_center, const T& a_radius)
228 {
229 EBGEOMETRY_REQUIRE(std::isfinite(a_center[0]) && std::isfinite(a_center[1]) && std::isfinite(a_center[2]),
230 "SphereSDF: the center must be finite (%g, %g, %g)",
231 double(a_center[0]),
232 double(a_center[1]),
233 double(a_center[2]));
234 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
235 "SphereSDF: the radius must be finite and positive (%g)",
236 double(a_radius));
237
238 m_center = a_center;
239 m_radius = a_radius;
240 }
241
245 SphereSDF(const SphereSDF&) = default;
246
250 SphereSDF(SphereSDF&&) = default;
251
256 SphereSDF&
257 operator=(const SphereSDF&) = default;
258
263 SphereSDF&
264 operator=(SphereSDF&&) = default;
265
270 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
271 const Vec3T<T>&
272 getCenter() const noexcept
273 {
274 return m_center;
275 }
276
282 Vec3T<T>&
283 getCenter() noexcept
284 {
285 return m_center;
286 }
287
292 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
293 const T&
294 getRadius() const noexcept
295 {
296 return m_radius;
297 }
298
304 T&
305 getRadius() noexcept
306 {
307 return m_radius;
308 }
309
315 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
316 T
317 signedDistance(const Vec3T<T>& a_point) const noexcept
318 {
319 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
320 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
321 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
322
323 return (a_point - m_center).length() - m_radius;
324 }
325
331 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
337
338protected:
343
347 T m_radius = T(1);
348};
349
358template <class T>
360{
361 static_assert(std::is_floating_point_v<T>, "BoxSDF<T>: T must be a floating-point type");
362
363public:
368
372 BoxSDF() = default;
373
380 BoxSDF(const Vec3T<T>& a_loCorner, const Vec3T<T>& a_hiCorner)
381 {
382 EBGEOMETRY_REQUIRE(std::isfinite(a_loCorner[0]) && std::isfinite(a_loCorner[1]) && std::isfinite(a_loCorner[2]),
383 "BoxSDF: the low corner must be finite (%g, %g, %g)",
384 double(a_loCorner[0]),
385 double(a_loCorner[1]),
386 double(a_loCorner[2]));
387 EBGEOMETRY_REQUIRE(std::isfinite(a_hiCorner[0]) && std::isfinite(a_hiCorner[1]) && std::isfinite(a_hiCorner[2]),
388 "BoxSDF: the high corner must be finite (%g, %g, %g)",
389 double(a_hiCorner[0]),
390 double(a_hiCorner[1]),
391 double(a_hiCorner[2]));
393 a_loCorner[0] < a_hiCorner[0] && a_loCorner[1] < a_hiCorner[1] && a_loCorner[2] < a_hiCorner[2],
394 "BoxSDF: the low corner (%g, %g, %g) must be below the high corner (%g, %g, %g) in every direction",
395 double(a_loCorner[0]),
396 double(a_loCorner[1]),
397 double(a_loCorner[2]),
398 double(a_hiCorner[0]),
399 double(a_hiCorner[1]),
400 double(a_hiCorner[2]));
401
402 m_loCorner = a_loCorner;
403 m_hiCorner = a_hiCorner;
404 }
405
409 BoxSDF(const BoxSDF&) = default;
410
414 BoxSDF(BoxSDF&&) = default;
415
420 BoxSDF&
421 operator=(const BoxSDF&) = default;
422
427 BoxSDF&
428 operator=(BoxSDF&&) = default;
429
434 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
435 const Vec3T<T>&
436 getLowCorner() const noexcept
437 {
438 return m_loCorner;
439 }
440
446 Vec3T<T>&
447 getLowCorner() noexcept
448 {
449 return m_loCorner;
450 }
451
456 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
457 const Vec3T<T>&
458 getHighCorner() const noexcept
459 {
460 return m_hiCorner;
461 }
462
468 Vec3T<T>&
469 getHighCorner() noexcept
470 {
471 return m_hiCorner;
472 }
473
479 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
480 T
481 signedDistance(const Vec3T<T>& a_point) const noexcept
482 {
483 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
484 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
485 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
486
487 // For each coordinate direction, we have delta[dir] if a_point[dir] falls
488 // between xLo and xHi. In this case delta[dir] will be the signed distance
489 // to the closest box face in the dir-direction. Otherwise, if a_point[dir]
490 // is outside the corner we have delta[dir] > 0.
491 const Vec3T<T> delta(Math::max(m_loCorner[0] - a_point[0], a_point[0] - m_hiCorner[0]),
492 Math::max(m_loCorner[1] - a_point[1], a_point[1] - m_hiCorner[1]),
493 Math::max(m_loCorner[2] - a_point[2], a_point[2] - m_hiCorner[2]));
494
495 // Note: max is max(Vec3T<T>, Vec3T<T>) and not std::max. It returns a
496 // vector with coordinate-wise largest components. Note that the first part
497 // Math::min(...) is the signed distance on the inside of the box (delta will
498 // have negative components). The other part max(Vec3T<T>::zeros(), ...) is
499 // for outside the box.
500 const T d = Math::min(T(0.0), delta[delta.maxDir(false)]) + max(Vec3T<T>::zeros(), delta).length();
501
502 return d;
503 }
504
509 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
510 uint32_t
511 getNumParts() const noexcept
512 {
513 return 6U;
514 }
515
521 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
522 uint32_t
523 closestPart(const Vec3T<T>& a_point) const noexcept
524 {
525 const Vec3T<T> lo = m_loCorner - a_point;
526 const Vec3T<T> hi = a_point - m_hiCorner;
527 const Vec3T<T> delta(Math::max(lo[0], hi[0]), Math::max(lo[1], hi[1]), Math::max(lo[2], hi[2]));
528
529 const size_t axis = delta.maxDir(false);
530
531 return 2U * uint32_t(axis) + ((hi[axis] > lo[axis]) ? 1U : 0U);
532 }
533
539 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
541 computeBoundingVolume() const noexcept
542 {
544 }
545
546protected:
550 Vec3T<T> m_loCorner = Vec3T<T>(T(-0.5), T(-0.5), T(-0.5));
551
555 Vec3T<T> m_hiCorner = Vec3T<T>(T(0.5), T(0.5), T(0.5));
556};
557
569template <class T>
571{
572 static_assert(std::is_floating_point_v<T>, "TorusSDF<T>: T must be a floating-point type");
573
574public:
579
583 TorusSDF() = default;
584
591 TorusSDF(const Vec3T<T>& a_center, const T& a_majorRadius, const T& a_minorRadius)
592 {
593 EBGEOMETRY_REQUIRE(std::isfinite(a_center[0]) && std::isfinite(a_center[1]) && std::isfinite(a_center[2]),
594 "TorusSDF: the center must be finite (%g, %g, %g)",
595 double(a_center[0]),
596 double(a_center[1]),
597 double(a_center[2]));
598 EBGEOMETRY_REQUIRE(std::isfinite(a_majorRadius) && a_majorRadius > T(0),
599 "TorusSDF: the major radius must be finite and positive (%g)",
600 double(a_majorRadius));
601 EBGEOMETRY_REQUIRE(std::isfinite(a_minorRadius) && a_minorRadius > T(0),
602 "TorusSDF: the minor radius must be finite and positive (%g)",
603 double(a_minorRadius));
604 EBGEOMETRY_REQUIRE(a_minorRadius < a_majorRadius,
605 "TorusSDF: the minor radius (%g) must be less than the major radius (%g)",
606 double(a_minorRadius),
607 double(a_majorRadius));
608
609 m_center = a_center;
610 m_majorRadius = a_majorRadius;
611 m_minorRadius = a_minorRadius;
612 }
613
617 TorusSDF(const TorusSDF&) = default;
618
622 TorusSDF(TorusSDF&&) = default;
623
628 TorusSDF&
629 operator=(const TorusSDF&) = default;
630
635 TorusSDF&
636 operator=(TorusSDF&&) = default;
637
642 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
643 const Vec3T<T>&
644 getCenter() const noexcept
645 {
646 return m_center;
647 }
648
654 Vec3T<T>&
655 getCenter() noexcept
656 {
657 return m_center;
658 }
659
664 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
665 const T&
666 getMajorRadius() const noexcept
667 {
668 return m_majorRadius;
669 }
670
676 T&
677 getMajorRadius() noexcept
678 {
679 return m_majorRadius;
680 }
681
686 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
687 const T&
688 getMinorRadius() const noexcept
689 {
690 return m_minorRadius;
691 }
692
698 T&
699 getMinorRadius() noexcept
700 {
701 return m_minorRadius;
702 }
708 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
709 T
710 signedDistance(const Vec3T<T>& a_point) const noexcept
711 {
712 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
713 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
714 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
715
716 const Vec3T<T> p = a_point - m_center;
717 const T rho = std::sqrt(p[0] * p[0] + p[2] * p[2]) - m_majorRadius;
718 const T d = std::sqrt(rho * rho + p[1] * p[1]) - m_minorRadius;
719
720 return d;
721 }
722
728 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
730 computeBoundingVolume() const noexcept
731 {
732 const T outer = m_majorRadius + m_minorRadius;
733 const Vec3T<T> half(outer, m_minorRadius, outer);
734
735 return BoundingVolumes::AABBT<T>(m_center - half, m_center + half);
736 }
737
738protected:
743
748
752 T m_minorRadius = T(0.5);
753};
754
764template <class T>
766{
767 static_assert(std::is_floating_point_v<T>, "CylinderSDF<T>: T must be a floating-point type");
768
769public:
774
779 CylinderSDF() = default;
780
787 CylinderSDF(const Vec3T<T>& a_center1, const Vec3T<T>& a_center2, const T& a_radius)
788 {
789 EBGEOMETRY_REQUIRE(std::isfinite(a_center1[0]) && std::isfinite(a_center1[1]) && std::isfinite(a_center1[2]),
790 "CylinderSDF: the first center must be finite (%g, %g, %g)",
791 double(a_center1[0]),
792 double(a_center1[1]),
793 double(a_center1[2]));
794 EBGEOMETRY_REQUIRE(std::isfinite(a_center2[0]) && std::isfinite(a_center2[1]) && std::isfinite(a_center2[2]),
795 "CylinderSDF: the second center must be finite (%g, %g, %g)",
796 double(a_center2[0]),
797 double(a_center2[1]),
798 double(a_center2[2]));
799 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
800 "CylinderSDF: the radius must be finite and positive (%g)",
801 double(a_radius));
802 EBGEOMETRY_REQUIRE((a_center2 - a_center1).length() > T(0),
803 "CylinderSDF: the two centers must differ, but both are (%g, %g, %g)",
804 double(a_center1[0]),
805 double(a_center1[1]),
806 double(a_center1[2]));
807
808 m_center1 = a_center1;
809 m_center2 = a_center2;
810 m_radius = a_radius;
811
812 m_center = (m_center2 + m_center1) * T(0.5);
815 }
816
820 CylinderSDF(const CylinderSDF&) = default;
821
826
832 operator=(const CylinderSDF&) = default;
833
839 operator=(CylinderSDF&&) = default;
840
845 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
846 const Vec3T<T>&
847 getCenter1() const noexcept
848 {
849 return m_center1;
850 }
851
856 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
857 const Vec3T<T>&
858 getCenter2() const noexcept
859 {
860 return m_center2;
861 }
862
867 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
868 const T&
869 getRadius() const noexcept
870 {
871 return m_radius;
872 }
873
879 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
880 T
881 signedDistance(const Vec3T<T>& a_point) const noexcept
882 {
883 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
884 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
885 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
886
888
889 if (m_length > T(0.0) && m_radius > T(0.0)) {
890 EBGEOMETRY_EXPECT(std::abs(m_axis.length() - T(1)) < std::sqrt(Math::Limits<T>::epsilon()));
891
892 const Vec3T<T> point = a_point - m_center;
893 const T para = dot(point, m_axis);
894 const Vec3T<T> ortho = point - para * m_axis; // Distance from cylinder axis.
895
896 // w: Distance from cylinder wall. < 0 on inside and > 0 on outside.
897 // h: Distance from cylinder top. < 0 on inside and > 0 on outside.
898 const T w = ortho.length() - m_radius;
899 const T h = std::abs(para) - T(0.5) * m_length;
900
901 constexpr T zero = T(0.0);
902
903 if (w <= zero && h <= zero) {
904 // Inside cylinder
905 d = (std::abs(w) < std::abs(h)) ? w : h;
906 }
907 else if (w <= zero && h > zero) {
908 // Above one of the endcaps.
909 d = h;
910 }
911 else if (w > zero && h < zero) {
912 // Outside radius but between the endcaps.
913 d = w;
914 }
915 else {
916 d = std::sqrt(w * w + h * h);
917 }
918 }
919
920 return d;
921 }
922
927 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
928 uint32_t
929 getNumParts() const noexcept
930 {
931 return 3U;
932 }
933
939 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
940 uint32_t
941 closestPart(const Vec3T<T>& a_point) const noexcept
942 {
943 const Vec3T<T> point = a_point - m_center;
944 const T para = dot(point, m_axis);
945 const T w = (point - para * m_axis).length() - m_radius;
946 const T h = std::abs(para) - T(0.5) * m_length;
947
948 // The side where its term decides (inside, the nearer of the two; outside, the larger).
949 const bool side = (w <= T(0) && h <= T(0)) ? (std::abs(w) < std::abs(h)) : (w > h);
950
951 return side ? 0U : ((para < T(0)) ? 1U : 2U);
952 }
953
960 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
962 computeBoundingVolume() const noexcept
963 {
964 Vec3T<T> reach;
965
966 for (size_t dir = 0; dir < 3; dir++) {
967 reach[dir] = m_radius * std::sqrt(Math::max(T(0), T(1) - m_axis[dir] * m_axis[dir]));
968 }
969
971 }
972
973protected:
977 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
978
982 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
983
988
992 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
993
997 T m_length = T(1);
998
1002 T m_radius = T(1);
1003};
1004
1014template <class T>
1016{
1017 static_assert(std::is_floating_point_v<T>, "InfiniteCylinderSDF<T>: T must be a floating-point type");
1018
1019public:
1024
1030
1037 InfiniteCylinderSDF(const Vec3T<T>& a_center, const T& a_radius, const size_t a_axis)
1038 {
1039 EBGEOMETRY_REQUIRE(std::isfinite(a_center[0]) && std::isfinite(a_center[1]) && std::isfinite(a_center[2]),
1040 "InfiniteCylinderSDF: the center must be finite (%g, %g, %g)",
1041 double(a_center[0]),
1042 double(a_center[1]),
1043 double(a_center[2]));
1044 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
1045 "InfiniteCylinderSDF: the radius must be finite and positive (%g)",
1046 double(a_radius));
1047 EBGEOMETRY_REQUIRE(a_axis < 3U, "InfiniteCylinderSDF: the axis must be 0, 1 or 2 (%zu)", a_axis);
1048
1049 m_center = a_center;
1050 m_radius = a_radius;
1051 m_axis = a_axis;
1052 }
1053
1058
1063
1070
1077
1083 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1084 T
1085 signedDistance(const Vec3T<T>& a_point) const noexcept
1086 {
1087 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1088 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1089 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1090
1091 Vec3T<T> delta = a_point - m_center;
1092 delta[m_axis] = 0.0;
1093
1094 const T d = delta.length() - m_radius;
1095
1096 return d;
1097 }
1098
1104 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1106 computeBoundingVolume() const noexcept
1107 {
1110
1113
1114 return BoundingVolumes::AABBT<T>(lo, hi);
1115 }
1116
1121 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1122 const Vec3T<T>&
1123 getCenter() const noexcept
1124 {
1125 return m_center;
1126 }
1127
1132 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1133 const T&
1134 getRadius() const noexcept
1135 {
1136 return m_radius;
1137 }
1138
1143 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1144 const size_t&
1145 getAxis() const noexcept
1146 {
1147 return m_axis;
1148 }
1149
1150protected:
1155
1159 T m_radius = T(1);
1160
1164 size_t m_axis = 1U;
1165};
1166
1184template <class T>
1186{
1187 static_assert(std::is_floating_point_v<T>, "CapsuleSDF<T>: T must be a floating-point type");
1188
1189public:
1194
1200 CapsuleSDF() = default;
1201
1213 CapsuleSDF(const Vec3T<T>& a_tip1, const Vec3T<T>& a_tip2, const T& a_radius)
1214 {
1215 EBGEOMETRY_REQUIRE(std::isfinite(a_tip1[0]) && std::isfinite(a_tip1[1]) && std::isfinite(a_tip1[2]),
1216 "CapsuleSDF: the first tip must be finite (%g, %g, %g)",
1217 double(a_tip1[0]),
1218 double(a_tip1[1]),
1219 double(a_tip1[2]));
1220 EBGEOMETRY_REQUIRE(std::isfinite(a_tip2[0]) && std::isfinite(a_tip2[1]) && std::isfinite(a_tip2[2]),
1221 "CapsuleSDF: the second tip must be finite (%g, %g, %g)",
1222 double(a_tip2[0]),
1223 double(a_tip2[1]),
1224 double(a_tip2[2]));
1225 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
1226 "CapsuleSDF: the radius must be finite and positive (%g)",
1227 double(a_radius));
1228 EBGEOMETRY_REQUIRE((a_tip2 - a_tip1).length() >= T(2) * a_radius,
1229 "CapsuleSDF: the tips must be at least two radii apart (distance %g, radius %g)",
1230 double((a_tip2 - a_tip1).length()),
1231 double(a_radius));
1232
1233 const Vec3T<T> axis = (a_tip2 - a_tip1) / length(a_tip2 - a_tip1);
1234
1235 m_center1 = a_tip1 + a_radius * axis;
1236 m_center2 = a_tip2 - a_radius * axis;
1237 m_radius = a_radius;
1238 }
1239
1243 CapsuleSDF(const CapsuleSDF&) = default;
1244
1249
1254 CapsuleSDF&
1255 operator=(const CapsuleSDF&) = default;
1256
1261 CapsuleSDF&
1262 operator=(CapsuleSDF&&) = default;
1263
1269 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1270 T
1271 signedDistance(const Vec3T<T>& a_point) const noexcept
1272 {
1273 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1274 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1275 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1276
1277 const Vec3T<T> v1 = a_point - m_center1;
1278 const Vec3T<T> v2 = m_center2 - m_center1;
1279
1280 // Tips exactly two radii apart put both hemisphere centers at the same point: a sphere. Guard the
1281 // projection, which would otherwise divide zero by zero.
1282 const T len2 = dot(v2, v2);
1283
1284 const T h = (len2 > T(0)) ? Math::clamp(dot(v1, v2) / len2, T(0.0), T(1.0)) : T(0.0);
1285 const T d = length(v1 - h * v2) - m_radius;
1286
1287 return d;
1288 }
1289
1294 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1295 uint32_t
1296 getNumParts() const noexcept
1297 {
1298 return 3U;
1299 }
1300
1306 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1307 uint32_t
1308 closestPart(const Vec3T<T>& a_point) const noexcept
1309 {
1310 const Vec3T<T> v1 = a_point - m_center1;
1311 const Vec3T<T> v2 = m_center2 - m_center1;
1312 const T len2 = dot(v2, v2);
1313 const T t = (len2 > T(0)) ? dot(v1, v2) / len2 : T(0);
1314
1315 return (t <= T(0)) ? 1U : ((t >= T(1)) ? 2U : 0U);
1316 }
1317
1323 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1330
1335 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1336 const Vec3T<T>&
1337 getCenter1() const noexcept
1338 {
1339 return m_center1;
1340 }
1341
1346 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1347 const Vec3T<T>&
1348 getCenter2() const noexcept
1349 {
1350 return m_center2;
1351 }
1352
1357 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1358 const T&
1359 getRadius() const noexcept
1360 {
1361 return m_radius;
1362 }
1363
1364protected:
1368 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
1369
1373 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
1374
1378 T m_radius = T(0.5);
1379};
1380
1396template <class T>
1398{
1399 static_assert(std::is_floating_point_v<T>, "InfiniteConeSDF<T>: T must be a floating-point type");
1400
1401public:
1406
1411 InfiniteConeSDF() = default;
1412
1419 InfiniteConeSDF(const Vec3T<T>& a_tip, const T& a_angle)
1420 {
1421 EBGEOMETRY_REQUIRE(std::isfinite(a_tip[0]) && std::isfinite(a_tip[1]) && std::isfinite(a_tip[2]),
1422 "InfiniteConeSDF: the tip must be finite (%g, %g, %g)",
1423 double(a_tip[0]),
1424 double(a_tip[1]),
1425 double(a_tip[2]));
1426 EBGEOMETRY_REQUIRE(a_angle > T(0) && a_angle < T(180),
1427 "InfiniteConeSDF: the angle must be in (0, 180) degrees (%g)",
1428 double(a_angle));
1429
1430 m_tip = a_tip;
1431 m_c[0] = std::sin(T(0.5) * a_angle * pi<T> / T(180));
1432 m_c[1] = std::cos(T(0.5) * a_angle * pi<T> / T(180));
1433 }
1434
1439
1444
1450 operator=(const InfiniteConeSDF&) = default;
1451
1458
1464 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1465 T
1466 signedDistance(const Vec3T<T>& a_point) const noexcept
1467 {
1468 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1469 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1470 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1471 EBGEOMETRY_EXPECT(std::abs(length(m_c) - T(1)) < std::sqrt(Math::Limits<T>::epsilon()));
1472
1473 const Vec3T<T> delta = a_point - m_tip;
1474 const Vec2T<T> q(std::sqrt(delta[0] * delta[0] + delta[2] * delta[2]), -delta[1]);
1475
1476 const T d1 = length(q - m_c * Math::max(dot(q, m_c), T(0.0)));
1477 const T d2 = d1 * ((q[0] * m_c[1] - q[1] * m_c[0] < T(0.0)) ? T(-1.0) : T(1.0));
1478
1479 return d2;
1480 }
1481
1487 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1489 computeBoundingVolume() const noexcept
1490 {
1491 Vec3T<T> hi = Vec3T<T>::max();
1492
1493 hi[1] = m_tip[1];
1494
1496 }
1497
1498protected:
1503
1507 Vec2T<T> m_c = Vec2T<T>(std::sin(pi<T> / T(8)), std::cos(pi<T> / T(8)));
1508};
1509
1522template <class T>
1524{
1525 static_assert(std::is_floating_point_v<T>, "ConeSDF<T>: T must be a floating-point type");
1526
1527public:
1532
1537 ConeSDF() = default;
1538
1545 ConeSDF(const Vec3T<T>& a_tip, const T& a_height, const T& a_angle)
1546 {
1547 EBGEOMETRY_REQUIRE(std::isfinite(a_tip[0]) && std::isfinite(a_tip[1]) && std::isfinite(a_tip[2]),
1548 "ConeSDF: the tip must be finite (%g, %g, %g)",
1549 double(a_tip[0]),
1550 double(a_tip[1]),
1551 double(a_tip[2]));
1552 EBGEOMETRY_REQUIRE(std::isfinite(a_height) && a_height > T(0),
1553 "ConeSDF: the height must be finite and positive (%g)",
1554 double(a_height));
1556 a_angle > T(0) && a_angle < T(180), "ConeSDF: the angle must be in (0, 180) degrees (%g)", double(a_angle));
1557
1558 m_tip = a_tip;
1559 m_height = a_height;
1560 m_c[0] = std::sin(T(0.5) * a_angle * pi<T> / T(180));
1561 m_c[1] = std::cos(T(0.5) * a_angle * pi<T> / T(180));
1562 }
1563
1567 ConeSDF(const ConeSDF&) = default;
1568
1572 ConeSDF(ConeSDF&&) = default;
1573
1578 ConeSDF&
1579 operator=(const ConeSDF&) = default;
1580
1585 ConeSDF&
1586 operator=(ConeSDF&&) = default;
1587
1593 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1594 T
1595 signedDistance(const Vec3T<T>& a_point) const noexcept
1596 {
1597 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1598 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1599 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1600 EBGEOMETRY_EXPECT(std::abs(length(m_c) - T(1)) < std::sqrt(Math::Limits<T>::epsilon()));
1601 EBGEOMETRY_EXPECT(m_c[1] > T(0));
1602
1603 const Vec3T<T> delta = a_point - m_tip;
1604 const T dr = std::sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
1605 const T dz = delta[1];
1606
1607 constexpr T zero = T(0.0);
1608 constexpr T one = T(1.0);
1609
1610 const Vec2T<T> q = m_height * Vec2T<T>(m_c[0] / m_c[1], -1.0);
1611 const Vec2T<T> w = Vec2T<T>(dr, dz);
1612 const Vec2T<T> a = w - Math::clamp(dot(w, q) / dot(q, q), zero, one) * q;
1613 const Vec2T<T> b = w - Vec2T<T>(q[0] * Math::clamp(w[0] / q[0], zero, one), q[1]);
1614
1615 auto sign = [](const T& x) -> int { return (x > zero) - (x < zero); };
1616
1617 const T k = sign(q[1]);
1618 const T d = Math::min(dot(a, a), dot(b, b));
1619 const T s = Math::max(k * (w[0] * q[1] - w[1] * q[0]), k * (w[1] - q[1]));
1620
1621 return std::sqrt(d) * sign(s);
1622 }
1623
1628 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1629 uint32_t
1630 getNumParts() const noexcept
1631 {
1632 return 2U;
1633 }
1634
1640 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1641 uint32_t
1642 closestPart(const Vec3T<T>& a_point) const noexcept
1643 {
1644 const Vec3T<T> delta = a_point - m_tip;
1645 const Vec2T<T> q = m_height * Vec2T<T>(m_c[0] / m_c[1], -1.0);
1646 const Vec2T<T> w = Vec2T<T>(std::sqrt(delta[0] * delta[0] + delta[2] * delta[2]), delta[1]);
1647 const Vec2T<T> a = w - Math::clamp(dot(w, q) / dot(q, q), T(0), T(1)) * q;
1648 const Vec2T<T> b = w - Vec2T<T>(q[0] * Math::clamp(w[0] / q[0], T(0), T(1)), q[1]);
1649
1650 return (dot(a, a) <= dot(b, b)) ? 0U : 1U;
1651 }
1652
1659 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1661 computeBoundingVolume() const noexcept
1662 {
1663 const T baseRadius = m_height * m_c[0] / m_c[1];
1664
1665 return BoundingVolumes::AABBT<T>(m_tip - Vec3T<T>(baseRadius, m_height, baseRadius),
1666 m_tip + Vec3T<T>(baseRadius, T(0), baseRadius));
1667 }
1668
1669protected:
1674
1678 Vec2T<T> m_c = Vec2T<T>(std::sin(pi<T> / T(8)), std::cos(pi<T> / T(8)));
1679
1683 T m_height = T(1);
1684};
1685
1694template <class T>
1696{
1697 static_assert(std::is_floating_point_v<T>, "RoundedBoxSDF<T>: T must be a floating-point type");
1698
1699public:
1704
1709 RoundedBoxSDF() = default;
1710
1718 RoundedBoxSDF(const Vec3T<T>& a_center, const Vec3T<T>& a_size, const T a_curvature)
1719 {
1720 EBGEOMETRY_REQUIRE(std::isfinite(a_center[0]) && std::isfinite(a_center[1]) && std::isfinite(a_center[2]),
1721 "RoundedBoxSDF: the center must be finite (%g, %g, %g)",
1722 double(a_center[0]),
1723 double(a_center[1]),
1724 double(a_center[2]));
1725 EBGEOMETRY_REQUIRE(std::isfinite(a_curvature) && a_curvature > T(0),
1726 "RoundedBoxSDF: the curvature must be finite and positive (%g)",
1727 double(a_curvature));
1728 EBGEOMETRY_REQUIRE(std::isfinite(a_size[0]) && std::isfinite(a_size[1]) && std::isfinite(a_size[2]) &&
1729 a_size[0] > T(2) * a_curvature && a_size[1] > T(2) * a_curvature &&
1730 a_size[2] > T(2) * a_curvature,
1731 "RoundedBoxSDF: the size (%g, %g, %g) must be finite and exceed twice the curvature (%g)",
1732 double(a_size[0]),
1733 double(a_size[1]),
1734 double(a_size[2]),
1735 double(a_curvature));
1736
1737 m_center = a_center;
1738 m_dimensions = T(0.5) * a_size - a_curvature * Vec3T<T>::ones();
1739 m_curvature = a_curvature;
1740 }
1741
1745 RoundedBoxSDF(const RoundedBoxSDF&) = default;
1746
1751
1757 operator=(const RoundedBoxSDF&) = default;
1758
1765
1771 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1772 T
1773 signedDistance(const Vec3T<T>& a_point) const noexcept
1774 {
1775 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1776 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1777 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1778
1779 // q is the point's per-axis distance beyond the inner box (negative inside it). Outside, the
1780 // distance to the inner box is the length of q's positive part; inside, it is the distance to
1781 // the nearest face, max(q) <= 0. Either way the rounding moves the surface out by m_curvature.
1782 const Vec3T<T> p = a_point - m_center;
1783 const Vec3T<T> q(
1784 std::abs(p[0]) - m_dimensions[0], std::abs(p[1]) - m_dimensions[1], std::abs(p[2]) - m_dimensions[2]);
1785
1786 const T outside = length(max(q, Vec3T<T>::zeros()));
1787 const T inside = Math::min(Math::max(q[0], Math::max(q[1], q[2])), T(0));
1788
1789 return outside + inside - m_curvature;
1790 }
1791
1796 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1797 uint32_t
1798 getNumParts() const noexcept
1799 {
1800 return 6U;
1801 }
1802
1808 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1809 uint32_t
1810 closestPart(const Vec3T<T>& a_point) const noexcept
1811 {
1812 const Vec3T<T> p = a_point - m_center;
1813 const Vec3T<T> q(
1814 std::abs(p[0]) - m_dimensions[0], std::abs(p[1]) - m_dimensions[1], std::abs(p[2]) - m_dimensions[2]);
1815
1816 const size_t axis = q.maxDir(false);
1817
1818 return 2U * uint32_t(axis) + ((p[axis] > T(0)) ? 1U : 0U);
1819 }
1820
1826 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1828 computeBoundingVolume() const noexcept
1829 {
1831
1832 return BoundingVolumes::AABBT<T>(m_center - half, m_center + half);
1833 }
1834
1835protected:
1839 T m_curvature = T(0.1);
1840
1845
1849 Vec3T<T> m_dimensions = Vec3T<T>(T(0.4), T(0.4), T(0.4));
1850};
1851
1869template <class T>
1871{
1872 static_assert(std::is_floating_point_v<T>, "PerlinSDF<T>: T must be a floating-point type");
1873
1874public:
1880
1885 PerlinSDF() noexcept : PerlinSDF(T(1), Vec3T<T>::ones(), T(0.5), 1U)
1886 {}
1887
1896 PerlinSDF(const T a_noiseAmplitude,
1897 const Vec3T<T> a_noiseFrequency,
1898 const T a_noisePersistence,
1899 const unsigned int a_noiseOctaves)
1900 {
1902 std::isfinite(a_noiseAmplitude), "PerlinSDF: the noise amplitude must be finite (%g)", double(a_noiseAmplitude));
1903 EBGEOMETRY_REQUIRE(std::isfinite(a_noiseFrequency[0]) && std::isfinite(a_noiseFrequency[1]) &&
1904 std::isfinite(a_noiseFrequency[2]),
1905 "PerlinSDF: the noise frequency must be finite (%g, %g, %g)",
1906 double(a_noiseFrequency[0]),
1907 double(a_noiseFrequency[1]),
1908 double(a_noiseFrequency[2]));
1909 EBGEOMETRY_REQUIRE(std::isfinite(a_noisePersistence),
1910 "PerlinSDF: the noise persistence must be finite (%g)",
1911 double(a_noisePersistence));
1912
1913 m_noiseAmplitude = a_noiseAmplitude;
1914 m_noiseFrequency = a_noiseFrequency;
1915 m_noisePersistence = Math::min(T(1), a_noisePersistence);
1916 m_noiseOctaves = Math::max(1U, a_noiseOctaves);
1917
1918 // Each octave divides the frequency by the persistence, so zero would give an infinite frequency
1919 // (and NaN noise) for an octave that contributes nothing anyway.
1920 if (!(m_noisePersistence > T(0))) {
1921 m_noisePersistence = T(1);
1922 m_noiseOctaves = 1U;
1923 }
1924
1925 std::mt19937 g(0);
1926 this->shuffle(g);
1927 }
1928
1932 PerlinSDF(const PerlinSDF&) = default;
1933
1937 PerlinSDF(PerlinSDF&&) = default;
1938
1943 PerlinSDF&
1944 operator=(const PerlinSDF&) = default;
1945
1950 PerlinSDF&
1951 operator=(PerlinSDF&&) = default;
1952
1958 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1959 T
1960 signedDistance(const Vec3T<T>& a_point) const noexcept
1961 {
1962 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
1963 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
1964 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
1965
1966 T ret = 0.0;
1967
1968 Vec3T<T> curFreq = m_noiseFrequency;
1969 T curAmp = 1.0;
1970
1971 for (unsigned int curOctave = 0; curOctave < m_noiseOctaves; curOctave++) {
1972 ret += T(0.5) * curAmp * (T(1) + this->noise(a_point * curFreq));
1973
1974 curFreq = curFreq / m_noisePersistence;
1975 curAmp = curAmp * m_noisePersistence;
1976 }
1977
1978 return ret * m_noiseAmplitude;
1979 };
1980
1993 template <class URNG>
1994 void
1995 shuffle(URNG& g) noexcept
1996 {
1997
1998 for (unsigned int i = 0; i < 256; i++) {
1999 m_permutationTable[i] = static_cast<int>(i);
2000 }
2001
2002 std::shuffle(m_permutationTable.begin(), m_permutationTable.begin() + 256, g);
2003
2004 for (int i = 0; i < 256; i++) {
2006 }
2007 }
2008
2015 {
2016 return m_permutationTable;
2017 }
2018
2024 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2026 computeBoundingVolume() const noexcept
2027 {
2029 }
2030
2031protected:
2036
2041
2046
2053
2057 unsigned int m_noiseOctaves = 1U;
2058
2066 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2067 T
2068 lerp(const T t, const T a, const T b) const noexcept
2069 {
2070 return a + t * (b - a);
2071 };
2072
2078 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2079 T
2080 fade(const T t) const noexcept
2081 {
2082 return t * t * t * (t * (t * 6 - 15) + 10);
2083 };
2084
2093 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2094 T
2095 grad(const int hash, const T x, const T y, const T z) const noexcept
2096 {
2097 const int h = hash & 15;
2098 const T u = h < 8 ? x : y;
2099 const T v = h < 4 ? y : h == 12 || h == 14 ? x : z;
2100 return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
2101 }
2102
2108 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2109 T
2110 noise(const Vec3T<T>& a_point) const noexcept
2111 {
2112 // Lower cube corner
2113 const int X = static_cast<int>(std::floor(a_point[0])) & 255;
2114 const int Y = static_cast<int>(std::floor(a_point[1])) & 255;
2115 const int Z = static_cast<int>(std::floor(a_point[2])) & 255;
2116
2117 // Relative distance wrt lower cube corner
2118 const T x = a_point[0] - std::floor(a_point[0]);
2119 const T y = a_point[1] - std::floor(a_point[1]);
2120 const T z = a_point[2] - std::floor(a_point[2]);
2121
2122 // Fade curves
2123 const T u = fade(x);
2124 const T v = fade(y);
2125 const T w = fade(z);
2126
2127 // Hash coordinates of 8 cube corners
2128 const int A = m_permutationTable[X] + Y;
2129 const int AA = m_permutationTable[A] + Z;
2130 const int AB = m_permutationTable[A + 1] + Z;
2131 const int B = m_permutationTable[X + 1] + Y;
2132 const int BA = m_permutationTable[B] + Z;
2133 const int BB = m_permutationTable[B + 1] + Z;
2134
2135 // Add blended results from 8 corners of cube
2136 return lerp(
2137 w,
2138 lerp(v,
2139 lerp(u, grad(m_permutationTable[AA], x, y, z), grad(m_permutationTable[BA], x - 1, y, z)),
2140 lerp(u, grad(m_permutationTable[AB], x, y - 1, z), grad(m_permutationTable[BB], x - 1, y - 1, z))),
2141 lerp(v,
2142 lerp(u, grad(m_permutationTable[AA + 1], x, y, z - 1), grad(m_permutationTable[BA + 1], x - 1, y, z - 1)),
2143 lerp(u,
2144 grad(m_permutationTable[AB + 1], x, y - 1, z - 1),
2145 grad(m_permutationTable[BB + 1], x - 1, y - 1, z - 1))));
2146 };
2147};
2148
2171template <class T>
2173{
2174 static_assert(std::is_floating_point_v<T>, "RoundedCylinderSDF<T>: T must be a floating-point type");
2175
2176public:
2181
2187
2196 RoundedCylinderSDF(const Vec3T<T>& a_center, const T a_radius, const T a_curvature, const T a_height)
2197 {
2198 EBGEOMETRY_REQUIRE(std::isfinite(a_center[0]) && std::isfinite(a_center[1]) && std::isfinite(a_center[2]),
2199 "RoundedCylinderSDF: the center must be finite (%g, %g, %g)",
2200 double(a_center[0]),
2201 double(a_center[1]),
2202 double(a_center[2]));
2203 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
2204 "RoundedCylinderSDF: the radius must be finite and positive (%g)",
2205 double(a_radius));
2206 EBGEOMETRY_REQUIRE(std::isfinite(a_curvature) && a_curvature > T(0),
2207 "RoundedCylinderSDF: the curvature must be finite and positive (%g)",
2208 double(a_curvature));
2209 EBGEOMETRY_REQUIRE(std::isfinite(a_height) && a_height > T(0),
2210 "RoundedCylinderSDF: the height must be finite and positive (%g)",
2211 double(a_height));
2212 EBGEOMETRY_REQUIRE(a_curvature < a_radius,
2213 "RoundedCylinderSDF: the curvature (%g) must be less than the radius (%g)",
2214 double(a_curvature),
2215 double(a_radius));
2216 EBGEOMETRY_REQUIRE(T(2) * a_curvature < a_height,
2217 "RoundedCylinderSDF: twice the curvature (%g) must be less than the height (%g)",
2218 double(a_curvature),
2219 double(a_height));
2220
2221 m_center = a_center;
2222 m_majorRadius = a_radius - a_curvature;
2223 m_minorRadius = a_curvature;
2224 m_height = T(0.5) * a_height - a_curvature;
2225 }
2226
2231
2236
2243
2250
2256 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2257 T
2258 signedDistance(const Vec3T<T>& a_point) const noexcept
2259 {
2260 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
2261 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
2262 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
2263
2264 const Vec3T<T> p = a_point - m_center;
2265 const T xz = std::sqrt(p[2] * p[2] + p[0] * p[0]);
2266 const auto d1 = Vec2T<T>(xz - m_majorRadius, std::abs(p[1]) - m_height);
2267 const auto d2 = Vec2T<T>(Math::max(d1[0], T(0)), Math::max(d1[1], T(0)));
2268
2269 return Math::min(Math::max(d1[0], d1[1]), T(0)) + std::sqrt(d2[0] * d2[0] + d2[1] * d2[1]) - m_minorRadius;
2270 }
2271
2276 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2277 uint32_t
2278 getNumParts() const noexcept
2279 {
2280 return 3U;
2281 }
2282
2288 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2289 uint32_t
2290 closestPart(const Vec3T<T>& a_point) const noexcept
2291 {
2292 const Vec3T<T> p = a_point - m_center;
2293 const T xz = std::sqrt(p[2] * p[2] + p[0] * p[0]);
2294 const T r = xz - m_majorRadius;
2295 const T y = std::abs(p[1]) - m_height;
2296
2297 return (r >= y) ? 0U : ((p[1] < T(0)) ? 1U : 2U);
2298 }
2299
2305 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2307 computeBoundingVolume() const noexcept
2308 {
2309 const T radius = m_majorRadius + m_minorRadius;
2310 const Vec3T<T> half(radius, m_height + m_minorRadius, radius);
2311
2312 return BoundingVolumes::AABBT<T>(m_center - half, m_center + half);
2313 }
2314
2315protected:
2320
2324 T m_majorRadius = T(0.9);
2325
2329 T m_minorRadius = T(0.1);
2330
2334 T m_height = T(0.4);
2335};
2336
2337namespace AnalyticDetail {
2338
2344template <class T>
2346{
2351
2356};
2357
2368template <class T>
2369[[nodiscard]] EBGEOMETRY_HOST_DEVICE
2371axialCoordinates(const Vec3T<T>& a_point, const Vec3T<T>& a_start, const Vec3T<T>& a_axis) noexcept
2372{
2373 const Vec3T<T> w = a_point - a_start;
2374 const T along = dot(w, a_axis);
2375
2376 return AxialCoordinates<T>{(w - along * a_axis).length(), along};
2377}
2378
2388template <class T>
2389[[nodiscard]] EBGEOMETRY_HOST_DEVICE
2390inline T
2391extrusion(const T a_profile, const T a_slab) noexcept
2392{
2393 const T outsideProfile = Math::max(a_profile, T(0));
2394 const T outsideSlab = Math::max(a_slab, T(0));
2395
2396 return Math::min(Math::max(a_profile, a_slab), T(0)) +
2397 std::sqrt(outsideProfile * outsideProfile + outsideSlab * outsideSlab);
2398}
2399
2407template <class T>
2408[[nodiscard]] inline bool
2409isFinite(const Vec3T<T>& a_point) noexcept
2410{
2411 return std::isfinite(a_point[0]) && std::isfinite(a_point[1]) && std::isfinite(a_point[2]);
2412}
2413
2431template <class T, size_t N>
2432[[nodiscard]] EBGEOMETRY_HOST_DEVICE
2433inline T
2434ellipsoidRoot(const T (&a_r)[N], const T (&a_n)[N], const T a_lo, const T a_hi) noexcept
2435{
2436 constexpr int MaxIterations = 64;
2437
2438 const T eps = Math::Limits<T>::epsilon();
2439
2440 // Only s moves: hi stays a_hi, a fixed safeguard for a step that rounding pushes past the root, not a
2441 // bracket that shrinks.
2442 T s = a_lo;
2443 T hi = a_hi;
2444
2445 for (int i = 0; i < MaxIterations; i++) {
2446 T f = T(-1);
2447 T df = T(0);
2448
2449 for (size_t k = 0; k < N; k++) {
2450 const T ratio = a_n[k] / (s + a_r[k]);
2451
2452 f += ratio * ratio;
2453 df -= T(2) * ratio * ratio / (s + a_r[k]);
2454 }
2455
2456 if (f <= T(0)) {
2457 break;
2458 }
2459
2460 T next = (df < T(0)) ? s - f / df : hi;
2461
2462 // No progress: s is the root to rounding. (Bisecting from here would step past it.)
2463 if (!(next > s)) {
2464 break;
2465 }
2466 if (next > hi) {
2467 next = T(0.5) * (s + hi);
2468 }
2469
2470 const bool converged = next - s <= T(4) * eps * Math::max(T(1), std::abs(s));
2471
2472 s = next;
2473
2474 if (converged) {
2475 break;
2476 }
2477 }
2478
2479 return s;
2480}
2481
2493template <class T>
2494[[nodiscard]] EBGEOMETRY_HOST_DEVICE
2495inline T
2496ellipseDistance(const T a_e0, const T a_e1, const T a_y0, const T a_y1) noexcept
2497{
2498 if (a_y1 > T(0)) {
2499 if (a_y0 > T(0)) {
2500 const T z0 = a_y0 / a_e0;
2501 const T z1 = a_y1 / a_e1;
2502 const T g = z0 * z0 + z1 * z1 - T(1);
2503
2504 if (g == T(0)) {
2505 return T(0);
2506 }
2507
2508 const T r0 = (a_e0 / a_e1) * (a_e0 / a_e1);
2509 const T r[2]{r0, T(1)};
2510 const T n[2]{r0 * z0, z1};
2511 const T s = ellipsoidRoot<T, 2>(r, n, z1 - T(1), (g < T(0)) ? T(0) : std::sqrt(n[0] * n[0] + z1 * z1) - T(1));
2512
2513 const T x0 = r0 * a_y0 / (s + r0);
2514 const T x1 = a_y1 / (s + T(1));
2515
2516 return std::sqrt((x0 - a_y0) * (x0 - a_y0) + (x1 - a_y1) * (x1 - a_y1));
2517 }
2518
2519 return std::abs(a_y1 - a_e1);
2520 }
2521
2522 const T numer0 = a_e0 * a_y0;
2523 const T denom0 = a_e0 * a_e0 - a_e1 * a_e1;
2524
2525 if (numer0 < denom0) {
2526 const T xde0 = numer0 / denom0;
2527 const T x0 = a_e0 * xde0;
2528 const T x1 = a_e1 * std::sqrt(Math::max(T(0), T(1) - xde0 * xde0));
2529
2530 return std::sqrt((x0 - a_y0) * (x0 - a_y0) + x1 * x1);
2531 }
2532
2533 return std::abs(a_y0 - a_e0);
2534}
2535
2553template <class T>
2554[[nodiscard]] EBGEOMETRY_HOST_DEVICE
2556inline T
2557ellipsoidDistance(const T a_e0, const T a_e1, const T a_e2, const T a_y0, const T a_y1, const T a_y2) noexcept
2558{
2559 if (a_y2 > T(0)) {
2560 if (a_y1 > T(0)) {
2561 if (a_y0 > T(0)) {
2562 const T z0 = a_y0 / a_e0;
2563 const T z1 = a_y1 / a_e1;
2564 const T z2 = a_y2 / a_e2;
2565 const T g = z0 * z0 + z1 * z1 + z2 * z2 - T(1);
2566
2567 if (g == T(0)) {
2568 return T(0);
2569 }
2570
2571 const T r0 = (a_e0 / a_e2) * (a_e0 / a_e2);
2572 const T r1 = (a_e1 / a_e2) * (a_e1 / a_e2);
2573 const T r[3]{r0, r1, T(1)};
2574 const T n[3]{r0 * z0, r1 * z1, z2};
2575 const T hi = (g < T(0)) ? T(0) : std::sqrt(n[0] * n[0] + n[1] * n[1] + z2 * z2) - T(1);
2576 const T s = ellipsoidRoot<T, 3>(r, n, z2 - T(1), hi);
2577
2578 const T x0 = r0 * a_y0 / (s + r0);
2579 const T x1 = r1 * a_y1 / (s + r1);
2580 const T x2 = a_y2 / (s + T(1));
2581
2582 return std::sqrt((x0 - a_y0) * (x0 - a_y0) + (x1 - a_y1) * (x1 - a_y1) + (x2 - a_y2) * (x2 - a_y2));
2583 }
2584
2585 return ellipseDistance(a_e1, a_e2, a_y1, a_y2);
2586 }
2587
2588 if (a_y0 > T(0)) {
2589 return ellipseDistance(a_e0, a_e2, a_y0, a_y2);
2590 }
2591
2592 return std::abs(a_y2 - a_e2);
2593 }
2594
2595 const T denom0 = a_e0 * a_e0 - a_e2 * a_e2;
2596 const T denom1 = a_e1 * a_e1 - a_e2 * a_e2;
2597 const T numer0 = a_e0 * a_y0;
2598 const T numer1 = a_e1 * a_y1;
2599
2600 if (numer0 < denom0 && numer1 < denom1) {
2601 const T xde0 = numer0 / denom0;
2602 const T xde1 = numer1 / denom1;
2603 const T discr = T(1) - xde0 * xde0 - xde1 * xde1;
2604
2605 if (discr > T(0)) {
2606 const T x0 = a_e0 * xde0;
2607 const T x1 = a_e1 * xde1;
2608 const T x2 = a_e2 * std::sqrt(discr);
2609
2610 return std::sqrt((x0 - a_y0) * (x0 - a_y0) + (x1 - a_y1) * (x1 - a_y1) + x2 * x2);
2611 }
2612 }
2613
2614 return ellipseDistance(a_e0, a_e1, a_y0, a_y1);
2615}
2616
2617} // namespace AnalyticDetail
2618
2630template <class T>
2632{
2633 static_assert(std::is_floating_point_v<T>, "EllipsoidSDF<T>: T must be a floating-point type");
2634
2635public:
2640
2644 EllipsoidSDF() = default;
2645
2651 EllipsoidSDF(const Vec3T<T>& a_center, const Vec3T<T>& a_radii)
2652 {
2653 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
2654 "EllipsoidSDF: the center must be finite (%g, %g, %g)",
2655 double(a_center[0]),
2656 double(a_center[1]),
2657 double(a_center[2]));
2658 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_radii) && a_radii[0] > T(0) && a_radii[1] > T(0) && a_radii[2] > T(0),
2659 "EllipsoidSDF: the radii must be finite and positive (%g, %g, %g)",
2660 double(a_radii[0]),
2661 double(a_radii[1]),
2662 double(a_radii[2]));
2663
2664 m_center = a_center;
2665 m_radii = a_radii;
2666 }
2667
2671 EllipsoidSDF(const EllipsoidSDF&) = default;
2672
2677
2683 operator=(const EllipsoidSDF&) = default;
2684
2691
2696 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2697 const Vec3T<T>&
2698 getCenter() const noexcept
2699 {
2700 return m_center;
2701 }
2702
2707 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2708 const Vec3T<T>&
2709 getRadii() const noexcept
2710 {
2711 return m_radii;
2712 }
2713
2721 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2722 T
2723 signedDistance(const Vec3T<T>& a_point) const noexcept
2724 {
2725 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
2726 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
2727 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
2728
2729 T e[3]{m_radii[0], m_radii[1], m_radii[2]};
2730 T y[3]{std::abs(a_point[0] - m_center[0]), std::abs(a_point[1] - m_center[1]), std::abs(a_point[2] - m_center[2])};
2731
2732 const T inside = (y[0] / e[0]) * (y[0] / e[0]) + (y[1] / e[1]) * (y[1] / e[1]) + (y[2] / e[2]) * (y[2] / e[2]);
2733
2734 // Sort the axes from largest to smallest, carrying the coordinates along.
2735 const auto order = [&e, &y](const size_t a_i, const size_t a_j) noexcept {
2736 if (e[a_i] < e[a_j]) {
2737 const T axis = e[a_i];
2738 const T coord = y[a_i];
2739
2740 e[a_i] = e[a_j];
2741 y[a_i] = y[a_j];
2742 e[a_j] = axis;
2743 y[a_j] = coord;
2744 }
2745 };
2746
2747 order(0, 1);
2748 order(1, 2);
2749 order(0, 1);
2750
2751 const T distance = AnalyticDetail::ellipsoidDistance(e[0], e[1], e[2], y[0], y[1], y[2]);
2752
2753 return (inside < T(1)) ? -distance : distance;
2754 }
2755
2760 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2762 computeBoundingVolume() const noexcept
2763 {
2765 }
2766
2767protected:
2772
2777};
2778
2788template <class T>
2790{
2791 static_assert(std::is_floating_point_v<T>, "CappedConeSDF<T>: T must be a floating-point type");
2792
2793public:
2798
2802 CappedConeSDF() = default;
2803
2811 CappedConeSDF(const Vec3T<T>& a_center1, const Vec3T<T>& a_center2, const T a_radius1, const T a_radius2)
2812 {
2813 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center1),
2814 "CappedConeSDF: the first center must be finite (%g, %g, %g)",
2815 double(a_center1[0]),
2816 double(a_center1[1]),
2817 double(a_center1[2]));
2818 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center2),
2819 "CappedConeSDF: the second center must be finite (%g, %g, %g)",
2820 double(a_center2[0]),
2821 double(a_center2[1]),
2822 double(a_center2[2]));
2823 EBGEOMETRY_REQUIRE((a_center2 - a_center1).length() > T(0),
2824 "CappedConeSDF: the two centers must differ, but both are (%g, %g, %g)",
2825 double(a_center1[0]),
2826 double(a_center1[1]),
2827 double(a_center1[2]));
2828 EBGEOMETRY_REQUIRE(std::isfinite(a_radius1) && std::isfinite(a_radius2) && a_radius1 >= T(0) && a_radius2 >= T(0) &&
2829 a_radius1 + a_radius2 > T(0),
2830 "CappedConeSDF: the radii must be finite, at least 0 and not both 0 (%g, %g)",
2831 double(a_radius1),
2832 double(a_radius2));
2833
2834 m_center1 = a_center1;
2835 m_center2 = a_center2;
2836 m_radius1 = a_radius1;
2837 m_radius2 = a_radius2;
2838 m_length = (a_center2 - a_center1).length();
2839 m_axis = (a_center2 - a_center1) / m_length;
2840 }
2841
2845 CappedConeSDF(const CappedConeSDF&) = default;
2846
2851
2857 operator=(const CappedConeSDF&) = default;
2858
2865
2870 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2871 const Vec3T<T>&
2872 getCenter1() const noexcept
2873 {
2874 return m_center1;
2875 }
2876
2881 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2882 const Vec3T<T>&
2883 getCenter2() const noexcept
2884 {
2885 return m_center2;
2886 }
2887
2892 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2893 const T&
2894 getRadius1() const noexcept
2895 {
2896 return m_radius1;
2897 }
2898
2903 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2904 const T&
2905 getRadius2() const noexcept
2906 {
2907 return m_radius2;
2908 }
2909
2915 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2916 T
2917 signedDistance(const Vec3T<T>& a_point) const noexcept
2918 {
2919 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
2920 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
2921 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
2922
2923 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
2924
2925 const T x = q.m_radial;
2926 const T y = q.m_axial;
2927 const T h = m_length;
2928
2929 // Distance to the nearer end disc: radially beyond its radius, and axially beyond the slab.
2930 const T capX = Math::max(T(0), x - ((y < T(0.5) * h) ? m_radius1 : m_radius2));
2931 const T capY = std::abs(y - T(0.5) * h) - T(0.5) * h;
2932
2933 // Distance to the slanted side, the segment from (radius1, 0) to (radius2, h).
2934 const T dr = m_radius2 - m_radius1;
2935 const T f = Math::clamp((dr * (x - m_radius1) + y * h) / (dr * dr + h * h), T(0), T(1));
2936 const T sideX = x - m_radius1 - f * dr;
2937 const T sideY = y - f * h;
2938
2939 const T sign = (sideX < T(0) && capY < T(0)) ? T(-1) : T(1);
2940
2941 return sign * std::sqrt(Math::min(capX * capX + capY * capY, sideX * sideX + sideY * sideY));
2942 }
2943
2948 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2949 uint32_t
2950 getNumParts() const noexcept
2951 {
2952 return 3U;
2953 }
2954
2960 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2961 uint32_t
2962 closestPart(const Vec3T<T>& a_point) const noexcept
2963 {
2964 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
2965
2966 const T x = q.m_radial;
2967 const T y = q.m_axial;
2968 const T h = m_length;
2969
2970 const T capX = Math::max(T(0), x - ((y < T(0.5) * h) ? m_radius1 : m_radius2));
2971 const T capY = std::abs(y - T(0.5) * h) - T(0.5) * h;
2972
2973 const T dr = m_radius2 - m_radius1;
2974 const T f = Math::clamp((dr * (x - m_radius1) + y * h) / (dr * dr + h * h), T(0), T(1));
2975 const T sideX = x - m_radius1 - f * dr;
2976 const T sideY = y - f * h;
2977
2978 if (sideX * sideX + sideY * sideY <= capX * capX + capY * capY) {
2979 return 0U;
2980 }
2981
2982 return (y < T(0.5) * h) ? 1U : 2U;
2983 }
2984
2991 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
2993 computeBoundingVolume() const noexcept
2994 {
2995 Vec3T<T> lo;
2996 Vec3T<T> hi;
2997
2998 for (size_t dir = 0; dir < 3; dir++) {
2999 const T across = std::sqrt(Math::max(T(0), T(1) - m_axis[dir] * m_axis[dir]));
3000
3001 lo[dir] = Math::min(m_center1[dir] - m_radius1 * across, m_center2[dir] - m_radius2 * across);
3002 hi[dir] = Math::max(m_center1[dir] + m_radius1 * across, m_center2[dir] + m_radius2 * across);
3003 }
3004
3005 return BoundingVolumes::AABBT<T>(lo, hi);
3006 }
3007
3008protected:
3012 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
3013
3017 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
3018
3022 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
3023
3027 T m_length = T(1);
3028
3032 T m_radius1 = T(1);
3033
3037 T m_radius2 = T(0.5);
3038};
3039
3049template <class T>
3051{
3052 static_assert(std::is_floating_point_v<T>, "RoundConeSDF<T>: T must be a floating-point type");
3053
3054public:
3059
3064 RoundConeSDF() = default;
3065
3074 RoundConeSDF(const Vec3T<T>& a_center1, const Vec3T<T>& a_center2, const T a_radius1, const T a_radius2)
3075 {
3076 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center1),
3077 "RoundConeSDF: the first center must be finite (%g, %g, %g)",
3078 double(a_center1[0]),
3079 double(a_center1[1]),
3080 double(a_center1[2]));
3081 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center2),
3082 "RoundConeSDF: the second center must be finite (%g, %g, %g)",
3083 double(a_center2[0]),
3084 double(a_center2[1]),
3085 double(a_center2[2]));
3086 EBGEOMETRY_REQUIRE(std::isfinite(a_radius1) && std::isfinite(a_radius2) && a_radius1 >= T(0) && a_radius2 >= T(0) &&
3087 a_radius1 + a_radius2 > T(0),
3088 "RoundConeSDF: the radii must be finite, at least 0 and not both 0 (%g, %g)",
3089 double(a_radius1),
3090 double(a_radius2));
3091 EBGEOMETRY_REQUIRE(std::abs(a_radius1 - a_radius2) < (a_center2 - a_center1).length(),
3092 "RoundConeSDF: the difference of the radii (%g, %g) must be less than the distance between "
3093 "the centers (%g)",
3094 double(a_radius1),
3095 double(a_radius2),
3096 double((a_center2 - a_center1).length()));
3097
3098 m_center1 = a_center1;
3099 m_center2 = a_center2;
3100 m_radius1 = a_radius1;
3101 m_radius2 = a_radius2;
3102 m_length = (a_center2 - a_center1).length();
3103 m_axis = (a_center2 - a_center1) / m_length;
3104 m_sin = (a_radius1 - a_radius2) / m_length;
3105 m_cos = std::sqrt(T(1) - m_sin * m_sin);
3106 }
3107
3111 RoundConeSDF(const RoundConeSDF&) = default;
3112
3117
3123 operator=(const RoundConeSDF&) = default;
3124
3131
3136 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3137 const Vec3T<T>&
3138 getCenter1() const noexcept
3139 {
3140 return m_center1;
3141 }
3142
3147 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3148 const Vec3T<T>&
3149 getCenter2() const noexcept
3150 {
3151 return m_center2;
3152 }
3153
3158 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3159 const T&
3160 getRadius1() const noexcept
3161 {
3162 return m_radius1;
3163 }
3164
3169 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3170 const T&
3171 getRadius2() const noexcept
3172 {
3173 return m_radius2;
3174 }
3175
3183 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3184 T
3185 signedDistance(const Vec3T<T>& a_point) const noexcept
3186 {
3187 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
3188 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
3189 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
3190
3191 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
3192
3193 const T x = q.m_radial;
3194 const T y = q.m_axial;
3195
3196 // Position along the tangent line's direction (-sin, cos) in the (radial, axial) plane.
3197 const T k = -m_sin * x + m_cos * y;
3198
3199 if (k < T(0)) {
3200 return std::sqrt(x * x + y * y) - m_radius1;
3201 }
3202 if (k > m_cos * m_length) {
3203 return std::sqrt(x * x + (y - m_length) * (y - m_length)) - m_radius2;
3204 }
3205
3206 return m_cos * x + m_sin * y - m_radius1;
3207 }
3208
3213 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3214 uint32_t
3215 getNumParts() const noexcept
3216 {
3217 return 3U;
3218 }
3219
3225 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3226 uint32_t
3227 closestPart(const Vec3T<T>& a_point) const noexcept
3228 {
3229 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
3230
3231 const T k = -m_sin * q.m_radial + m_cos * q.m_axial;
3232
3233 return (k < T(0)) ? 1U : ((k > m_cos * m_length) ? 2U : 0U);
3234 }
3235
3240 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3248
3249protected:
3253 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
3254
3258 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
3259
3263 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
3264
3268 T m_length = T(1);
3269
3273 T m_radius1 = T(0.5);
3274
3278 T m_radius2 = T(0.25);
3279
3283 T m_sin = T(0.25);
3284
3288 T m_cos = T(0.96824583655185422);
3289};
3290
3303template <class T>
3305{
3306 static_assert(std::is_floating_point_v<T>, "PolygonPrismSDF<T>: T must be a floating-point type");
3307
3308public:
3313
3318 PolygonPrismSDF() = default;
3319
3329 PolygonPrismSDF(const Vec3T<T>& a_center1,
3330 const Vec3T<T>& a_center2,
3331 const T a_radius,
3332 const unsigned a_sides,
3333 const Vec3T<T>& a_vertexDirection)
3334 {
3335 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center1),
3336 "PolygonPrismSDF: the first center must be finite (%g, %g, %g)",
3337 double(a_center1[0]),
3338 double(a_center1[1]),
3339 double(a_center1[2]));
3340 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center2),
3341 "PolygonPrismSDF: the second center must be finite (%g, %g, %g)",
3342 double(a_center2[0]),
3343 double(a_center2[1]),
3344 double(a_center2[2]));
3345 EBGEOMETRY_REQUIRE((a_center2 - a_center1).length() > T(0),
3346 "PolygonPrismSDF: the two centers must differ, but both are (%g, %g, %g)",
3347 double(a_center1[0]),
3348 double(a_center1[1]),
3349 double(a_center1[2]));
3350 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
3351 "PolygonPrismSDF: the radius must be finite and positive (%g)",
3352 double(a_radius));
3353 EBGEOMETRY_REQUIRE(a_sides >= 3U, "PolygonPrismSDF: the number of sides must be at least 3 (%u)", a_sides);
3354
3355 const T length = (a_center2 - a_center1).length();
3356 const Vec3T<T> axis = (a_center2 - a_center1) / length;
3357 const Vec3T<T> across = a_vertexDirection - dot(a_vertexDirection, axis) * axis;
3358
3359 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_vertexDirection) && across.length() > T(0),
3360 "PolygonPrismSDF: the vertex direction (%g, %g, %g) must have a part across the axis",
3361 double(a_vertexDirection[0]),
3362 double(a_vertexDirection[1]),
3363 double(a_vertexDirection[2]));
3364
3365 m_center1 = a_center1;
3366 m_center2 = a_center2;
3367 m_axis = axis;
3368 m_length = length;
3369 m_radius = a_radius;
3370 m_sides = a_sides;
3371 m_vertex = across / across.length();
3373 }
3374
3379
3384
3390 operator=(const PolygonPrismSDF&) = default;
3391
3398
3403 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3404 const Vec3T<T>&
3405 getCenter1() const noexcept
3406 {
3407 return m_center1;
3408 }
3409
3414 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3415 const Vec3T<T>&
3416 getCenter2() const noexcept
3417 {
3418 return m_center2;
3419 }
3420
3425 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3426 const T&
3427 getRadius() const noexcept
3428 {
3429 return m_radius;
3430 }
3431
3436 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3437 unsigned
3438 getSides() const noexcept
3439 {
3440 return m_sides;
3441 }
3442
3447 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3448 const Vec3T<T>&
3449 getVertexDirection() const noexcept
3450 {
3451 return m_vertex;
3452 }
3453
3464 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3466 T
3467 polygonDistance(const T a_u, const T a_v) const noexcept
3468 {
3469 const T half = pi<T> / T(m_sides);
3470
3471 // The angle from the first vertex, turned into [-half, half) around the middle of the first edge.
3472 const T angle = std::atan2(a_v, a_u);
3473 const T turn = angle - T(2) * half * std::floor(angle / (T(2) * half)) - half;
3474 const T r = std::sqrt(a_u * a_u + a_v * a_v);
3475
3476 // The point in the first sector: x toward the edge's middle, y along the edge.
3477 const T x = r * std::cos(turn) - m_radius * std::cos(half);
3478 T y = r * std::abs(std::sin(turn)) - m_radius * std::sin(half);
3479
3480 y += Math::clamp(-y, T(0), m_radius * std::sin(half));
3481
3482 const T length = std::sqrt(x * x + y * y);
3483
3484 return (x < T(0)) ? -length : length;
3485 }
3486
3492 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3493 T
3494 signedDistance(const Vec3T<T>& a_point) const noexcept
3495 {
3496 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
3497 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
3498 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
3499
3500 const Vec3T<T> w = a_point - m_center1;
3501 const T y = dot(w, m_axis);
3502
3503 return AnalyticDetail::extrusion(polygonDistance(dot(w, m_vertex), dot(w, m_side)),
3504 std::abs(y - T(0.5) * m_length) - T(0.5) * m_length);
3505 }
3506
3511 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3512 uint32_t
3513 getNumParts() const noexcept
3514 {
3515 return m_sides + 2U;
3516 }
3517
3523 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3524 uint32_t
3525 closestPart(const Vec3T<T>& a_point) const noexcept
3526 {
3527 const Vec3T<T> w = a_point - m_center1;
3528 const T y = dot(w, m_axis);
3529 const T u = dot(w, m_vertex);
3530 const T v = dot(w, m_side);
3531
3532 const T profile = this->polygonDistance(u, v);
3533 const T slab = std::abs(y - T(0.5) * m_length) - T(0.5) * m_length;
3534
3535 if (profile >= slab) {
3536 const T sector = T(2) * pi<T> / T(m_sides);
3537 T angle = std::atan2(v, u);
3538
3539 if (angle < T(0)) {
3540 angle += T(2) * pi<T>;
3541 }
3542
3543 return Math::min(uint32_t(angle / sector), m_sides - 1U);
3544 }
3545
3546 return (y < T(0.5) * m_length) ? m_sides : m_sides + 1U;
3547 }
3548
3555 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3557 computeBoundingVolume() const noexcept
3558 {
3559 Vec3T<T> reach;
3560
3561 for (size_t dir = 0; dir < 3; dir++) {
3562 reach[dir] = m_radius * std::sqrt(Math::max(T(0), T(1) - m_axis[dir] * m_axis[dir]));
3563 }
3564
3566 }
3567
3568protected:
3572 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
3573
3577 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
3578
3582 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
3583
3587 Vec3T<T> m_vertex = Vec3T<T>(T(1), T(0), T(0));
3588
3592 Vec3T<T> m_side = Vec3T<T>(T(0), T(0), T(-1));
3593
3597 T m_length = T(1);
3598
3602 T m_radius = T(1);
3603
3607 unsigned m_sides = 6U;
3608};
3609
3618template <class T>
3620{
3621 static_assert(std::is_floating_point_v<T>, "TubeSDF<T>: T must be a floating-point type");
3622
3623public:
3628
3633 TubeSDF() = default;
3634
3642 TubeSDF(const Vec3T<T>& a_center1, const Vec3T<T>& a_center2, const T a_innerRadius, const T a_outerRadius)
3643 {
3644 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center1),
3645 "TubeSDF: the first center must be finite (%g, %g, %g)",
3646 double(a_center1[0]),
3647 double(a_center1[1]),
3648 double(a_center1[2]));
3649 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center2),
3650 "TubeSDF: the second center must be finite (%g, %g, %g)",
3651 double(a_center2[0]),
3652 double(a_center2[1]),
3653 double(a_center2[2]));
3654 EBGEOMETRY_REQUIRE((a_center2 - a_center1).length() > T(0),
3655 "TubeSDF: the two centers must differ, but both are (%g, %g, %g)",
3656 double(a_center1[0]),
3657 double(a_center1[1]),
3658 double(a_center1[2]));
3659 EBGEOMETRY_REQUIRE(std::isfinite(a_outerRadius) && a_innerRadius > T(0) && a_innerRadius < a_outerRadius,
3660 "TubeSDF: the radii must satisfy 0 < inner (%g) < outer (%g)",
3661 double(a_innerRadius),
3662 double(a_outerRadius));
3663
3664 m_center1 = a_center1;
3665 m_center2 = a_center2;
3666 m_innerRadius = a_innerRadius;
3667 m_outerRadius = a_outerRadius;
3668 m_length = (a_center2 - a_center1).length();
3669 m_axis = (a_center2 - a_center1) / m_length;
3670 }
3671
3675 TubeSDF(const TubeSDF&) = default;
3676
3680 TubeSDF(TubeSDF&&) = default;
3681
3686 TubeSDF&
3687 operator=(const TubeSDF&) = default;
3688
3693 TubeSDF&
3694 operator=(TubeSDF&&) = default;
3695
3700 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3701 const Vec3T<T>&
3702 getCenter1() const noexcept
3703 {
3704 return m_center1;
3705 }
3706
3711 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3712 const Vec3T<T>&
3713 getCenter2() const noexcept
3714 {
3715 return m_center2;
3716 }
3717
3722 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3723 const T&
3724 getInnerRadius() const noexcept
3725 {
3726 return m_innerRadius;
3727 }
3728
3733 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3734 const T&
3735 getOuterRadius() const noexcept
3736 {
3737 return m_outerRadius;
3738 }
3739
3745 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3746 T
3747 signedDistance(const Vec3T<T>& a_point) const noexcept
3748 {
3749 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
3750 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
3751 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
3752
3753 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
3754
3755 const T annulus =
3756 std::abs(q.m_radial - T(0.5) * (m_innerRadius + m_outerRadius)) - T(0.5) * (m_outerRadius - m_innerRadius);
3757
3758 return AnalyticDetail::extrusion(annulus, std::abs(q.m_axial - T(0.5) * m_length) - T(0.5) * m_length);
3759 }
3760
3765 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3766 uint32_t
3767 getNumParts() const noexcept
3768 {
3769 return 4U;
3770 }
3771
3777 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3778 uint32_t
3779 closestPart(const Vec3T<T>& a_point) const noexcept
3780 {
3781 const AnalyticDetail::AxialCoordinates<T> q = AnalyticDetail::axialCoordinates(a_point, m_center1, m_axis);
3782
3783 const T middle = T(0.5) * (m_innerRadius + m_outerRadius);
3784 const T annulus = std::abs(q.m_radial - middle) - T(0.5) * (m_outerRadius - m_innerRadius);
3785 const T slab = std::abs(q.m_axial - T(0.5) * m_length) - T(0.5) * m_length;
3786
3787 if (annulus >= slab) {
3788 return (q.m_radial >= middle) ? 0U : 1U;
3789 }
3790
3791 return (q.m_axial < T(0.5) * m_length) ? 2U : 3U;
3792 }
3793
3798 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3800 computeBoundingVolume() const noexcept
3801 {
3802 Vec3T<T> reach;
3803
3804 for (size_t dir = 0; dir < 3; dir++) {
3805 reach[dir] = m_outerRadius * std::sqrt(Math::max(T(0), T(1) - m_axis[dir] * m_axis[dir]));
3806 }
3807
3809 }
3810
3811protected:
3815 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-0.5), T(0));
3816
3820 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(0.5), T(0));
3821
3825 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
3826
3830 T m_length = T(1);
3831
3835 T m_innerRadius = T(0.5);
3836
3841};
3842
3854template <class T>
3856{
3857 static_assert(std::is_floating_point_v<T>, "CappedTorusSDF<T>: T must be a floating-point type");
3858
3859public:
3864
3869 CappedTorusSDF() = default;
3870
3878 CappedTorusSDF(const Vec3T<T>& a_center, const T a_majorRadius, const T a_minorRadius, const T a_angle)
3879 {
3880 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
3881 "CappedTorusSDF: the center must be finite (%g, %g, %g)",
3882 double(a_center[0]),
3883 double(a_center[1]),
3884 double(a_center[2]));
3885 EBGEOMETRY_REQUIRE(std::isfinite(a_majorRadius) && a_minorRadius > T(0) && a_minorRadius < a_majorRadius,
3886 "CappedTorusSDF: the radii must satisfy 0 < minor (%g) < major (%g)",
3887 double(a_minorRadius),
3888 double(a_majorRadius));
3889 EBGEOMETRY_REQUIRE(a_angle > T(0) && a_angle <= T(360),
3890 "CappedTorusSDF: the angle must be in (0, 360] degrees (%g)",
3891 double(a_angle));
3892
3893 m_center = a_center;
3894 m_majorRadius = a_majorRadius;
3895 m_minorRadius = a_minorRadius;
3896 m_angle = a_angle;
3897 m_whole = !(a_angle < T(360));
3898 m_cos = std::cos(T(0.5) * a_angle * pi<T> / T(180));
3899 m_sin = std::sin(T(0.5) * a_angle * pi<T> / T(180));
3900 }
3901
3906
3911
3917 operator=(const CappedTorusSDF&) = default;
3918
3925
3930 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3931 const Vec3T<T>&
3932 getCenter() const noexcept
3933 {
3934 return m_center;
3935 }
3936
3941 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3942 const T&
3943 getMajorRadius() const noexcept
3944 {
3945 return m_majorRadius;
3946 }
3947
3952 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3953 const T&
3954 getMinorRadius() const noexcept
3955 {
3956 return m_minorRadius;
3957 }
3958
3963 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3964 const T&
3965 getAngle() const noexcept
3966 {
3967 return m_angle;
3968 }
3969
3975 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
3976 T
3977 signedDistance(const Vec3T<T>& a_point) const noexcept
3978 {
3979 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
3980 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
3981 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
3982
3983 const Vec3T<T> p = a_point - m_center;
3984 const T rho = std::sqrt(p[0] * p[0] + p[2] * p[2]);
3985
3986 // The distance to the whole torus.
3987 const T torus = std::sqrt((rho - m_majorRadius) * (rho - m_majorRadius) + p[1] * p[1]) - m_minorRadius;
3988
3989 if (m_whole) {
3990 return torus;
3991 }
3992
3993 // The distance to the end disc in the half-plane at angle a_sin, a_cos from +x: the part across the
3994 // half-plane, and in it, how far beyond the disc's rim the point lies.
3995 const auto disc = [&p, this](const T a_sin) noexcept {
3996 const T across = p[2] * m_cos - p[0] * a_sin;
3997 const T radial = p[0] * m_cos + p[2] * a_sin;
3998 const T rim =
3999 Math::max(T(0), std::sqrt((radial - m_majorRadius) * (radial - m_majorRadius) + p[1] * p[1]) - m_minorRadius);
4000
4001 return std::sqrt(across * across + rim * rim);
4002 };
4003
4004 const T ends = Math::min(disc(m_sin), disc(-m_sin));
4005
4006 // Inside the arc's angle: cos(angle to the point) >= cos(half the arc).
4007 if (p[0] >= rho * m_cos) {
4008 return (torus >= T(0)) ? torus : -Math::min(-torus, ends);
4009 }
4010
4011 return ends;
4012 }
4013
4018 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4019 uint32_t
4020 getNumParts() const noexcept
4021 {
4022 return 3U;
4023 }
4024
4030 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4031 uint32_t
4032 closestPart(const Vec3T<T>& a_point) const noexcept
4033 {
4034 if (m_whole) {
4035 return 0U;
4036 }
4037
4038 const Vec3T<T> p = a_point - m_center;
4039 const T rho = std::sqrt(p[0] * p[0] + p[2] * p[2]);
4040 const T torus = std::sqrt((rho - m_majorRadius) * (rho - m_majorRadius) + p[1] * p[1]) - m_minorRadius;
4041
4042 const auto disc = [&p, this](const T a_sin) noexcept {
4043 const T across = p[2] * m_cos - p[0] * a_sin;
4044 const T radial = p[0] * m_cos + p[2] * a_sin;
4045 const T rim =
4046 Math::max(T(0), std::sqrt((radial - m_majorRadius) * (radial - m_majorRadius) + p[1] * p[1]) - m_minorRadius);
4047
4048 return std::sqrt(across * across + rim * rim);
4049 };
4050
4051 const T positive = disc(m_sin);
4052 const T negative = disc(-m_sin);
4053 const uint32_t end = (positive <= negative) ? 1U : 2U;
4054
4055 if (p[0] >= rho * m_cos) {
4056 return (torus >= T(0) || -torus <= Math::min(positive, negative)) ? 0U : end;
4057 }
4058
4059 return end;
4060 }
4061
4068 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4070 computeBoundingVolume() const noexcept
4071 {
4072 const T outer = m_majorRadius + m_minorRadius;
4073 const T inner = m_majorRadius - m_minorRadius;
4074
4075 // The arc reaches angle 180 (-x) only when whole; it reaches +-90 (z) when it sweeps at least 180.
4076 const T xLow = m_whole ? -outer : ((m_cos >= T(0)) ? inner : outer) * m_cos;
4077 const T zHigh = (m_cos <= T(0)) ? outer : outer * m_sin;
4078
4080 m_center + Vec3T<T>(outer, m_minorRadius, zHigh));
4081 }
4082
4083protected:
4088
4093
4097 T m_minorRadius = T(0.25);
4098
4102 T m_angle = T(90);
4103
4107 T m_cos = T(0.70710678118654752);
4108
4112 T m_sin = T(0.70710678118654752);
4113
4117 bool m_whole = false;
4118};
4119
4129template <class T>
4131{
4132 static_assert(std::is_floating_point_v<T>, "CutSphereSDF<T>: T must be a floating-point type");
4133
4134public:
4139
4143 CutSphereSDF() = default;
4144
4151 CutSphereSDF(const Vec3T<T>& a_center, const T a_radius, const T a_height)
4152 {
4153 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
4154 "CutSphereSDF: the center must be finite (%g, %g, %g)",
4155 double(a_center[0]),
4156 double(a_center[1]),
4157 double(a_center[2]));
4158 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
4159 "CutSphereSDF: the radius must be finite and positive (%g)",
4160 double(a_radius));
4161 EBGEOMETRY_REQUIRE(std::abs(a_height) < a_radius,
4162 "CutSphereSDF: the height (%g) must be between minus and plus the radius (%g)",
4163 double(a_height),
4164 double(a_radius));
4165
4166 m_center = a_center;
4167 m_radius = a_radius;
4168 m_height = a_height;
4169 m_rim = std::sqrt(a_radius * a_radius - a_height * a_height);
4170 }
4171
4175 CutSphereSDF(const CutSphereSDF&) = default;
4176
4181
4187 operator=(const CutSphereSDF&) = default;
4188
4195
4200 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4201 const Vec3T<T>&
4202 getCenter() const noexcept
4203 {
4204 return m_center;
4205 }
4206
4211 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4212 const T&
4213 getRadius() const noexcept
4214 {
4215 return m_radius;
4216 }
4217
4222 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4223 const T&
4224 getHeight() const noexcept
4225 {
4226 return m_height;
4227 }
4228
4234 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4235 T
4236 signedDistance(const Vec3T<T>& a_point) const noexcept
4237 {
4238 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
4239 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
4240 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
4241
4242 const Vec3T<T> p = a_point - m_center;
4243 const T x = std::sqrt(p[0] * p[0] + p[2] * p[2]);
4244 const T y = p[1];
4245 const T r = m_radius;
4246 const T h = m_height;
4247 const T w = m_rim;
4248
4249 // s < 0 where the nearest point is on the sphere; otherwise on the flat face (x < w) or the rim.
4250 const T s = Math::max((h - r) * x * x + w * w * (h + r - T(2) * y), h * x - w * y);
4251
4252 if (s < T(0)) {
4253 return std::sqrt(x * x + y * y) - r;
4254 }
4255 if (x < w) {
4256 return h - y;
4257 }
4258
4259 return std::sqrt((x - w) * (x - w) + (y - h) * (y - h));
4260 }
4261
4266 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4267 uint32_t
4268 getNumParts() const noexcept
4269 {
4270 return 2U;
4271 }
4272
4278 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4279 uint32_t
4280 closestPart(const Vec3T<T>& a_point) const noexcept
4281 {
4282 const Vec3T<T> p = a_point - m_center;
4283 const T x = std::sqrt(p[0] * p[0] + p[2] * p[2]);
4284 const T y = p[1];
4285
4286 const T s = Math::max((m_height - m_radius) * x * x + m_rim * m_rim * (m_height + m_radius - T(2) * y),
4287 m_height * x - m_rim * y);
4288
4289 return (s < T(0)) ? 0U : 1U;
4290 }
4291
4296 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4298 computeBoundingVolume() const noexcept
4299 {
4300 const T across = (m_height <= T(0)) ? m_radius : m_rim;
4301
4302 return BoundingVolumes::AABBT<T>(m_center + Vec3T<T>(-across, m_height, -across),
4303 m_center + Vec3T<T>(across, m_radius, across));
4304 }
4305
4306protected:
4311
4315 T m_radius = T(1);
4316
4320 T m_height = T(0);
4321
4325 T m_rim = T(1);
4326};
4327
4339template <class T>
4341{
4342 static_assert(std::is_floating_point_v<T>, "CutHollowSphereSDF<T>: T must be a floating-point type");
4343
4344public:
4349
4355
4363 CutHollowSphereSDF(const Vec3T<T>& a_center, const T a_radius, const T a_height, const T a_thickness)
4364 {
4365 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
4366 "CutHollowSphereSDF: the center must be finite (%g, %g, %g)",
4367 double(a_center[0]),
4368 double(a_center[1]),
4369 double(a_center[2]));
4370 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
4371 "CutHollowSphereSDF: the radius must be finite and positive (%g)",
4372 double(a_radius));
4373 EBGEOMETRY_REQUIRE(std::abs(a_height) < a_radius,
4374 "CutHollowSphereSDF: the height (%g) must be between minus and plus the radius (%g)",
4375 double(a_height),
4376 double(a_radius));
4377 EBGEOMETRY_REQUIRE(a_thickness > T(0) && a_thickness < T(2) * a_radius,
4378 "CutHollowSphereSDF: the thickness (%g) must be positive and less than twice the radius (%g)",
4379 double(a_thickness),
4380 double(a_radius));
4381
4382 m_center = a_center;
4383 m_radius = a_radius;
4384 m_height = a_height;
4385 m_thickness = a_thickness;
4386 m_rim = std::sqrt(a_radius * a_radius - a_height * a_height);
4387 }
4388
4393
4398
4405
4412
4417 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4418 const Vec3T<T>&
4419 getCenter() const noexcept
4420 {
4421 return m_center;
4422 }
4423
4428 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4429 const T&
4430 getRadius() const noexcept
4431 {
4432 return m_radius;
4433 }
4434
4439 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4440 const T&
4441 getHeight() const noexcept
4442 {
4443 return m_height;
4444 }
4445
4450 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4451 const T&
4452 getThickness() const noexcept
4453 {
4454 return m_thickness;
4455 }
4456
4462 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4463 T
4464 signedDistance(const Vec3T<T>& a_point) const noexcept
4465 {
4466 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
4467 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
4468 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
4469
4470 const Vec3T<T> p = a_point - m_center;
4471 const T x = std::sqrt(p[0] * p[0] + p[2] * p[2]);
4472 const T y = p[1];
4473
4474 // Below the cone through the rim, the nearest point of the arc is the rim; above it, on the sphere.
4475 const T arc = (m_rim * y < m_height * x) ? std::sqrt((x - m_rim) * (x - m_rim) + (y - m_height) * (y - m_height))
4476 : std::abs(std::sqrt(x * x + y * y) - m_radius);
4477
4478 return arc - T(0.5) * m_thickness;
4479 }
4480
4485 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4486 uint32_t
4487 getNumParts() const noexcept
4488 {
4489 return 2U;
4490 }
4491
4497 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4498 uint32_t
4499 closestPart(const Vec3T<T>& a_point) const noexcept
4500 {
4501 const Vec3T<T> p = a_point - m_center;
4502 const T x = std::sqrt(p[0] * p[0] + p[2] * p[2]);
4503
4504 return (m_rim * p[1] < m_height * x) ? 1U : 0U;
4505 }
4506
4511 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4513 computeBoundingVolume() const noexcept
4514 {
4515 const T half = T(0.5) * m_thickness;
4516 const T across = ((m_height <= T(0)) ? m_radius : m_rim) + half;
4517
4518 return BoundingVolumes::AABBT<T>(m_center + Vec3T<T>(-across, m_height - half, -across),
4519 m_center + Vec3T<T>(across, m_radius + half, across));
4520 }
4521
4522protected:
4527
4531 T m_radius = T(1);
4532
4536 T m_height = T(0);
4537
4541 T m_thickness = T(0.1);
4542
4546 T m_rim = T(1);
4547};
4548
4558template <class T>
4560{
4561 static_assert(std::is_floating_point_v<T>, "WedgeSDF<T>: T must be a floating-point type");
4562
4563public:
4568
4572 WedgeSDF() = default;
4573
4579 WedgeSDF(const Vec3T<T>& a_tip, const T a_angle)
4580 {
4581 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_tip),
4582 "WedgeSDF: the tip must be finite (%g, %g, %g)",
4583 double(a_tip[0]),
4584 double(a_tip[1]),
4585 double(a_tip[2]));
4587 a_angle > T(0) && a_angle < T(180), "WedgeSDF: the angle must be in (0, 180) degrees (%g)", double(a_angle));
4588
4589 m_tip = a_tip;
4590 m_angle = a_angle;
4591 m_sin = std::sin(T(0.5) * a_angle * pi<T> / T(180));
4592 m_cos = std::cos(T(0.5) * a_angle * pi<T> / T(180));
4593 }
4594
4598 WedgeSDF(const WedgeSDF&) = default;
4599
4603 WedgeSDF(WedgeSDF&&) = default;
4604
4609 WedgeSDF&
4610 operator=(const WedgeSDF&) = default;
4611
4616 WedgeSDF&
4617 operator=(WedgeSDF&&) = default;
4618
4623 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4624 const Vec3T<T>&
4625 getTip() const noexcept
4626 {
4627 return m_tip;
4628 }
4629
4634 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4635 const T&
4636 getAngle() const noexcept
4637 {
4638 return m_angle;
4639 }
4640
4645 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4646 Vec3T<T>
4647 getFaceNormal() const noexcept
4648 {
4649 return Vec3T<T>(m_cos, m_sin, T(0));
4650 }
4651
4657 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4658 T
4659 signedDistance(const Vec3T<T>& a_point) const noexcept
4660 {
4661 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
4662 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
4663 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
4664
4665 // In the cross-section, folded onto the +x face: x >= 0.
4666 const T x = std::abs(a_point[0] - m_tip[0]);
4667 const T y = a_point[1] - m_tip[1];
4668
4669 // The face's outward normal is (cos, sin), its direction away from the tip (sin, -cos).
4670 const T plane = m_cos * x + m_sin * y;
4671 const T along = m_sin * x - m_cos * y;
4672
4673 if (plane <= T(0) || along >= T(0)) {
4674 return plane;
4675 }
4676
4677 return std::sqrt(x * x + y * y);
4678 }
4679
4684 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4685 uint32_t
4686 getNumParts() const noexcept
4687 {
4688 return 2U;
4689 }
4690
4696 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4697 uint32_t
4698 closestPart(const Vec3T<T>& a_point) const noexcept
4699 {
4700 return (a_point[0] >= m_tip[0]) ? 1U : 0U;
4701 }
4702
4707 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4709 computeBoundingVolume() const noexcept
4710 {
4711 const T big = Math::Limits<T>::max();
4712
4713 return BoundingVolumes::AABBT<T>(Vec3T<T>(-big, -big, -big), Vec3T<T>(big, m_tip[1], big));
4714 }
4715
4716protected:
4721
4725 T m_angle = T(60);
4726
4730 T m_sin = T(0.5);
4731
4735 T m_cos = T(0.86602540378443865);
4736};
4737
4755template <class T>
4757{
4758 static_assert(std::is_floating_point_v<T>, "ConvexPolyhedronSDF<T>: T must be a floating-point type");
4759
4760public:
4765
4769 static constexpr uint32_t MaxFaces = 20U;
4770
4774 static constexpr uint32_t MaxVertices = 20U;
4775
4779 static constexpr uint32_t MaxEdges = MaxFaces + MaxVertices - 2U;
4780
4785
4797 explicit ConvexPolyhedronSDF(const std::vector<PlaneSDF<T>>& a_planes);
4798
4808 [[nodiscard]] static ConvexPolyhedronSDF
4809 tetrahedron(const Vec3T<T>& a_center, T a_radius);
4810
4820 [[nodiscard]] static ConvexPolyhedronSDF
4821 octahedron(const Vec3T<T>& a_center, T a_radius);
4822
4834 [[nodiscard]] static ConvexPolyhedronSDF
4835 dodecahedron(const Vec3T<T>& a_center, T a_radius);
4836
4849 [[nodiscard]] static ConvexPolyhedronSDF
4850 icosahedron(const Vec3T<T>& a_center, T a_radius);
4851
4867 [[nodiscard]] static ConvexPolyhedronSDF
4868 pyramid(const Vec3T<T>& a_baseCenter,
4869 const Vec3T<T>& a_apex,
4870 T a_radius,
4871 unsigned a_sides,
4872 const Vec3T<T>& a_vertexDirection);
4873
4878
4883
4890
4897
4902 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4903 uint32_t
4904 getNumFaces() const noexcept
4905 {
4906 return m_numFaces;
4907 }
4908
4914 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4915 const Vec3T<T>&
4916 getNormal(const uint32_t a_face) const noexcept
4917 {
4918 EBGEOMETRY_EXPECT(a_face < m_numFaces);
4919
4920 return m_normals[a_face];
4921 }
4922
4928 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4929 const T&
4930 getOffset(const uint32_t a_face) const noexcept
4931 {
4932 EBGEOMETRY_EXPECT(a_face < m_numFaces);
4933
4934 return m_offsets[a_face];
4935 }
4936
4941 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4942 uint32_t
4943 getNumVertices() const noexcept
4944 {
4945 return m_numVertices;
4946 }
4947
4953 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4954 const Vec3T<T>&
4955 getVertex(const uint32_t a_vertex) const noexcept
4956 {
4957 EBGEOMETRY_EXPECT(a_vertex < m_numVertices);
4958
4959 return m_vertices[a_vertex];
4960 }
4961
4966 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4967 uint32_t
4968 getNumEdges() const noexcept
4969 {
4970 return m_numEdges;
4971 }
4972
4979 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4980 uint32_t
4981 getEdgeVertex(const uint32_t a_edge, const uint32_t a_end) const noexcept
4982 {
4983 EBGEOMETRY_EXPECT(a_edge < m_numEdges && a_end < 2U);
4984
4985 return m_edges[2U * a_edge + a_end];
4986 }
4987
4996 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
4998 T
4999 signedDistance(const Vec3T<T>& a_point) const noexcept;
5000
5005 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5006 uint32_t
5007 getNumParts() const noexcept
5008 {
5009 return m_numFaces;
5010 }
5011
5019 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5020 uint32_t
5021 closestPart(const Vec3T<T>& a_point) const noexcept;
5022
5027 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5029 computeBoundingVolume() const noexcept;
5030
5031protected:
5040 void
5041 build(const std::vector<Vec3T<double>>& a_points, const std::vector<Vec3T<double>>& a_normals, double a_epsilon);
5042
5047 static std::vector<PlaneSDF<T>>
5048 cubePlanes();
5049
5057 static std::vector<Vec3T<T>>
5058 goldenDirections(T a_small, T a_large);
5059
5070 static ConvexPolyhedronSDF
5071 fromNormals(const Vec3T<T>& a_center,
5072 const std::vector<Vec3T<T>>& a_vertexDirections,
5073 const std::vector<Vec3T<T>>& a_normals,
5074 T a_radius,
5075 const char* a_who);
5076
5080 uint32_t m_numFaces = 0U;
5081
5085 uint32_t m_numVertices = 0U;
5086
5090 uint32_t m_numEdges = 0U;
5091
5096
5101
5106
5110 Array<uint8_t, 2U * MaxEdges> m_edges;
5111};
5112
5123template <class T>
5125{
5126 static_assert(std::is_floating_point_v<T>, "BoxFrameSDF<T>: T must be a floating-point type");
5127
5128public:
5133
5137 BoxFrameSDF() = default;
5138
5145 BoxFrameSDF(const Vec3T<T>& a_loCorner, const Vec3T<T>& a_hiCorner, T a_thickness);
5146
5150 BoxFrameSDF(const BoxFrameSDF&) = default;
5151
5156
5162 operator=(const BoxFrameSDF&) = default;
5163
5170
5175 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5176 const Vec3T<T>&
5177 getLowCorner() const noexcept
5178 {
5179 return m_loCorner;
5180 }
5181
5186 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5187 const Vec3T<T>&
5188 getHighCorner() const noexcept
5189 {
5190 return m_hiCorner;
5191 }
5192
5197 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5198 const T&
5199 getThickness() const noexcept
5200 {
5201 return m_thickness;
5202 }
5203
5209 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5210 T
5211 signedDistance(const Vec3T<T>& a_point) const noexcept;
5212
5217 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5218 uint32_t
5219 getNumParts() const noexcept
5220 {
5221 return 12U;
5222 }
5223
5231 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5232 uint32_t
5233 closestPart(const Vec3T<T>& a_point) const noexcept;
5234
5239 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5241 computeBoundingVolume() const noexcept
5242 {
5243 return BoundingVolumes::AABBT<T>(m_loCorner, m_hiCorner);
5244 }
5245
5246protected:
5256 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
5258 Vec3T<T>
5259 barTerms(const Vec3T<T>& a_point) const noexcept;
5260
5264 Vec3T<T> m_loCorner = Vec3T<T>(T(-0.5), T(-0.5), T(-0.5));
5265
5269 Vec3T<T> m_hiCorner = Vec3T<T>(T(0.5), T(0.5), T(0.5));
5270
5274 T m_thickness = T(0.1);
5275};
5276
5277namespace AnalyticDetail {
5278
5284{
5288 std::vector<Vec3T<double>> m_vertices;
5289
5293 std::vector<std::pair<uint32_t, uint32_t>> m_edges;
5294};
5295
5312inline PolyhedronTopology
5313polyhedronTopology(const std::vector<Vec3T<double>>& a_normals,
5314 const std::vector<double>& a_offsets,
5315 const double a_epsilon,
5316 const double a_magnitude,
5317 const char* a_who)
5318{
5319 const size_t numPlanes = a_normals.size();
5320
5321 double scale = 0.0;
5322
5323 for (const double h : a_offsets) {
5324 scale = Math::max(scale, std::abs(h));
5325 }
5326
5327 // The planes are rounded to the shape's precision, so where more than three meet, their crossings scatter by a
5328 // few of its units in the last place, amplified by how obliquely they meet.
5329 const double tol = 256.0 * a_epsilon * Math::max(scale + a_magnitude, 1.E-300);
5330
5331 PolyhedronTopology topology;
5332
5333 for (size_t i = 0; i < numPlanes; i++) {
5334 for (size_t j = i + 1; j < numPlanes; j++) {
5335 for (size_t k = j + 1; k < numPlanes; k++) {
5336 const Vec3T<double>& a = a_normals[i];
5337 const Vec3T<double>& b = a_normals[j];
5338 const Vec3T<double>& c = a_normals[k];
5339
5340 const Vec3T<double> bc = cross(b, c);
5341 const double det = dot(a, bc);
5342
5343 if (std::abs(det) < 1.E-12) {
5344 continue;
5345 }
5346
5347 // Cramer's rule for dot(a, x) = ha, dot(b, x) = hb, dot(c, x) = hc.
5348 const Vec3T<double> x = (a_offsets[i] * bc + a_offsets[j] * cross(c, a) + a_offsets[k] * cross(a, b)) / det;
5349
5350 bool behind = true;
5351
5352 for (size_t m = 0; m < numPlanes && behind; m++) {
5353 behind = dot(a_normals[m], x) - a_offsets[m] <= tol;
5354 }
5355
5356 if (!behind) {
5357 continue;
5358 }
5359
5360 bool known = false;
5361
5362 for (const Vec3T<double>& v : topology.m_vertices) {
5363 known = known || (v - x).length() <= 10.0 * tol;
5364 }
5365
5366 if (!known) {
5367 topology.m_vertices.push_back(x);
5368 }
5369 }
5370 }
5371 }
5372
5373 const size_t numVertices = topology.m_vertices.size();
5374
5375 // The planes each vertex is on.
5376 std::vector<std::vector<bool>> on(numVertices, std::vector<bool>(numPlanes, false));
5377
5378 for (size_t v = 0; v < numVertices; v++) {
5379 for (size_t m = 0; m < numPlanes; m++) {
5380 on[v][m] = std::abs(dot(a_normals[m], topology.m_vertices[v]) - a_offsets[m]) <= 10.0 * tol;
5381 }
5382 }
5383
5384 for (size_t m = 0; m < numPlanes; m++) {
5385 size_t count = 0;
5386
5387 for (size_t v = 0; v < numVertices; v++) {
5388 count += on[v][m] ? 1U : 0U;
5389 }
5390
5392 count >= 3U, "%s: plane %zu does not bound a face of the solid, or the solid is not finite", a_who, m);
5393 }
5394
5395 for (size_t v = 0; v < numVertices; v++) {
5396 for (size_t w = v + 1; w < numVertices; w++) {
5397 size_t shared = 0;
5398
5399 for (size_t m = 0; m < numPlanes; m++) {
5400 shared += (on[v][m] && on[w][m]) ? 1U : 0U;
5401 }
5402
5403 if (shared >= 2U) {
5404 topology.m_edges.emplace_back(uint32_t(v), uint32_t(w));
5405 }
5406 }
5407 }
5408
5409 EBGEOMETRY_REQUIRE(numVertices + numPlanes == topology.m_edges.size() + 2U,
5410 "%s: the planes do not bound a finite solid with a volume (%zu vertices, %zu edges, %zu faces)",
5411 a_who,
5412 numVertices,
5413 topology.m_edges.size(),
5414 numPlanes);
5415
5416 return topology;
5417}
5418
5419} // namespace AnalyticDetail
5420
5421template <class T>
5422inline std::vector<PlaneSDF<T>>
5424{
5425 std::vector<PlaneSDF<T>> planes;
5426
5427 for (size_t dir = 0; dir < 3; dir++) {
5428 for (const T side : {T(-1), T(1)}) {
5430
5431 normal[dir] = side;
5432
5433 planes.emplace_back(T(0.5) * normal, normal);
5434 }
5435 }
5436
5437 return planes;
5438}
5439
5440template <class T>
5443
5444template <class T>
5446{
5447 std::vector<Vec3T<double>> points;
5448 std::vector<Vec3T<double>> normals;
5449
5450 for (const PlaneSDF<T>& plane : a_planes) {
5451 points.emplace_back(double(plane.getPoint()[0]), double(plane.getPoint()[1]), double(plane.getPoint()[2]));
5452 normals.emplace_back(double(plane.getNormal()[0]), double(plane.getNormal()[1]), double(plane.getNormal()[2]));
5453 }
5454
5455 this->build(points, normals, double(Math::Limits<T>::epsilon()));
5456}
5457
5458template <class T>
5459inline void
5461 const std::vector<Vec3T<double>>& a_normals,
5462 const double a_epsilon)
5463{
5464 EBGEOMETRY_REQUIRE(a_points.size() >= 4U && a_points.size() <= MaxFaces,
5465 "ConvexPolyhedronSDF: a polyhedron has from 4 to %u planes (%zu)",
5466 unsigned(MaxFaces),
5467 a_points.size());
5468
5469 // The planes are taken relative to the mean of their points, so that the tolerance for where planes meet scales
5470 // with the solid's size, plus the rounding of the coordinates it was given in. A small solid far from the origin is
5471 // then judged by its own size where its planes are exact (the regular solids and pyramids, built in double); one
5472 // whose planes were rounded to float far from the origin may be rejected, and is better built near the origin and
5473 // moved with Translate.
5474 Vec3T<double> reference = Vec3T<double>::zeros();
5475
5476 for (const Vec3T<double>& point : a_points) {
5477 reference += point;
5478 }
5479
5480 reference = reference / double(a_points.size());
5481
5482 std::vector<Vec3T<double>> normals;
5483 std::vector<double> offsets;
5484
5485 for (size_t k = 0; k < a_points.size(); k++) {
5486 const Vec3T<double>& point = a_points[k];
5487 const Vec3T<double>& normal = a_normals[k];
5488
5489 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(point) && AnalyticDetail::isFinite(normal) && normal.length() > 0.0,
5490 "ConvexPolyhedronSDF: plane %zu must have a finite point and a finite, nonzero normal",
5491 k);
5492
5493 normals.push_back(normal / normal.length());
5494 offsets.push_back(dot(normals.back(), point - reference));
5495 }
5496
5497 const AnalyticDetail::PolyhedronTopology topology = AnalyticDetail::polyhedronTopology(
5498 normals,
5499 offsets,
5500 a_epsilon,
5501 Math::max(std::abs(reference[0]), Math::max(std::abs(reference[1]), std::abs(reference[2]))),
5502 "ConvexPolyhedronSDF");
5503
5504 EBGEOMETRY_REQUIRE(topology.m_vertices.size() <= MaxVertices,
5505 "ConvexPolyhedronSDF: a polyhedron has at most %u vertices (%zu)",
5506 unsigned(MaxVertices),
5507 topology.m_vertices.size());
5508
5509 m_numFaces = uint32_t(normals.size());
5510 m_numVertices = uint32_t(topology.m_vertices.size());
5511 m_numEdges = uint32_t(topology.m_edges.size());
5512
5513 for (uint32_t f = 0; f < m_numFaces; f++) {
5514 m_normals[f] = Vec3T<T>(T(normals[f][0]), T(normals[f][1]), T(normals[f][2]));
5515 m_offsets[f] = T(offsets[f] + dot(normals[f], reference));
5516 }
5517
5518 for (uint32_t v = 0; v < m_numVertices; v++) {
5519 const Vec3T<double> x = topology.m_vertices[v] + reference;
5520
5521 m_vertices[v] = Vec3T<T>(T(x[0]), T(x[1]), T(x[2]));
5522 }
5523
5524 for (uint32_t e = 0; e < m_numEdges; e++) {
5525 m_edges[2U * e] = uint8_t(topology.m_edges[e].first);
5526 m_edges[2U * e + 1U] = uint8_t(topology.m_edges[e].second);
5527 }
5528}
5529
5530template <class T>
5533 const std::vector<Vec3T<T>>& a_vertexDirections,
5534 const std::vector<Vec3T<T>>& a_normals,
5535 const T a_radius,
5536 const char* a_who)
5537{
5538 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
5539 "%s: the center must be finite (%g, %g, %g)",
5540 a_who,
5541 double(a_center[0]),
5542 double(a_center[1]),
5543 double(a_center[2]));
5544 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
5545 "%s: the radius must be finite and positive (%g)",
5546 a_who,
5547 double(a_radius));
5548
5549 // Each face's plane is at the largest height of a vertex along its normal (the vertices lie on a sphere of the
5550 // circumradius), all in double: a float solid then has its planes rounded once, at the end, as its vertices are.
5551 const Vec3T<double> center = Vec3T<double>(double(a_center[0]), double(a_center[1]), double(a_center[2]));
5552
5553 const auto unit = [](const Vec3T<T>& a_v) {
5554 const Vec3T<double> v = Vec3T<double>(double(a_v[0]), double(a_v[1]), double(a_v[2]));
5555
5556 return v / v.length();
5557 };
5558
5559 std::vector<Vec3T<double>> points;
5560 std::vector<Vec3T<double>> normals;
5561
5562 for (const Vec3T<T>& n : a_normals) {
5563 const Vec3T<double> normal = unit(n);
5564
5565 double height = -1.0;
5566
5567 for (const Vec3T<T>& d : a_vertexDirections) {
5568 height = Math::max(height, dot(normal, unit(d)));
5569 }
5570
5571 points.push_back(center + height * double(a_radius) * normal);
5572 normals.push_back(normal);
5573 }
5574
5576
5577 solid.build(points, normals, Math::Limits<double>::epsilon());
5578
5579 return solid;
5580}
5581
5582template <class T>
5584ConvexPolyhedronSDF<T>::tetrahedron(const Vec3T<T>& a_center, const T a_radius)
5585{
5586 const std::vector<Vec3T<T>> vertices{Vec3T<T>(T(1), T(1), T(1)),
5587 Vec3T<T>(T(1), T(-1), T(-1)),
5588 Vec3T<T>(T(-1), T(1), T(-1)),
5589 Vec3T<T>(T(-1), T(-1), T(1))};
5590
5591 std::vector<Vec3T<T>> normals;
5592
5593 for (const Vec3T<T>& v : vertices) {
5594 normals.push_back(-v);
5595 }
5596
5597 return fromNormals(a_center, vertices, normals, a_radius, "ConvexPolyhedronSDF::tetrahedron");
5598}
5599
5600template <class T>
5602ConvexPolyhedronSDF<T>::octahedron(const Vec3T<T>& a_center, const T a_radius)
5603{
5604 std::vector<Vec3T<T>> vertices;
5605 std::vector<Vec3T<T>> normals;
5606
5607 for (size_t dir = 0; dir < 3; dir++) {
5608 vertices.push_back(Vec3T<T>::unit(dir));
5609 vertices.push_back(-Vec3T<T>::unit(dir));
5610 }
5611
5612 for (uint32_t f = 0; f < 8U; f++) {
5613 normals.emplace_back((f & 4U) ? T(-1) : T(1), (f & 2U) ? T(-1) : T(1), (f & 1U) ? T(-1) : T(1));
5614 }
5615
5616 return fromNormals(a_center, vertices, normals, a_radius, "ConvexPolyhedronSDF::octahedron");
5617}
5618
5619template <class T>
5620inline std::vector<Vec3T<T>>
5621ConvexPolyhedronSDF<T>::goldenDirections(const T a_small, const T a_large)
5622{
5623 std::vector<Vec3T<T>> directions;
5624
5625 for (const T s : {T(1), T(-1)}) {
5626 for (const T t : {T(1), T(-1)}) {
5627 directions.emplace_back(T(0), s * a_small, t * a_large);
5628 }
5629 }
5630
5631 for (const T s : {T(1), T(-1)}) {
5632 for (const T t : {T(1), T(-1)}) {
5633 directions.emplace_back(s * a_small, t * a_large, T(0));
5634 }
5635 }
5636
5637 for (const T s : {T(1), T(-1)}) {
5638 for (const T t : {T(1), T(-1)}) {
5639 directions.emplace_back(s * a_large, T(0), t * a_small);
5640 }
5641 }
5642
5643 return directions;
5644}
5645
5646template <class T>
5648ConvexPolyhedronSDF<T>::dodecahedron(const Vec3T<T>& a_center, const T a_radius)
5649{
5650 const T phi = (T(1) + std::sqrt(T(5))) / T(2);
5651
5652 std::vector<Vec3T<T>> vertices;
5653
5654 for (uint32_t c = 0; c < 8U; c++) {
5655 vertices.emplace_back((c & 4U) ? T(-1) : T(1), (c & 2U) ? T(-1) : T(1), (c & 1U) ? T(-1) : T(1));
5656 }
5657
5658 for (const Vec3T<T>& v : goldenDirections(T(1) / phi, phi)) {
5659 vertices.push_back(v);
5660 }
5661
5662 return fromNormals(a_center, vertices, goldenDirections(phi, T(1)), a_radius, "ConvexPolyhedronSDF::dodecahedron");
5663}
5664
5665template <class T>
5667ConvexPolyhedronSDF<T>::icosahedron(const Vec3T<T>& a_center, const T a_radius)
5668{
5669 const T phi = (T(1) + std::sqrt(T(5))) / T(2);
5670
5671 std::vector<Vec3T<T>> normals;
5672
5673 for (uint32_t c = 0; c < 8U; c++) {
5674 normals.emplace_back((c & 4U) ? T(-1) : T(1), (c & 2U) ? T(-1) : T(1), (c & 1U) ? T(-1) : T(1));
5675 }
5676
5677 for (const Vec3T<T>& n : goldenDirections(phi, T(1) / phi)) {
5678 normals.push_back(n);
5679 }
5680
5681 return fromNormals(a_center, goldenDirections(T(1), phi), normals, a_radius, "ConvexPolyhedronSDF::icosahedron");
5682}
5683
5684template <class T>
5687 const Vec3T<T>& a_apex,
5688 const T a_radius,
5689 const unsigned a_sides,
5690 const Vec3T<T>& a_vertexDirection)
5691{
5692 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_baseCenter),
5693 "ConvexPolyhedronSDF::pyramid: the base center must be finite (%g, %g, %g)",
5694 double(a_baseCenter[0]),
5695 double(a_baseCenter[1]),
5696 double(a_baseCenter[2]));
5697 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_apex),
5698 "ConvexPolyhedronSDF::pyramid: the apex must be finite (%g, %g, %g)",
5699 double(a_apex[0]),
5700 double(a_apex[1]),
5701 double(a_apex[2]));
5703 (a_apex - a_baseCenter).length() > T(0),
5704 "ConvexPolyhedronSDF::pyramid: the apex must differ from the base center, but both are (%g, %g, %g)",
5705 double(a_apex[0]),
5706 double(a_apex[1]),
5707 double(a_apex[2]));
5708 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
5709 "ConvexPolyhedronSDF::pyramid: the radius must be finite and positive (%g)",
5710 double(a_radius));
5711 EBGEOMETRY_REQUIRE(a_sides >= 3U && a_sides < MaxVertices,
5712 "ConvexPolyhedronSDF::pyramid: the number of sides must be from 3 to %u (%u)",
5713 unsigned(MaxVertices - 1U),
5714 a_sides);
5715
5716 // In double: the base vertices, then each side's plane through two of them and the apex.
5717 const auto toDouble = [](const Vec3T<T>& a_v) {
5718 return Vec3T<double>(double(a_v[0]), double(a_v[1]), double(a_v[2]));
5719 };
5720
5721 const Vec3T<double> base = toDouble(a_baseCenter);
5722 const Vec3T<double> apex = toDouble(a_apex);
5723 const Vec3T<double> axis = (apex - base) / (apex - base).length();
5724 const Vec3T<double> dir = toDouble(a_vertexDirection);
5725 const Vec3T<double> across = dir - dot(dir, axis) * axis;
5726
5727 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_vertexDirection) && across.length() > 0.0,
5728 "ConvexPolyhedronSDF::pyramid: the vertex direction (%g, %g, %g) must have a part across the axis",
5729 double(a_vertexDirection[0]),
5730 double(a_vertexDirection[1]),
5731 double(a_vertexDirection[2]));
5732
5733 const Vec3T<double> u = across / across.length();
5734 const Vec3T<double> v = cross(axis, u);
5735
5736 std::vector<Vec3T<double>> corners;
5737
5738 for (unsigned k = 0; k < a_sides; k++) {
5739 const double angle = 2.0 * pi<double> * double(k) / double(a_sides);
5740
5741 corners.push_back(base + double(a_radius) * (std::cos(angle) * u + std::sin(angle) * v));
5742 }
5743
5744 std::vector<Vec3T<double>> points;
5745 std::vector<Vec3T<double>> normals;
5746
5747 for (unsigned k = 0; k < a_sides; k++) {
5748 const Vec3T<double>& a = corners[k];
5749 const Vec3T<double>& b = corners[(k + 1U) % a_sides];
5750
5751 Vec3T<double> normal = cross(b - a, apex - a);
5752
5753 // Outward: away from the base center.
5754 if (dot(normal, a - base) < 0.0) {
5755 normal = -normal;
5756 }
5757
5758 points.push_back(a);
5759 normals.push_back(normal / normal.length());
5760 }
5761
5762 points.push_back(base);
5763 normals.push_back(-axis);
5764
5766
5767 solid.build(points, normals, Math::Limits<double>::epsilon());
5768
5769 return solid;
5770}
5771
5772template <class T>
5774inline uint32_t
5775ConvexPolyhedronSDF<T>::closestPart(const Vec3T<T>& a_point) const noexcept
5776{
5777 uint32_t face = 0U;
5778 T best = dot(m_normals[0], a_point) - m_offsets[0];
5779
5780 for (uint32_t f = 1; f < m_numFaces; f++) {
5781 const T d = dot(m_normals[f], a_point) - m_offsets[f];
5782
5783 if (d > best) {
5784 best = d;
5785 face = f;
5786 }
5787 }
5788
5789 return face;
5790}
5791
5792template <class T>
5794inline T
5796{
5797 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
5798 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
5799 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
5800
5801 const uint32_t face = this->closestPart(a_point);
5802 const T d = dot(m_normals[face], a_point) - m_offsets[face];
5803
5804 // Inside, the nearest face plane is the distance: its foot is on the face, the solid being convex.
5805 if (d <= T(0)) {
5806 return d;
5807 }
5808
5809 // Outside, the closest point is inside a face only if that face's plane is the farthest from the point, and then
5810 // it is the point's foot on that plane: the foot is the closest point when every other plane is above it.
5811 const Vec3T<T> foot = a_point - d * m_normals[face];
5812 bool inside = true;
5813
5814 for (uint32_t f = 0; f < m_numFaces; f++) {
5815 if (f != face && dot(m_normals[f], foot) - m_offsets[f] > T(0)) {
5816 inside = false;
5817 }
5818 }
5819
5820 if (inside) {
5821 return d;
5822 }
5823
5824 // Otherwise the closest point is on an edge, or at a vertex, an end of one.
5825 T squared = Math::Limits<T>::max();
5826
5827 for (uint32_t e = 0; e < m_numEdges; e++) {
5828 const Vec3T<T>& a = m_vertices[m_edges[2U * e]];
5829 const Vec3T<T> ab = m_vertices[m_edges[2U * e + 1U]] - a;
5830 const Vec3T<T> ap = a_point - a;
5831 const T s = Math::clamp(dot(ap, ab) / dot(ab, ab), T(0), T(1));
5832 const Vec3T<T> w = ap - s * ab;
5833
5834 squared = Math::min(squared, dot(w, w));
5835 }
5836
5837 return std::sqrt(squared);
5838}
5839
5840template <class T>
5844{
5845 Vec3T<T> lo = m_vertices[0];
5846 Vec3T<T> hi = m_vertices[0];
5847
5848 for (uint32_t v = 1; v < m_numVertices; v++) {
5849 lo = min(lo, m_vertices[v]);
5850 hi = max(hi, m_vertices[v]);
5851 }
5852
5853 return BoundingVolumes::AABBT<T>(lo, hi);
5854}
5855
5856template <class T>
5857inline BoxFrameSDF<T>::BoxFrameSDF(const Vec3T<T>& a_loCorner, const Vec3T<T>& a_hiCorner, const T a_thickness)
5858{
5859 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_loCorner),
5860 "BoxFrameSDF: the low corner must be finite (%g, %g, %g)",
5861 double(a_loCorner[0]),
5862 double(a_loCorner[1]),
5863 double(a_loCorner[2]));
5864 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_hiCorner),
5865 "BoxFrameSDF: the high corner must be finite (%g, %g, %g)",
5866 double(a_hiCorner[0]),
5867 double(a_hiCorner[1]),
5868 double(a_hiCorner[2]));
5870 a_loCorner[0] < a_hiCorner[0] && a_loCorner[1] < a_hiCorner[1] && a_loCorner[2] < a_hiCorner[2],
5871 "BoxFrameSDF: the low corner (%g, %g, %g) must be below the high corner (%g, %g, %g) in every direction",
5872 double(a_loCorner[0]),
5873 double(a_loCorner[1]),
5874 double(a_loCorner[2]),
5875 double(a_hiCorner[0]),
5876 double(a_hiCorner[1]),
5877 double(a_hiCorner[2]));
5878
5879 const Vec3T<T> size = a_hiCorner - a_loCorner;
5880 const T side = Math::min(size[0], Math::min(size[1], size[2]));
5881
5882 EBGEOMETRY_REQUIRE(std::isfinite(a_thickness) && a_thickness > T(0) && T(2) * a_thickness < side,
5883 "BoxFrameSDF: the thickness must be positive and less than half the shortest side %g (%g)",
5884 double(side),
5885 double(a_thickness));
5886
5887 m_loCorner = a_loCorner;
5888 m_hiCorner = a_hiCorner;
5889 m_thickness = a_thickness;
5890}
5891
5892template <class T>
5894inline Vec3T<T>
5895BoxFrameSDF<T>::barTerms(const Vec3T<T>& a_point) const noexcept
5896{
5897 const T e = T(0.5) * m_thickness;
5898 const Vec3T<T> c = T(0.5) * (m_loCorner + m_hiCorner);
5899 const Vec3T<T> b = T(0.5) * (m_hiCorner - m_loCorner);
5900
5901 // Folded into one octant: p is the signed distance to the box's faces along each axis, q that to the slab two
5902 // half-thicknesses inside them, which a bar fills across its own axis.
5903 Vec3T<T> p;
5904 Vec3T<T> q;
5905
5906 for (size_t dir = 0; dir < 3; dir++) {
5907 p[dir] = std::abs(a_point[dir] - c[dir]) - b[dir];
5908 q[dir] = std::abs(p[dir] + e) - e;
5909 }
5910
5911 // A bar along axis a: the box p_a <= 0 crossed with q <= 0 across it.
5912 const auto bar = [](const T a_x, const T a_y, const T a_z) noexcept {
5913 const T x = Math::max(a_x, T(0));
5914 const T y = Math::max(a_y, T(0));
5915 const T z = Math::max(a_z, T(0));
5916
5917 return std::sqrt(x * x + y * y + z * z) + Math::min(Math::max(a_x, Math::max(a_y, a_z)), T(0));
5918 };
5919
5920 return Vec3T<T>(bar(p[0], q[1], q[2]), bar(q[0], p[1], q[2]), bar(q[0], q[1], p[2]));
5921}
5922
5923template <class T>
5925inline T
5926BoxFrameSDF<T>::signedDistance(const Vec3T<T>& a_point) const noexcept
5927{
5928 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
5929 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
5930 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
5931
5932 const Vec3T<T> terms = this->barTerms(a_point);
5933 const T outside = Math::min(terms[0], Math::min(terms[1], terms[2]));
5934
5935 if (outside >= T(0)) {
5936 return outside;
5937 }
5938
5939 // Inside, the nearest bar's depth undercuts the distance where bars meet: the boundary is the box's outer faces,
5940 // or the openings between the bars, where two coordinates are more than a thickness inside the outer faces.
5941 const Vec3T<T> c = T(0.5) * (m_loCorner + m_hiCorner);
5942 const Vec3T<T> b = T(0.5) * (m_hiCorner - m_loCorner);
5943
5944 Vec3T<T> depth;
5945 Vec3T<T> opening;
5946
5947 for (size_t dir = 0; dir < 3; dir++) {
5948 depth[dir] = b[dir] - std::abs(a_point[dir] - c[dir]);
5949 opening[dir] = Math::max(m_thickness - depth[dir], T(0));
5950 }
5951
5952 T inside = Math::min(depth[0], Math::min(depth[1], depth[2]));
5953
5954 inside = Math::min(inside, std::sqrt(opening[0] * opening[0] + opening[1] * opening[1]));
5955 inside = Math::min(inside, std::sqrt(opening[0] * opening[0] + opening[2] * opening[2]));
5956 inside = Math::min(inside, std::sqrt(opening[1] * opening[1] + opening[2] * opening[2]));
5957
5958 return -inside;
5959}
5960
5961template <class T>
5963inline uint32_t
5964BoxFrameSDF<T>::closestPart(const Vec3T<T>& a_point) const noexcept
5965{
5966 const Vec3T<T> terms = this->barTerms(a_point);
5967 const Vec3T<T> c = T(0.5) * (m_loCorner + m_hiCorner);
5968
5969 uint32_t axis = 0U;
5970
5971 if (terms[1] < terms[axis]) {
5972 axis = 1U;
5973 }
5974 if (terms[2] < terms[axis]) {
5975 axis = 2U;
5976 }
5977
5978 const uint32_t first = (axis == 0U) ? 1U : 0U;
5979 const uint32_t second = (axis == 2U) ? 1U : 2U;
5980
5981 return 4U * axis + ((a_point[first] >= c[first]) ? 2U : 0U) + ((a_point[second] >= c[second]) ? 1U : 0U);
5982}
5983
5984namespace AnalyticDetail {
5985
6003template <class T>
6004[[nodiscard]] EBGEOMETRY_HOST_DEVICE
6006inline T
6007hyperbolaDistance(const T a_A, const T a_B, const T a_x, const T a_y) noexcept
6008{
6009 const T A2 = a_A * a_A;
6010 const T B2 = a_B * a_B;
6011 const T S = A2 + B2;
6012
6013 if (!(a_y > T(0))) {
6014 const T foot = a_x * A2 / S;
6015
6016 if (foot > a_A) {
6017 const T Y = a_B * std::sqrt(foot * foot / A2 - T(1));
6018
6019 return std::sqrt((foot - a_x) * (foot - a_x) + Y * Y);
6020 }
6021
6022 return std::abs(a_x - a_A);
6023 }
6024
6025 if (!(a_x > T(0))) {
6026 const T Y = a_y * B2 / S;
6027 const T X = a_A * std::sqrt(T(1) + Y * Y / B2);
6028
6029 return std::sqrt(X * X + (Y - a_y) * (Y - a_y));
6030 }
6031
6032 const T xA = a_x * a_A;
6033 const T yB = a_y * a_B;
6034
6035 // F is negative at u = x A (there X = A, and Y > 0) and below S, and tends to +infinity as u tends to 0, which
6036 // is the bracket's lower end until a step finds F positive. One loop does both the bracketing and the root:
6037 // where a Newton step leaves the bracket, the step bisects it, which from a lower end of 0 halves u.
6038 constexpr int MaxIterations = 160;
6039
6040 const T eps = Math::Limits<T>::epsilon();
6041
6042 T lo = T(0);
6043 T hi = Math::min(xA, S);
6044 T u = T(0.5) * hi;
6045
6046 for (int i = 0; i < MaxIterations; i++) {
6047 const T first = xA / u;
6048 const T second = yB / (S - u);
6049 const T f = first * first - second * second - T(1);
6050
6051 if (f == T(0)) {
6052 break;
6053 }
6054
6055 if (f > T(0)) {
6056 lo = u;
6057 }
6058 else {
6059 hi = u;
6060 }
6061
6062 const T df = -T(2) * first * first / u - T(2) * second * second / (S - u);
6063
6064 T next = u - f / df;
6065
6066 if (!(next > lo && next < hi)) {
6067 next = T(0.5) * (lo + hi);
6068 }
6069
6070 const bool converged = std::abs(next - u) <= T(4) * eps * u;
6071
6072 u = next;
6073
6074 if (converged) {
6075 break;
6076 }
6077 }
6078
6079 const T X = xA * a_A / u;
6080 const T Y = yB * a_B / (S - u);
6081
6082 return std::sqrt((X - a_x) * (X - a_x) + (Y - a_y) * (Y - a_y));
6083}
6084
6101template <class T>
6102[[nodiscard]] EBGEOMETRY_HOST_DEVICE
6104inline T
6105parabolaDistance(const T a_rho, const T a_r, const T a_y) noexcept
6106{
6107 constexpr int MaxIterations = 64;
6108
6109 const T P = T(2) * a_rho * (a_rho + a_y);
6110 const T Q = -T(2) * a_rho * a_rho * a_r;
6111
6112 T s = std::sqrt(Math::max(-P, T(0))) + std::cbrt(-Q);
6113
6114 for (int i = 0; i < MaxIterations; i++) {
6115 const T g = s * s * s + P * s + Q;
6116 const T slope = T(3) * s * s + P;
6117
6118 if (!(g > T(0)) || !(slope > T(0))) {
6119 break;
6120 }
6121
6122 const T next = Math::max(s - g / slope, T(0));
6123
6124 if (!(next < s)) {
6125 break;
6126 }
6127
6128 s = next;
6129 }
6130
6131 const T dr = s - a_r;
6132 const T dy = a_y + s * s / (T(2) * a_rho);
6133
6134 return std::sqrt(dr * dr + dy * dy);
6135}
6136
6146template <class T>
6147[[nodiscard]] EBGEOMETRY_HOST_DEVICE
6148inline T
6149pNorm(const T a_a, const T a_b, const T a_p) noexcept
6150{
6151 const T m = Math::max(a_a, a_b);
6152
6153 if (!(m > T(0))) {
6154 return T(0);
6155 }
6156
6157 return m * std::pow(std::pow(a_a / m, a_p) + std::pow(a_b / m, a_p), T(1) / a_p);
6158}
6159
6175template <class T>
6176[[nodiscard]] inline T
6177superellipsoidScale(const Vec3T<T>& a_radii, const T a_exponent1, const T a_exponent2) noexcept
6178{
6179 const auto factor = [](const T a_e) { return std::pow(T(2), Math::max(T(0), T(0.5) * (a_e - T(1)))); };
6180
6181 return Math::min(a_radii[0], Math::min(a_radii[1], a_radii[2])) / (factor(a_exponent1) * factor(a_exponent2));
6182}
6183
6197inline double
6198helixTurnDistance(const double a_radius, const double a_pitch)
6199{
6200 const double rate = a_pitch / (2.0 * pi<double>);
6201
6202 const auto squared = [&](const double a_theta) {
6203 return 2.0 * a_radius * a_radius * (1.0 - std::cos(a_theta)) + rate * rate * a_theta * a_theta;
6204 };
6205
6206 constexpr int Samples = 4096;
6207
6208 const double step = 4.0 * pi<double> / double(Samples);
6209
6210 // Past the first maximum, the smallest sample.
6211 int i = 1;
6212 double prev = squared(step);
6213
6214 while (i < Samples && squared(double(i + 1) * step) >= prev) {
6215 i++;
6216 prev = squared(double(i) * step);
6217 }
6218
6219 if (i >= Samples) {
6221 }
6222
6223 int best = i;
6224 double minimum = prev;
6225
6226 for (int j = i; j <= Samples; j++) {
6227 if (squared(double(j) * step) < minimum) {
6228 minimum = squared(double(j) * step);
6229 best = j;
6230 }
6231 }
6232
6233 // Golden section on the samples around the smallest.
6234 const double golden = 0.5 * (std::sqrt(5.0) - 1.0);
6235
6236 double lo = double(best - 1) * step;
6237 double hi = double(best + 1) * step;
6238
6239 for (int k = 0; k < 100; k++) {
6240 const double a = hi - golden * (hi - lo);
6241 const double b = lo + golden * (hi - lo);
6242
6243 if (squared(a) < squared(b)) {
6244 hi = b;
6245 }
6246 else {
6247 lo = a;
6248 }
6249 }
6250
6251 return std::sqrt(Math::min(minimum, squared(0.5 * (lo + hi))));
6252}
6253
6254} // namespace AnalyticDetail
6255
6267template <class T>
6269{
6270 static_assert(std::is_floating_point_v<T>, "QuadricSDF<T>: T must be a floating-point type");
6271
6272public:
6277
6281 enum class Kind : uint32_t
6282 {
6285 Paraboloid
6286 };
6287
6292 QuadricSDF() = default;
6293
6302 [[nodiscard]] static QuadricSDF
6303 hyperboloid(const Vec3T<T>& a_center, const T a_waist, const T a_angle)
6304 {
6305 QuadricSDF q = QuadricSDF::checked(a_center, a_waist, a_angle, "QuadricSDF::hyperboloid");
6306
6308 q.m_a = a_waist;
6309 q.m_c = T(double(a_waist) / std::tan(0.5 * double(a_angle) * pi<double> / 180.0));
6310
6311 return q;
6312 }
6313
6323 [[nodiscard]] static QuadricSDF
6324 hyperboloidTwoSheets(const Vec3T<T>& a_center, const T a_tipDistance, const T a_angle)
6325 {
6326 QuadricSDF q = QuadricSDF::checked(a_center, a_tipDistance, a_angle, "QuadricSDF::hyperboloidTwoSheets");
6327
6329 q.m_c = a_tipDistance;
6330 q.m_a = T(double(a_tipDistance) * std::tan(0.5 * double(a_angle) * pi<double> / 180.0));
6331
6332 return q;
6333 }
6334
6342 [[nodiscard]] static QuadricSDF
6343 paraboloid(const Vec3T<T>& a_tip, const T a_tipRadius)
6344 {
6345 QuadricSDF q = QuadricSDF::checked(a_tip, a_tipRadius, T(90), "QuadricSDF::paraboloid");
6346
6348 q.m_a = a_tipRadius;
6349 q.m_c = a_tipRadius;
6350
6351 return q;
6352 }
6353
6357 QuadricSDF(const QuadricSDF&) = default;
6358
6363
6368 QuadricSDF&
6369 operator=(const QuadricSDF&) = default;
6370
6375 QuadricSDF&
6376 operator=(QuadricSDF&&) = default;
6377
6382 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6383 Kind
6384 getKind() const noexcept
6385 {
6386 return m_kind;
6387 }
6388
6393 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6394 const Vec3T<T>&
6395 getCenter() const noexcept
6396 {
6397 return m_center;
6398 }
6399
6404 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6405 const T&
6406 getA() const noexcept
6407 {
6408 return m_a;
6409 }
6410
6415 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6416 const T&
6417 getC() const noexcept
6418 {
6419 return m_c;
6420 }
6421
6427 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6428 T
6429 signedDistance(const Vec3T<T>& a_point) const noexcept
6430 {
6431 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
6432 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
6433 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
6434
6435 const Vec3T<T> w = a_point - m_center;
6436 const T r = std::sqrt(w[0] * w[0] + w[2] * w[2]);
6437 const T y = w[1];
6438
6439 if (m_kind == Kind::Paraboloid) {
6440 const T d = AnalyticDetail::parabolaDistance(m_a, r, y);
6441
6442 return (y + r * r / (T(2) * m_a) < T(0)) ? -d : d;
6443 }
6444
6445 // Folded into the quadrant of the branch: one sheet's hyperbola opens along r, two sheets' along y.
6446 const bool oneSheet = m_kind == Kind::HyperboloidOneSheet;
6447 const T X = oneSheet ? r : std::abs(y);
6448 const T Y = oneSheet ? std::abs(y) : r;
6449 const T A = oneSheet ? m_a : m_c;
6450 const T B = oneSheet ? m_c : m_a;
6451
6452 const T d = AnalyticDetail::hyperbolaDistance(A, B, X, Y);
6453 const T g = (X / A) * (X / A) - (Y / B) * (Y / B) - T(1);
6454 const bool inside = oneSheet ? (g < T(0)) : (g > T(0));
6455
6456 return inside ? -d : d;
6457 }
6458
6463 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6465 computeBoundingVolume() const noexcept
6466 {
6467 const T big = Math::Limits<T>::max();
6468 const T top = (m_kind == Kind::Paraboloid) ? m_center[1] : big;
6469
6470 return BoundingVolumes::AABBT<T>(Vec3T<T>(-big, -big, -big), Vec3T<T>(big, top, big));
6471 }
6472
6473protected:
6482 static QuadricSDF
6483 checked(const Vec3T<T>& a_center, const T a_size, const T a_angle, const char* a_who)
6484 {
6485 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
6486 "%s: the center must be finite (%g, %g, %g)",
6487 a_who,
6488 double(a_center[0]),
6489 double(a_center[1]),
6490 double(a_center[2]));
6492 std::isfinite(a_size) && a_size > T(0), "%s: the size must be finite and positive (%g)", a_who, double(a_size));
6494 a_angle > T(0) && a_angle < T(180), "%s: the angle must be in (0, 180) degrees (%g)", a_who, double(a_angle));
6495
6496 QuadricSDF q;
6497
6498 q.m_center = a_center;
6499
6500 return q;
6501 }
6502
6507
6512
6516 T m_a = T(1);
6517
6521 T m_c = T(1);
6522};
6523
6536template <class T>
6538{
6539 static_assert(std::is_floating_point_v<T>, "SuperellipsoidSDF<T>: T must be a floating-point type");
6540
6541public:
6546
6551
6559 SuperellipsoidSDF(const Vec3T<T>& a_center, const Vec3T<T>& a_radii, const T a_exponent1, const T a_exponent2)
6560 {
6561 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
6562 "SuperellipsoidSDF: the center must be finite (%g, %g, %g)",
6563 double(a_center[0]),
6564 double(a_center[1]),
6565 double(a_center[2]));
6566 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_radii) && a_radii[0] > T(0) && a_radii[1] > T(0) && a_radii[2] > T(0),
6567 "SuperellipsoidSDF: the semi-axes must be finite and positive (%g, %g, %g)",
6568 double(a_radii[0]),
6569 double(a_radii[1]),
6570 double(a_radii[2]));
6571 EBGEOMETRY_REQUIRE(a_exponent1 >= T(0.1) && a_exponent1 <= T(2) && a_exponent2 >= T(0.1) && a_exponent2 <= T(2),
6572 "SuperellipsoidSDF: the exponents must be in [0.1, 2] (%g, %g)",
6573 double(a_exponent1),
6574 double(a_exponent2));
6575
6576 m_center = a_center;
6577 m_radii = a_radii;
6578 m_exponent1 = a_exponent1;
6579 m_exponent2 = a_exponent2;
6580 m_scale = AnalyticDetail::superellipsoidScale(a_radii, a_exponent1, a_exponent2);
6581 }
6582
6587
6592
6598 operator=(const SuperellipsoidSDF&) = default;
6599
6606
6611 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6612 const Vec3T<T>&
6613 getCenter() const noexcept
6614 {
6615 return m_center;
6616 }
6617
6622 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6623 const Vec3T<T>&
6624 getRadii() const noexcept
6625 {
6626 return m_radii;
6627 }
6628
6637 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6639 T
6640 gauge(const Vec3T<T>& a_point) const noexcept
6641 {
6642 const Vec3T<T> w = a_point - m_center;
6643 const T x = std::abs(w[0] / m_radii[0]);
6644 const T y = std::abs(w[1] / m_radii[1]);
6645 const T z = std::abs(w[2] / m_radii[2]);
6646
6647 const T across = AnalyticDetail::pNorm(x, z, T(2) / m_exponent2);
6648
6649 return AnalyticDetail::pNorm(across, y, T(2) / m_exponent1);
6650 }
6651
6657 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6658 T
6659 signedDistance(const Vec3T<T>& a_point) const noexcept
6660 {
6661 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
6662 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
6663 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
6664
6665 return (this->gauge(a_point) - T(1)) * m_scale;
6666 }
6667
6672 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6674 computeBoundingVolume() const noexcept
6675 {
6677 }
6678
6679protected:
6684
6689
6693 T m_exponent1 = T(0.5);
6694
6698 T m_exponent2 = T(0.5);
6699
6703 T m_scale = T(1);
6704};
6705
6714template <class T>
6716{
6717 static_assert(std::is_floating_point_v<T>, "SolidAngleSDF<T>: T must be a floating-point type");
6718
6719public:
6724
6728 SolidAngleSDF() = default;
6729
6736 SolidAngleSDF(const Vec3T<T>& a_center, const T a_radius, const T a_angle)
6737 {
6738 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center),
6739 "SolidAngleSDF: the center must be finite (%g, %g, %g)",
6740 double(a_center[0]),
6741 double(a_center[1]),
6742 double(a_center[2]));
6743 EBGEOMETRY_REQUIRE(std::isfinite(a_radius) && a_radius > T(0),
6744 "SolidAngleSDF: the radius must be finite and positive (%g)",
6745 double(a_radius));
6747 a_angle > T(0) && a_angle < T(360), "SolidAngleSDF: the angle must be in (0, 360) degrees (%g)", double(a_angle));
6748
6749 m_center = a_center;
6750 m_radius = a_radius;
6751 m_angle = a_angle;
6752 m_sin = T(std::sin(0.5 * double(a_angle) * pi<double> / 180.0));
6753 m_cos = T(std::cos(0.5 * double(a_angle) * pi<double> / 180.0));
6754 }
6755
6759 SolidAngleSDF(const SolidAngleSDF&) = default;
6760
6765
6771 operator=(const SolidAngleSDF&) = default;
6772
6779
6784 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6785 const Vec3T<T>&
6786 getCenter() const noexcept
6787 {
6788 return m_center;
6789 }
6790
6795 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6796 const T&
6797 getRadius() const noexcept
6798 {
6799 return m_radius;
6800 }
6801
6806 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6807 const T&
6808 getAngle() const noexcept
6809 {
6810 return m_angle;
6811 }
6812
6818 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6819 T
6820 signedDistance(const Vec3T<T>& a_point) const noexcept
6821 {
6822 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
6823 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
6824 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
6825
6826 T sphere;
6827 T side;
6828
6829 this->terms(a_point, sphere, side);
6830
6831 return Math::max(sphere, side);
6832 }
6833
6838 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6839 uint32_t
6840 getNumParts() const noexcept
6841 {
6842 return 2U;
6843 }
6844
6850 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6851 uint32_t
6852 closestPart(const Vec3T<T>& a_point) const noexcept
6853 {
6854 T sphere;
6855 T side;
6856
6857 this->terms(a_point, sphere, side);
6858
6859 return (sphere >= side) ? 0U : 1U;
6860 }
6861
6866 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
6872
6873protected:
6881 void
6882 terms(const Vec3T<T>& a_point, T& a_sphere, T& a_side) const noexcept
6883 {
6884 const Vec3T<T> w = a_point - m_center;
6885 const T r = std::sqrt(w[0] * w[0] + w[2] * w[2]);
6886 const T y = w[1];
6887
6888 const T along = Math::clamp(r * m_sin + y * m_cos, T(0), m_radius);
6889 const T dr = r - along * m_sin;
6890 const T dy = y - along * m_cos;
6891 const T cross = m_cos * r - m_sin * y;
6892
6893 a_sphere = std::sqrt(r * r + y * y) - m_radius;
6894 a_side = std::sqrt(dr * dr + dy * dy) * ((cross > T(0)) ? T(1) : ((cross < T(0)) ? T(-1) : T(0)));
6895 }
6896
6901
6905 T m_radius = T(1);
6906
6910 T m_angle = T(60);
6911
6915 T m_sin = T(0.5);
6916
6920 T m_cos = T(0.86602540378443865);
6921};
6922
6931template <class T>
6933{
6934 static_assert(std::is_floating_point_v<T>, "VesicaSDF<T>: T must be a floating-point type");
6935
6936public:
6941
6945 VesicaSDF() = default;
6946
6954 VesicaSDF(const Vec3T<T>& a_tip1, const Vec3T<T>& a_tip2, const T a_radius)
6955 {
6956 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_tip1) && AnalyticDetail::isFinite(a_tip2),
6957 "VesicaSDF: the tips must be finite (%g, %g, %g) and (%g, %g, %g)",
6958 double(a_tip1[0]),
6959 double(a_tip1[1]),
6960 double(a_tip1[2]),
6961 double(a_tip2[0]),
6962 double(a_tip2[1]),
6963 double(a_tip2[2]));
6964
6965 const T half = T(0.5) * (a_tip2 - a_tip1).length();
6966
6967 EBGEOMETRY_REQUIRE(half > T(0),
6968 "VesicaSDF: the two tips must differ, but both are (%g, %g, %g)",
6969 double(a_tip1[0]),
6970 double(a_tip1[1]),
6971 double(a_tip1[2]));
6973 std::isfinite(a_radius) && a_radius > T(0) && a_radius < half,
6974 "VesicaSDF: the radius must be positive and less than half the distance between the tips %g (%g)",
6975 double(half),
6976 double(a_radius));
6977
6978 m_tip1 = a_tip1;
6979 m_tip2 = a_tip2;
6980 m_radius = a_radius;
6981 }
6982
6986 VesicaSDF(const VesicaSDF&) = default;
6987
6991 VesicaSDF(VesicaSDF&&) = default;
6992
6997 VesicaSDF&
6998 operator=(const VesicaSDF&) = default;
6999
7004 VesicaSDF&
7005 operator=(VesicaSDF&&) = default;
7006
7011 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7012 const Vec3T<T>&
7013 getTip1() const noexcept
7014 {
7015 return m_tip1;
7016 }
7017
7022 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7023 const Vec3T<T>&
7024 getTip2() const noexcept
7025 {
7026 return m_tip2;
7027 }
7028
7033 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7034 const T&
7035 getRadius() const noexcept
7036 {
7037 return m_radius;
7038 }
7039
7045 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7046 T
7047 signedDistance(const Vec3T<T>& a_point) const noexcept
7048 {
7049 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
7050 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
7051 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
7052
7053 const Vec3T<T> c = T(0.5) * (m_tip1 + m_tip2);
7054 const Vec3T<T> axis = m_tip2 - m_tip1;
7055 const T length = axis.length();
7056 const Vec3T<T> v = axis / length;
7057 const Vec3T<T> w = a_point - c;
7058 const T along = dot(w, v);
7059 const T qx = (w - along * v).length();
7060 const T qy = std::abs(along);
7061 const T half = T(0.5) * length;
7062
7063 // The arc's circle is centered at -d across the axis, with radius d + radius.
7064 const T d = T(0.5) * (half * half - m_radius * m_radius) / m_radius;
7065
7066 // Beyond the line from the circle's center through the tip, the tip is the closest point.
7067 if (half * qx < d * (qy - half)) {
7068 return std::sqrt(qx * qx + (qy - half) * (qy - half));
7069 }
7070
7071 return std::sqrt((qx + d) * (qx + d) + qy * qy) - (d + m_radius);
7072 }
7073
7078 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7085
7086protected:
7090 Vec3T<T> m_tip1 = Vec3T<T>(T(0), T(-1), T(0));
7091
7095 Vec3T<T> m_tip2 = Vec3T<T>(T(0), T(1), T(0));
7096
7100 T m_radius = T(0.5);
7101};
7102
7118template <class T>
7120{
7121 static_assert(std::is_floating_point_v<T>, "HelixSDF<T>: T must be a floating-point type");
7122
7123public:
7128
7133 HelixSDF() = default;
7134
7146 HelixSDF(const Vec3T<T>& a_center1,
7147 const Vec3T<T>& a_center2,
7148 const T a_helixRadius,
7149 const T a_turns,
7150 const T a_tubeRadius,
7151 const Vec3T<T>& a_startDirection)
7152 {
7153 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_center1) && AnalyticDetail::isFinite(a_center2),
7154 "HelixSDF: the centers must be finite (%g, %g, %g) and (%g, %g, %g)",
7155 double(a_center1[0]),
7156 double(a_center1[1]),
7157 double(a_center1[2]),
7158 double(a_center2[0]),
7159 double(a_center2[1]),
7160 double(a_center2[2]));
7161
7162 const T length = (a_center2 - a_center1).length();
7163
7165 "HelixSDF: the two centers must differ, but both are (%g, %g, %g)",
7166 double(a_center1[0]),
7167 double(a_center1[1]),
7168 double(a_center1[2]));
7169 EBGEOMETRY_REQUIRE(std::isfinite(a_helixRadius) && a_helixRadius > T(0),
7170 "HelixSDF: the helix radius must be finite and positive (%g)",
7171 double(a_helixRadius));
7172 EBGEOMETRY_REQUIRE(std::isfinite(a_turns) && a_turns > T(0),
7173 "HelixSDF: the number of turns must be finite and positive (%g)",
7174 double(a_turns));
7175
7176 const T apart = T(AnalyticDetail::helixTurnDistance(double(a_helixRadius), double(length) / double(a_turns)));
7177
7178 EBGEOMETRY_REQUIRE(std::isfinite(a_tubeRadius) && a_tubeRadius > T(0) && a_tubeRadius < a_helixRadius &&
7179 T(2) * a_tubeRadius < apart,
7180 "HelixSDF: the tube radius must be positive and less than the helix radius %g and half the "
7181 "distance between turns %g (%g)",
7182 double(a_helixRadius),
7183 double(T(0.5) * apart),
7184 double(a_tubeRadius));
7185
7186 const Vec3T<T> axis = (a_center2 - a_center1) / length;
7187 const Vec3T<T> across = a_startDirection - dot(a_startDirection, axis) * axis;
7188
7189 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_startDirection) && across.length() > T(0),
7190 "HelixSDF: the start direction (%g, %g, %g) must have a part across the axis",
7191 double(a_startDirection[0]),
7192 double(a_startDirection[1]),
7193 double(a_startDirection[2]));
7194
7195 m_center1 = a_center1;
7196 m_center2 = a_center2;
7197 m_axis = axis;
7198 m_start = across / across.length();
7199 m_helixRadius = a_helixRadius;
7200 m_turns = a_turns;
7201 m_tubeRadius = a_tubeRadius;
7202 }
7203
7207 HelixSDF(const HelixSDF&) = default;
7208
7212 HelixSDF(HelixSDF&&) = default;
7213
7218 HelixSDF&
7219 operator=(const HelixSDF&) = default;
7220
7225 HelixSDF&
7226 operator=(HelixSDF&&) = default;
7227
7232 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7233 const Vec3T<T>&
7234 getCenter1() const noexcept
7235 {
7236 return m_center1;
7237 }
7238
7243 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7244 const Vec3T<T>&
7245 getCenter2() const noexcept
7246 {
7247 return m_center2;
7248 }
7249
7254 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7255 const T&
7256 getHelixRadius() const noexcept
7257 {
7258 return m_helixRadius;
7259 }
7260
7265 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7266 const T&
7267 getTurns() const noexcept
7268 {
7269 return m_turns;
7270 }
7271
7276 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7277 const T&
7278 getTubeRadius() const noexcept
7279 {
7280 return m_tubeRadius;
7281 }
7282
7287 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7288 const Vec3T<T>&
7289 getStartDirection() const noexcept
7290 {
7291 return m_start;
7292 }
7293
7299 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7300 Vec3T<T>
7301 centerLine(const T a_angle) const noexcept
7302 {
7303 const T rise = a_angle * (m_center2 - m_center1).length() / (T(2) * pi<T> * m_turns);
7304
7305 return m_center1 + rise * m_axis +
7306 m_helixRadius * (std::cos(a_angle) * m_start + std::sin(a_angle) * cross(m_axis, m_start));
7307 }
7308
7314 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7315 T
7316 signedDistance(const Vec3T<T>& a_point) const noexcept
7317 {
7318 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
7319 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
7320 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
7321
7322 const T twoPi = T(2) * pi<T>;
7323
7324 // The point around the axis: its height y, its distance rho from the axis, and its angle phi from the start.
7325 const Vec3T<T> w = a_point - m_center1;
7326 const T y = dot(w, m_axis);
7327 const T x = dot(w, m_start);
7328 const T z = dot(w, cross(m_axis, m_start));
7329 const T rho = std::sqrt(x * x + z * z);
7330 const T phi = std::atan2(z, x);
7331
7332 // The rise per radian, and the last angle.
7333 const T rate = (m_center2 - m_center1).length() / (twoPi * m_turns);
7334 const T last = twoPi * m_turns;
7335
7336 // Window k covers the angles phi + 2 pi k + s, |s| <= pi.
7337 const T kLow = std::ceil((-pi<T> - phi) / twoPi);
7338 const T kHigh = std::floor((last + pi<T> - phi) / twoPi);
7339 const T kNear = Math::clamp(std::round((y / rate - phi) / twoPi), kLow, kHigh);
7340
7341 const T across = (rho - m_helixRadius) * (rho - m_helixRadius);
7342
7343 // The windows outward from the nearest, alternately below and above it, until a window's height difference
7344 // alone rules out every further one on its side. One call site of windowMinimum(), since a tape copies this into
7345 // each of its levels.
7346 T best = Math::Limits<T>::max();
7347 bool belowDone = false;
7348 bool aboveDone = false;
7349
7350 const int count = 2 * int(kHigh - kLow) + 1;
7351
7352 for (int i = 0; i < count && !(belowDone && aboveDone); i++) {
7353 const bool below = (i % 2) == 1;
7354 const T step = T((i + 1) / 2);
7355 const T k = below ? kNear - step : kNear + step;
7356
7357 if ((i > 0 && below && belowDone) || (i > 0 && !below && aboveDone)) {
7358 continue;
7359 }
7360
7361 const T lo = Math::max(phi + twoPi * k - T(0.5) * twoPi, T(0));
7362 const T hi = Math::min(phi + twoPi * k + T(0.5) * twoPi, last);
7363 const T gap = Math::max(Math::max(rate * lo - y, y - rate * hi), T(0));
7364 const T rule = across + gap * gap;
7365
7366 if (k < kLow || k > kHigh || rule >= best) {
7367 if (below) {
7368 belowDone = true;
7369 }
7370 else if (i > 0) {
7371 aboveDone = true;
7372 }
7373
7374 continue;
7375 }
7376
7377 best = Math::min(best, this->windowMinimum(k, rho, phi, y, rate, last));
7378 }
7379
7380 return std::sqrt(best) - m_tubeRadius;
7381 }
7382
7387 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7389 computeBoundingVolume() const noexcept
7390 {
7391 const T reach = m_helixRadius + m_tubeRadius;
7392
7394 max(m_center1, m_center2) + reach * Vec3T<T>::ones());
7395 }
7396
7397protected:
7415 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7417 T
7418 windowMinimum(const T a_k, const T a_rho, const T a_phi, const T a_y, const T a_rate, const T a_last) const noexcept
7419 {
7420 const T halfTurn = pi<T>;
7421 const T base = a_phi + T(2) * halfTurn * a_k;
7422 const T Y = a_y - a_rate * base;
7423 const T rR = a_rho * m_helixRadius;
7424 const T rate2 = a_rate * a_rate;
7425 const T A = a_rho * a_rho + m_helixRadius * m_helixRadius;
7426
7427 const T sLo = Math::max(-halfTurn, -base);
7428 const T sHi = Math::min(halfTurn, a_last - base);
7429
7430 const auto f = [&](const T a_s) noexcept {
7431 const T v = Y - a_rate * a_s;
7432
7433 return A - T(2) * rR * std::cos(a_s) + v * v;
7434 };
7435
7436 const auto g = [&](const T a_s) noexcept { return rR * std::sin(a_s) + rate2 * a_s - a_rate * Y; };
7437
7438 T best = Math::min(f(sLo), f(sHi));
7439
7440 const T sc = (rR > rate2) ? std::acos(-rate2 / rR) : halfTurn;
7441 T lo = Math::max(-sc, sLo);
7442 T hi = Math::min(sc, sHi);
7443
7444 if (lo < hi && g(lo) < T(0) && g(hi) > T(0)) {
7445 constexpr int MaxIterations = 64;
7446
7447 const T eps = Math::Limits<T>::epsilon();
7448
7449 T s = Math::clamp(Y / a_rate, lo, hi);
7450
7451 for (int i = 0; i < MaxIterations; i++) {
7452 const T value = g(s);
7453
7454 if (value == T(0)) {
7455 break;
7456 }
7457
7458 if (value < T(0)) {
7459 lo = s;
7460 }
7461 else {
7462 hi = s;
7463 }
7464
7465 const T slope = rR * std::cos(s) + rate2;
7466
7467 T next = (slope > T(0)) ? s - value / slope : T(0.5) * (lo + hi);
7468
7469 if (!(next > lo && next < hi)) {
7470 next = T(0.5) * (lo + hi);
7471 }
7472
7473 const bool converged = std::abs(next - s) <= T(4) * eps * Math::max(T(1), std::abs(s)) ||
7474 hi - lo <= T(4) * eps * Math::max(T(1), std::abs(s));
7475
7476 s = next;
7477
7478 if (converged) {
7479 break;
7480 }
7481 }
7482
7483 best = Math::min(best, f(s));
7484 }
7485
7486 return Math::max(best, T(0));
7487 }
7488
7492 Vec3T<T> m_center1 = Vec3T<T>(T(0), T(-1), T(0));
7493
7497 Vec3T<T> m_center2 = Vec3T<T>(T(0), T(1), T(0));
7498
7502 Vec3T<T> m_axis = Vec3T<T>(T(0), T(1), T(0));
7503
7507 Vec3T<T> m_start = Vec3T<T>(T(1), T(0), T(0));
7508
7512 T m_helixRadius = T(0.5);
7513
7517 T m_turns = T(4);
7518
7522 T m_tubeRadius = T(0.1);
7523};
7524
7536template <class T>
7538{
7539 static_assert(std::is_floating_point_v<T>, "LatticeSDF<T>: T must be a floating-point type");
7540
7541public:
7546
7550 enum class Kind : uint32_t
7551 {
7552 Gyroid,
7553 SchwarzP,
7554 SchwarzD,
7555 Neovius
7556 };
7557
7561 LatticeSDF() = default;
7562
7570 LatticeSDF(const Kind a_kind, const Vec3T<T>& a_cellSize, const T a_thickness)
7571 {
7572 EBGEOMETRY_REQUIRE(AnalyticDetail::isFinite(a_cellSize) && a_cellSize[0] > T(0) && a_cellSize[1] > T(0) &&
7573 a_cellSize[2] > T(0),
7574 "LatticeSDF: the cell size must be finite and positive (%g, %g, %g)",
7575 double(a_cellSize[0]),
7576 double(a_cellSize[1]),
7577 double(a_cellSize[2]));
7578
7579 const T smallest = Math::min(a_cellSize[0], Math::min(a_cellSize[1], a_cellSize[2]));
7580
7581 EBGEOMETRY_REQUIRE(std::isfinite(a_thickness) && a_thickness > T(0) && a_thickness < smallest,
7582 "LatticeSDF: the thickness must be positive and less than the smallest cell size %g (%g)",
7583 double(smallest),
7584 double(a_thickness));
7585 EBGEOMETRY_REQUIRE(a_kind == Kind::Gyroid || a_kind == Kind::SchwarzP || a_kind == Kind::SchwarzD ||
7586 a_kind == Kind::Neovius,
7587 "LatticeSDF: unknown kind %u",
7588 unsigned(a_kind));
7589
7590 m_kind = a_kind;
7591 m_cellSize = a_cellSize;
7592 m_thickness = a_thickness;
7593 m_scale = smallest / (T(2) * pi<T> * ((a_kind == Kind::Neovius) ? T(7) : std::sqrt(T(3))));
7594 }
7595
7599 LatticeSDF(const LatticeSDF&) = default;
7600
7605
7610 LatticeSDF&
7611 operator=(const LatticeSDF&) = default;
7612
7617 LatticeSDF&
7618 operator=(LatticeSDF&&) = default;
7619
7624 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7625 Kind
7626 getKind() const noexcept
7627 {
7628 return m_kind;
7629 }
7630
7635 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7636 const Vec3T<T>&
7637 getCellSize() const noexcept
7638 {
7639 return m_cellSize;
7640 }
7641
7646 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7647 const T&
7648 getThickness() const noexcept
7649 {
7650 return m_thickness;
7651 }
7652
7661 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7663 T
7664 field(const Vec3T<T>& a_point) const noexcept
7665 {
7666 const T twoPi = T(2) * pi<T>;
7667
7668 const T x = twoPi * a_point[0] / m_cellSize[0];
7669 const T y = twoPi * a_point[1] / m_cellSize[1];
7670 const T z = twoPi * a_point[2] / m_cellSize[2];
7671
7672 const T sx = std::sin(x);
7673 const T sy = std::sin(y);
7674 const T sz = std::sin(z);
7675 const T cx = std::cos(x);
7676 const T cy = std::cos(y);
7677 const T cz = std::cos(z);
7678
7679 switch (m_kind) {
7680 case Kind::SchwarzP: {
7681 return cx + cy + cz;
7682 }
7683 case Kind::SchwarzD: {
7684 return sx * sy * sz + sx * cy * cz + cx * sy * cz + cx * cy * sz;
7685 }
7686 case Kind::Neovius: {
7687 return T(3) * (cx + cy + cz) + T(4) * cx * cy * cz;
7688 }
7689 default: {
7690 return sx * cy + sy * cz + sz * cx;
7691 }
7692 }
7693 }
7694
7700 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7701 T
7702 signedDistance(const Vec3T<T>& a_point) const noexcept
7703 {
7704 EBGEOMETRY_EXPECT(std::isfinite(a_point[0]));
7705 EBGEOMETRY_EXPECT(std::isfinite(a_point[1]));
7706 EBGEOMETRY_EXPECT(std::isfinite(a_point[2]));
7707
7708 return std::abs(this->field(a_point)) * m_scale - T(0.5) * m_thickness;
7709 }
7710
7715 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
7717 computeBoundingVolume() const noexcept
7718 {
7719 const T big = Math::Limits<T>::max();
7720
7721 return BoundingVolumes::AABBT<T>(Vec3T<T>(-big, -big, -big), Vec3T<T>(big, big, big));
7722 }
7723
7724protected:
7729
7734
7738 T m_thickness = T(0.1);
7739
7743 T m_scale = T(1) / (T(2) * pi<T> * T(1.7320508075688772));
7744};
7745
7750static_assert(std::is_trivially_copyable_v<PlaneSDF<float>>, "PlaneSDF<float> must be trivially copyable");
7751static_assert(std::is_trivially_copyable_v<PlaneSDF<double>>, "PlaneSDF<double> must be trivially copyable");
7752static_assert(std::is_trivially_copyable_v<SphereSDF<float>>, "SphereSDF<float> must be trivially copyable");
7753static_assert(std::is_trivially_copyable_v<SphereSDF<double>>, "SphereSDF<double> must be trivially copyable");
7754static_assert(std::is_trivially_copyable_v<BoxSDF<float>>, "BoxSDF<float> must be trivially copyable");
7755static_assert(std::is_trivially_copyable_v<BoxSDF<double>>, "BoxSDF<double> must be trivially copyable");
7756static_assert(std::is_trivially_copyable_v<TorusSDF<float>>, "TorusSDF<float> must be trivially copyable");
7757static_assert(std::is_trivially_copyable_v<TorusSDF<double>>, "TorusSDF<double> must be trivially copyable");
7758static_assert(std::is_trivially_copyable_v<CylinderSDF<float>>, "CylinderSDF<float> must be trivially copyable");
7759static_assert(std::is_trivially_copyable_v<CylinderSDF<double>>, "CylinderSDF<double> must be trivially copyable");
7760static_assert(std::is_trivially_copyable_v<InfiniteCylinderSDF<float>>,
7761 "InfiniteCylinderSDF<float> must be trivially copyable");
7762static_assert(std::is_trivially_copyable_v<InfiniteCylinderSDF<double>>,
7763 "InfiniteCylinderSDF<double> must be trivially copyable");
7764static_assert(std::is_trivially_copyable_v<CapsuleSDF<float>>, "CapsuleSDF<float> must be trivially copyable");
7765static_assert(std::is_trivially_copyable_v<CapsuleSDF<double>>, "CapsuleSDF<double> must be trivially copyable");
7766static_assert(std::is_trivially_copyable_v<InfiniteConeSDF<float>>,
7767 "InfiniteConeSDF<float> must be trivially copyable");
7768static_assert(std::is_trivially_copyable_v<InfiniteConeSDF<double>>,
7769 "InfiniteConeSDF<double> must be trivially copyable");
7770static_assert(std::is_trivially_copyable_v<ConeSDF<float>>, "ConeSDF<float> must be trivially copyable");
7771static_assert(std::is_trivially_copyable_v<ConeSDF<double>>, "ConeSDF<double> must be trivially copyable");
7772static_assert(std::is_trivially_copyable_v<RoundedBoxSDF<float>>, "RoundedBoxSDF<float> must be trivially copyable");
7773static_assert(std::is_trivially_copyable_v<RoundedBoxSDF<double>>, "RoundedBoxSDF<double> must be trivially copyable");
7774static_assert(std::is_trivially_copyable_v<PerlinSDF<float>>, "PerlinSDF<float> must be trivially copyable");
7775static_assert(std::is_trivially_copyable_v<PerlinSDF<double>>, "PerlinSDF<double> must be trivially copyable");
7776static_assert(std::is_trivially_copyable_v<RoundedCylinderSDF<float>>,
7777 "RoundedCylinderSDF<float> must be trivially copyable");
7778static_assert(std::is_trivially_copyable_v<RoundedCylinderSDF<double>>,
7779 "RoundedCylinderSDF<double> must be trivially copyable");
7780
7781static_assert(std::is_trivially_copyable_v<EllipsoidSDF<float>>, "EllipsoidSDF<float> must be trivially copyable");
7782static_assert(std::is_trivially_copyable_v<EllipsoidSDF<double>>, "EllipsoidSDF<double> must be trivially copyable");
7783static_assert(std::is_trivially_copyable_v<CappedConeSDF<float>>, "CappedConeSDF<float> must be trivially copyable");
7784static_assert(std::is_trivially_copyable_v<CappedConeSDF<double>>, "CappedConeSDF<double> must be trivially copyable");
7785static_assert(std::is_trivially_copyable_v<RoundConeSDF<float>>, "RoundConeSDF<float> must be trivially copyable");
7786static_assert(std::is_trivially_copyable_v<RoundConeSDF<double>>, "RoundConeSDF<double> must be trivially copyable");
7787static_assert(std::is_trivially_copyable_v<PolygonPrismSDF<float>>,
7788 "PolygonPrismSDF<float> must be trivially copyable");
7789static_assert(std::is_trivially_copyable_v<PolygonPrismSDF<double>>,
7790 "PolygonPrismSDF<double> must be trivially copyable");
7791static_assert(std::is_trivially_copyable_v<TubeSDF<float>>, "TubeSDF<float> must be trivially copyable");
7792static_assert(std::is_trivially_copyable_v<TubeSDF<double>>, "TubeSDF<double> must be trivially copyable");
7793static_assert(std::is_trivially_copyable_v<CappedTorusSDF<float>>, "CappedTorusSDF<float> must be trivially copyable");
7794static_assert(std::is_trivially_copyable_v<CappedTorusSDF<double>>,
7795 "CappedTorusSDF<double> must be trivially copyable");
7796static_assert(std::is_trivially_copyable_v<CutSphereSDF<float>>, "CutSphereSDF<float> must be trivially copyable");
7797static_assert(std::is_trivially_copyable_v<CutSphereSDF<double>>, "CutSphereSDF<double> must be trivially copyable");
7798static_assert(std::is_trivially_copyable_v<CutHollowSphereSDF<float>>,
7799 "CutHollowSphereSDF<float> must be trivially copyable");
7800static_assert(std::is_trivially_copyable_v<CutHollowSphereSDF<double>>,
7801 "CutHollowSphereSDF<double> must be trivially copyable");
7802static_assert(std::is_trivially_copyable_v<WedgeSDF<float>>, "WedgeSDF<float> must be trivially copyable");
7803static_assert(std::is_trivially_copyable_v<WedgeSDF<double>>, "WedgeSDF<double> must be trivially copyable");
7804
7805static_assert(std::is_trivially_copyable_v<ConvexPolyhedronSDF<float>>,
7806 "ConvexPolyhedronSDF<float> must be trivially copyable");
7807static_assert(std::is_trivially_copyable_v<ConvexPolyhedronSDF<double>>,
7808 "ConvexPolyhedronSDF<double> must be trivially copyable");
7809static_assert(std::is_trivially_copyable_v<BoxFrameSDF<float>>, "BoxFrameSDF<float> must be trivially copyable");
7810static_assert(std::is_trivially_copyable_v<BoxFrameSDF<double>>, "BoxFrameSDF<double> must be trivially copyable");
7811static_assert(std::is_trivially_copyable_v<QuadricSDF<float>>, "QuadricSDF<float> must be trivially copyable");
7812static_assert(std::is_trivially_copyable_v<QuadricSDF<double>>, "QuadricSDF<double> must be trivially copyable");
7813static_assert(std::is_trivially_copyable_v<SuperellipsoidSDF<float>>,
7814 "SuperellipsoidSDF<float> must be trivially copyable");
7815static_assert(std::is_trivially_copyable_v<SuperellipsoidSDF<double>>,
7816 "SuperellipsoidSDF<double> must be trivially copyable");
7817static_assert(std::is_trivially_copyable_v<SolidAngleSDF<float>>, "SolidAngleSDF<float> must be trivially copyable");
7818static_assert(std::is_trivially_copyable_v<SolidAngleSDF<double>>, "SolidAngleSDF<double> must be trivially copyable");
7819static_assert(std::is_trivially_copyable_v<VesicaSDF<float>>, "VesicaSDF<float> must be trivially copyable");
7820static_assert(std::is_trivially_copyable_v<VesicaSDF<double>>, "VesicaSDF<double> must be trivially copyable");
7821static_assert(std::is_trivially_copyable_v<HelixSDF<float>>, "HelixSDF<float> must be trivially copyable");
7822static_assert(std::is_trivially_copyable_v<HelixSDF<double>>, "HelixSDF<double> must be trivially copyable");
7823static_assert(std::is_trivially_copyable_v<LatticeSDF<float>>, "LatticeSDF<float> must be trivially copyable");
7824static_assert(std::is_trivially_copyable_v<LatticeSDF<double>>, "LatticeSDF<double> must be trivially copyable");
7825
7826} // namespace EBGeometry
7827
7828// Profiles turned or extruded (ProfileSDF), in a header of their own.
7829#include "EBGeometry_Profile.hpp"
7830
7831// Every translation unit that sees these shapes sees their ray forms too, so firstHit() on one of them
7832// is the same function everywhere.
7834
7835#endif
bool isFinite(const Vec3T< T > &a_point) noexcept
Checks that a point given to a constructor is finite.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2409
T ellipsoidDistance(const T a_e0, const T a_e1, const T a_e2, const T a_y0, const T a_y1, const T a_y2) noexcept
The distance from a point to an ellipsoid with semi-axes a_e0 >= a_e1 >= a_e2 > 0,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2557
T superellipsoidScale(const Vec3T< T > &a_radii, const T a_exponent1, const T a_exponent2) noexcept
One over the largest slope of a superellipsoid's gauge: its smallest semi-axis, over the largest rati...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6177
T pNorm(const T a_a, const T a_b, const T a_p) noexcept
The p-norm (|a|^p + |b|^p)^(1/p) of two values at least 0, scaled by the larger so that no power over...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6149
T hyperbolaDistance(const T a_A, const T a_B, const T a_x, const T a_y) noexcept
The distance from a point to the branch X^2 / A^2 - Y^2 / B^2 = 1, X > 0, of a hyperbola,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6007
T parabolaDistance(const T a_rho, const T a_r, const T a_y) noexcept
The distance from a point to the parabola y = -r^2 / (2 rho), for a point with coordinates a_r >= 0 a...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6105
double helixTurnDistance(const double a_radius, const double a_pitch)
The closest distance between a helix' center line and its neighboring turns: twice the largest tube r...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6198
T extrusion(const T a_profile, const T a_slab) noexcept
The signed distance to a 2D profile extruded between two parallel planes: the exact distance,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2391
T ellipsoidRoot(const T(&a_r)[N], const T(&a_n)[N], const T a_lo, const T a_hi) noexcept
The root of Eberly's function F(s) = sum_i (a_n[i] / (s + a_r[i]))^2 - 1 over the components with a_n...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2434
AxialCoordinates< T > axialCoordinates(const Vec3T< T > &a_point, const Vec3T< T > &a_start, const Vec3T< T > &a_axis) noexcept
A point's coordinates around the axis that starts at a_start and runs along the unit a_axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2371
T ellipseDistance(const T a_e0, const T a_e1, const T a_y0, const T a_y1) noexcept
The distance from a point to an ellipse with semi-axes a_e0 >= a_e1 > 0, for a point with coordinates...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2496
PolyhedronTopology polyhedronTopology(const std::vector< Vec3T< double > > &a_normals, const std::vector< double > &a_offsets, const double a_epsilon, const double a_magnitude, const char *a_who)
Finds the vertices and edges of the convex polyhedron behind a set of planes, and checks that every p...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5313
Ray forms (see RayForm) for the analytic shapes that have a closed-form crossing: PlaneSDF,...
A fixed-size array that compiles for both host and device.
Declarations of bounding volume types used in bounding volume hierarchies.
Mathematical constants for EBGeometry.
How far a function's value can be trusted as a distance: DistanceQuality, and the distanceQualityOf t...
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_DEVICE_NOINLINE
Keep a function out of line in the device pass (CUDA/HIP); nothing on the host.
Definition EBGeometry_GPU.hpp:110
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
Utility macros for EBGeometry.
#define EBGEOMETRY_REQUIRE(cond,...)
Always-on check of user input and one-time host setup.
Definition EBGeometry_Macros.hpp:200
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:269
Scalar helpers and numeric limits that compile for both host and device.
Profiles: closed outlines of straight edges, circular arcs and quadratic Bezier curves in a plane (Pr...
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Signed distance field for the frame of a box: its twelve edges, as bars of square cross-section.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5125
Vec3T< T > barTerms(const Vec3T< T > &a_point) const noexcept
The three bars that meet at the corner of the octant a point is in: the signed distance to the one al...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5895
BoxFrameSDF & operator=(BoxFrameSDF &&)=default
Move assignment.
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): the nearest bar, 4 a + 2 i + j for t...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5964
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the frame.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5926
const Vec3T< T > & getHighCorner() const noexcept
Get the upper corner of the box the frame fits.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5188
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: the box the frame fits.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5241
BoxFrameSDF(const BoxFrameSDF &)=default
Copy constructor.
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): its twelve bars.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5219
const Vec3T< T > & getLowCorner() const noexcept
Get the lower corner of the box the frame fits.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5177
const T & getThickness() const noexcept
Get the thickness of a bar.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5199
BoxFrameSDF()=default
Default constructor. Constructs the frame of the cube [-0.5, 0.5]^3, with bars 0.1 thick.
BoxFrameSDF & operator=(const BoxFrameSDF &)=default
Copy assignment.
BoxFrameSDF(BoxFrameSDF &&)=default
Move constructor.
Signed distance field for an axis-aligned box (AABB).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:360
BoxSDF & operator=(const BoxSDF &)=default
Copy assignment.
BoxSDF()=default
Default constructor. Constructs a unit cube centered at the origin: [-0.5, 0.5]^3.
BoxSDF(const BoxSDF &)=default
Copy constructor.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:541
Vec3T< T > m_loCorner
Low box corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:550
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 6.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:511
Vec3T< T > & getHighCorner() noexcept
Get upper-right corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:469
Vec3T< T > & getLowCorner() noexcept
Get lower-left corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:447
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 2 axis + 0 for the face at the low c...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:523
BoxSDF & operator=(BoxSDF &&)=default
Move assignment.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the axis-aligned box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:481
const Vec3T< T > & getHighCorner() const noexcept
Get upper-right corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:458
const Vec3T< T > & getLowCorner() const noexcept
Get lower-left corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:436
Vec3T< T > m_hiCorner
High box corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:555
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:367
BoxSDF(const Vec3T< T > &a_loCorner, const Vec3T< T > &a_hiCorner)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:380
BoxSDF(BoxSDF &&)=default
Move constructor.
Signed distance field for a capped cone (a frustum): a cone cut flat at both ends,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2790
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2797
CappedConeSDF(const CappedConeSDF &)=default
Copy constructor.
Vec3T< T > m_center1
Center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3012
CappedConeSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_radius1, const T a_radius2)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2811
Vec3T< T > m_axis
Unit axis from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3022
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2950
CappedConeSDF()=default
Default constructor. Constructs a frustum from (0,-0.5,0) with radius 1 to (0,0.5,...
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2993
const T & getRadius2() const noexcept
Get the radius at m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2905
const Vec3T< T > & getCenter1() const noexcept
Get the center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2872
T m_length
Distance between the end centers.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3027
T m_radius1
Radius at m_center1.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3032
const Vec3T< T > & getCenter2() const noexcept
Get the center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2883
CappedConeSDF(CappedConeSDF &&)=default
Move constructor.
CappedConeSDF & operator=(const CappedConeSDF &)=default
Copy assignment.
T m_radius2
Radius at m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3037
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the slanted side,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2962
Vec3T< T > m_center2
Center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3017
const T & getRadius1() const noexcept
Get the radius at m_center1.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2894
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the frustum.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2917
CappedConeSDF & operator=(CappedConeSDF &&)=default
Move assignment.
Signed distance field for a capped torus: an arc of a torus with flat ends, such as a pipe elbow.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3856
T m_angle
The angle the arc sweeps, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4102
const T & getMinorRadius() const noexcept
Get the minor (tube) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3954
T m_minorRadius
Minor (tube) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4097
T m_majorRadius
Major (ring) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4092
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4070
const T & getAngle() const noexcept
Get the angle the arc sweeps, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3965
CappedTorusSDF(const CappedTorusSDF &)=default
Copy constructor.
CappedTorusSDF()=default
Default constructor. Constructs an arc of 90 degrees, centered at the origin, with major radius 1 and...
CappedTorusSDF(CappedTorusSDF &&)=default
Move constructor.
T m_sin
Sine of half the arc's angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4112
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3863
T m_cos
Cosine of half the arc's angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4107
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4020
const Vec3T< T > & getCenter() const noexcept
Get the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3932
Vec3T< T > m_center
Center of the torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4087
CappedTorusSDF & operator=(CappedTorusSDF &&)=default
Move assignment.
CappedTorusSDF(const Vec3T< T > &a_center, const T a_majorRadius, const T a_minorRadius, const T a_angle)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3878
bool m_whole
Whether the arc is the whole torus, with no ends.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4117
const T & getMajorRadius() const noexcept
Get the major (ring) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3943
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the tube, 1 the end disc at the po...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4032
CappedTorusSDF & operator=(const CappedTorusSDF &)=default
Copy assignment.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the capped torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3977
Signed distance field for a capsule (pill shape): a cylinder capped with hemispheres.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1186
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1193
const Vec3T< T > & getCenter2() const noexcept
Get the center of the second hemispherical cap.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1348
CapsuleSDF & operator=(const CapsuleSDF &)=default
Copy assignment.
Vec3T< T > m_center2
Center of the other hemispherical cap.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1373
CapsuleSDF()=default
Default constructor. Constructs a capsule with tips at (0,-1,0) and (0,1,0), radius 0....
const T & getRadius() const noexcept
Get the radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1359
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1325
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the side, 1 the hemisphere at the ...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1308
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the capsule.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1271
CapsuleSDF(const CapsuleSDF &)=default
Copy constructor.
CapsuleSDF & operator=(CapsuleSDF &&)=default
Move assignment.
T m_radius
Capsule radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1378
CapsuleSDF(const Vec3T< T > &a_tip1, const Vec3T< T > &a_tip2, const T &a_radius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1213
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1296
const Vec3T< T > & getCenter1() const noexcept
Get the center of the first hemispherical cap.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1337
CapsuleSDF(CapsuleSDF &&)=default
Move constructor.
Vec3T< T > m_center1
Center of one hemispherical cap.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1368
Signed distance field for a finite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1524
ConeSDF()=default
Default constructor. Constructs a finite cone with its tip at the origin, height 1,...
Vec3T< T > m_tip
Tip position.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1673
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1661
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the finite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1595
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1630
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the slanted side,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1642
ConeSDF & operator=(ConeSDF &&)=default
Move assignment.
ConeSDF & operator=(const ConeSDF &)=default
Copy assignment.
ConeSDF(ConeSDF &&)=default
Move constructor.
T m_height
Cone height (tip to base).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1683
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1531
ConeSDF(const ConeSDF &)=default
Copy constructor.
ConeSDF(const Vec3T< T > &a_tip, const T &a_height, const T &a_angle)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1545
Vec2T< T > m_c
(sin, cos) of the half opening-angle. Default: 45° full angle → half-angle 22.5°.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1678
Signed distance field for a convex polyhedron: the intersection of the half-spaces behind a set of pl...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4757
static ConvexPolyhedronSDF fromNormals(const Vec3T< T > &a_center, const std::vector< Vec3T< T > > &a_vertexDirections, const std::vector< Vec3T< T > > &a_normals, T a_radius, const char *a_who)
A regular solid from the directions of its vertices and of its faces' normals: each face's plane is a...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5532
static std::vector< Vec3T< T > > goldenDirections(T a_small, T a_large)
The twelve directions (0, +-a, +-b), (+-a, +-b, 0) and (+-b, 0, +-a), in that order,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5621
ConvexPolyhedronSDF()
Default constructor. Constructs the cube [-0.5, 0.5]^3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5441
ConvexPolyhedronSDF & operator=(ConvexPolyhedronSDF &&)=default
Move assignment.
const T & getOffset(const uint32_t a_face) const noexcept
Get the offset of a face's plane: the plane is the points x with dot(getNormal(a_face),...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4930
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): the face whose plane is farthest abo...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5775
static ConvexPolyhedronSDF dodecahedron(const Vec3T< T > &a_center, T a_radius)
A regular dodecahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5648
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: that of its vertices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5843
const Vec3T< T > & getNormal(const uint32_t a_face) const noexcept
Get the unit outward normal of a face.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4916
static constexpr uint32_t MaxEdges
The most edges a polyhedron can have, from Euler's formula: MaxFaces + MaxVertices - 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4779
ConvexPolyhedronSDF(ConvexPolyhedronSDF &&)=default
Move constructor.
uint32_t getNumFaces() const noexcept
Get the number of faces.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4904
Array< Vec3T< T >, MaxVertices > m_vertices
The vertices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5105
Array< Vec3T< T >, MaxFaces > m_normals
Unit outward normal of each face.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5095
static std::vector< PlaneSDF< T > > cubePlanes()
The six planes of the cube [-0.5, 0.5]^3, the default polyhedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5423
static constexpr uint32_t MaxFaces
The most faces a polyhedron can have: those of the icosahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4769
uint32_t getEdgeVertex(const uint32_t a_edge, const uint32_t a_end) const noexcept
Get one end of an edge.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4981
uint32_t getNumVertices() const noexcept
Get the number of vertices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4943
static ConvexPolyhedronSDF tetrahedron(const Vec3T< T > &a_center, T a_radius)
A regular tetrahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5584
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4764
void build(const std::vector< Vec3T< double > > &a_points, const std::vector< Vec3T< double > > &a_normals, double a_epsilon)
Sets the polyhedron to the one bounded by planes given in double precision: finds its vertices and ed...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5460
ConvexPolyhedronSDF(const ConvexPolyhedronSDF &)=default
Copy constructor.
static constexpr uint32_t MaxVertices
The most vertices a polyhedron can have: those of the dodecahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4774
uint32_t m_numVertices
Number of vertices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5085
uint32_t m_numEdges
Number of edges.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5090
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): its faces, getNumFaces().
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5007
uint32_t m_numFaces
Number of faces.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5080
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the polyhedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5795
Array< T, MaxFaces > m_offsets
Offset of each face's plane along its normal.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5100
Array< uint8_t, 2U *MaxEdges > m_edges
The edges, as the indices of their two vertices: edge e from m_edges[2 e] to m_edges[2 e + 1].
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5110
static ConvexPolyhedronSDF icosahedron(const Vec3T< T > &a_center, T a_radius)
A regular icosahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5667
ConvexPolyhedronSDF & operator=(const ConvexPolyhedronSDF &)=default
Copy assignment.
const Vec3T< T > & getVertex(const uint32_t a_vertex) const noexcept
Get a vertex.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4955
static ConvexPolyhedronSDF pyramid(const Vec3T< T > &a_baseCenter, const Vec3T< T > &a_apex, T a_radius, unsigned a_sides, const Vec3T< T > &a_vertexDirection)
A right pyramid on a regular polygon: a square pyramid with four sides, a tetrahedron-like one with t...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5686
static ConvexPolyhedronSDF octahedron(const Vec3T< T > &a_center, T a_radius)
A regular octahedron.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5602
uint32_t getNumEdges() const noexcept
Get the number of edges.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4968
Signed distance field for a cut hollow sphere: a spherical shell of some thickness,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4341
T m_radius
Radius of the shell's middle surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4531
CutHollowSphereSDF & operator=(const CutHollowSphereSDF &)=default
Copy assignment.
CutHollowSphereSDF(const Vec3T< T > &a_center, const T a_radius, const T a_height, const T a_thickness)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4363
CutHollowSphereSDF(const CutHollowSphereSDF &)=default
Copy constructor.
CutHollowSphereSDF(CutHollowSphereSDF &&)=default
Move constructor.
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4487
T m_height
Height of the cut plane above the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4536
const T & getRadius() const noexcept
Get the radius of the shell's middle surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4430
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4513
CutHollowSphereSDF & operator=(CutHollowSphereSDF &&)=default
Move assignment.
CutHollowSphereSDF()=default
Default constructor. Constructs the upper half of a shell of thickness 0.1 around the unit sphere at ...
Vec3T< T > m_center
Center of the sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4526
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4348
T m_rim
Radius of the rim, sqrt(radius^2 - height^2).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4546
const T & getHeight() const noexcept
Get the height of the cut plane above the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4441
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the shell, 1 its rounded rim.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4499
const Vec3T< T > & getCenter() const noexcept
Get the center of the sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4419
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the cut hollow sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4464
T m_thickness
The shell's thickness.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4541
const T & getThickness() const noexcept
Get the shell's thickness.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4452
Signed distance field for a cut sphere: the part of a sphere above a horizontal plane,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4131
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4268
CutSphereSDF & operator=(const CutSphereSDF &)=default
Copy assignment.
const T & getHeight() const noexcept
Get the height of the cut plane above the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4224
T m_radius
Radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4315
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the cut sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4236
CutSphereSDF(const CutSphereSDF &)=default
Copy constructor.
const T & getRadius() const noexcept
Get the radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4213
CutSphereSDF()=default
Default constructor. Constructs the upper half of the unit sphere at the origin.
CutSphereSDF(CutSphereSDF &&)=default
Move constructor.
CutSphereSDF(const Vec3T< T > &a_center, const T a_radius, const T a_height)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4151
T m_rim
Radius of the rim, sqrt(radius^2 - height^2).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4325
CutSphereSDF & operator=(CutSphereSDF &&)=default
Move assignment.
Vec3T< T > m_center
Center of the sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4310
T m_height
Height of the cut plane above the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4320
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4138
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the sphere, 1 the flat cut face (i...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4280
const Vec3T< T > & getCenter() const noexcept
Get the center of the sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4202
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4298
Signed distance field for a finite, flat-capped cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:766
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:962
T m_length
Distance between the two endpoints.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:997
Vec3T< T > m_center1
One endpoint (cap center).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:977
const Vec3T< T > & getCenter2() const noexcept
Get the other endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:858
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:881
Vec3T< T > m_center2
Other endpoint (cap center).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:982
CylinderSDF()=default
Default constructor. Constructs a unit cylinder of radius 1 and height 1, centered at the origin with...
CylinderSDF(const CylinderSDF &)=default
Copy constructor.
Vec3T< T > m_center
Midpoint of m_center1 and m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:987
const T & getRadius() const noexcept
Get radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:869
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:929
CylinderSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T &a_radius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:787
Vec3T< T > m_axis
Unit axis pointing from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:992
const Vec3T< T > & getCenter1() const noexcept
Get one endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:847
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:773
T m_radius
Cylinder radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1002
CylinderSDF(CylinderSDF &&)=default
Move constructor.
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the side, 1 the cap at the first c...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:941
CylinderSDF & operator=(CylinderSDF &&)=default
Move assignment.
CylinderSDF & operator=(const CylinderSDF &)=default
Copy assignment.
Signed distance field for an ellipsoid with its semi-axes along x, y and z.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2632
EllipsoidSDF & operator=(EllipsoidSDF &&)=default
Move assignment.
EllipsoidSDF & operator=(const EllipsoidSDF &)=default
Copy assignment.
EllipsoidSDF(const Vec3T< T > &a_center, const Vec3T< T > &a_radii)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2651
Vec3T< T > m_radii
Semi-axes along x, y and z.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2776
EllipsoidSDF(const EllipsoidSDF &)=default
Copy constructor.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2639
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2762
EllipsoidSDF()=default
Default constructor. Constructs the unit sphere at the origin.
const Vec3T< T > & getCenter() const noexcept
Get the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2698
const Vec3T< T > & getRadii() const noexcept
Get the semi-axes.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2709
Vec3T< T > m_center
Center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2771
EllipsoidSDF(EllipsoidSDF &&)=default
Move constructor.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the ellipsoid.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2723
Signed distance field for a helical tube: a spring, a coil or a thread, with rounded ends.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7120
HelixSDF(HelixSDF &&)=default
Move constructor.
T m_helixRadius
The helix radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7512
HelixSDF & operator=(const HelixSDF &)=default
Copy assignment.
const Vec3T< T > & getStartDirection() const noexcept
Get the unit direction from the axis to the center line at the first end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7289
Vec3T< T > centerLine(const T a_angle) const noexcept
Get the point on the center line at a helix angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7301
T m_tubeRadius
The tube's radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7522
Vec3T< T > m_center2
The axis point at the second end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7497
HelixSDF & operator=(HelixSDF &&)=default
Move assignment.
const Vec3T< T > & getCenter1() const noexcept
Get the axis point at the first end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7234
T m_turns
The number of turns.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7517
Vec3T< T > m_start
Unit direction to the center line at the first end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7507
const T & getTubeRadius() const noexcept
Get the tube radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7278
Vec3T< T > m_center1
The axis point at the first end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7492
HelixSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_helixRadius, const T a_turns, const T a_tubeRadius, const Vec3T< T > &a_startDirection)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7146
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the helix.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7316
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7127
const T & getTurns() const noexcept
Get the number of turns.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7267
const T & getHelixRadius() const noexcept
Get the helix radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7256
const Vec3T< T > & getCenter2() const noexcept
Get the axis point at the second end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7245
Vec3T< T > m_axis
Unit axis from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7502
T windowMinimum(const T a_k, const T a_rho, const T a_phi, const T a_y, const T a_rate, const T a_last) const noexcept
The smallest squared distance from a point to the center line over one window of helix angles,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7418
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: that of the cylinder the tube fits in.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7389
HelixSDF()=default
Default constructor. Constructs a helix from (0,-1,0) to (0,1,0) in 4 turns of radius 0....
HelixSDF(const HelixSDF &)=default
Copy constructor.
Signed distance field for an infinite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1398
InfiniteConeSDF(const InfiniteConeSDF &)=default
Copy constructor.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1489
InfiniteConeSDF()=default
Default constructor. Constructs an infinite cone with tip at the origin, 45° full opening angle,...
Vec3T< T > m_tip
Tip position.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1502
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1405
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the infinite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1466
InfiniteConeSDF(const Vec3T< T > &a_tip, const T &a_angle)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1419
Vec2T< T > m_c
(sin, cos) of the half opening-angle. Default: 45° full angle → half-angle 22.5°.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1507
InfiniteConeSDF(InfiniteConeSDF &&)=default
Move constructor.
InfiniteConeSDF & operator=(InfiniteConeSDF &&)=default
Move assignment.
InfiniteConeSDF & operator=(const InfiniteConeSDF &)=default
Copy assignment.
Signed distance field for an infinitely long cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1016
T m_radius
Cylinder radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1159
InfiniteCylinderSDF & operator=(const InfiniteCylinderSDF &)=default
Copy assignment.
InfiniteCylinderSDF(const Vec3T< T > &a_center, const T &a_radius, const size_t a_axis)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1037
const size_t & getAxis() const noexcept
Get the coordinate axis the cylinder runs along.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1145
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the infinite cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1085
InfiniteCylinderSDF(const InfiniteCylinderSDF &)=default
Copy constructor.
Vec3T< T > m_center
Center point on the cylinder axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1154
InfiniteCylinderSDF(InfiniteCylinderSDF &&)=default
Move constructor.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1106
const Vec3T< T > & getCenter() const noexcept
Get the point on the axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1123
InfiniteCylinderSDF()=default
Default constructor. Constructs an infinite cylinder of radius 1 centered at the origin with its axis...
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1023
size_t m_axis
Coordinate axis index (0 = x, 1 = y, 2 = z).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1164
const T & getRadius() const noexcept
Get the radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1134
InfiniteCylinderSDF & operator=(InfiniteCylinderSDF &&)=default
Move assignment.
Signed distance field for a lattice of walls along a triply periodic minimal surface: a gyroid,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7538
LatticeSDF()=default
Default constructor. Constructs a gyroid of unit cells, with walls 0.1 thick.
T m_scale
One over the field's largest slope in space.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7743
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the lattice: a bound.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7702
Kind
Which surface, in coordinates scaled so that a cell is 2 pi.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7551
@ Neovius
3 (cos x + cos y + cos z) + 4 cos x cos y cos z.
@ SchwarzP
cos x + cos y + cos z.
@ Gyroid
sin x cos y + sin y cos z + sin z cos x.
@ SchwarzD
The diamond: sin x sin y sin z + sin x cos y cos z + cos x sin y cos z + cos x cos y sin z.
LatticeSDF(const Kind a_kind, const Vec3T< T > &a_cellSize, const T a_thickness)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7570
LatticeSDF(LatticeSDF &&)=default
Move constructor.
T field(const Vec3T< T > &a_point) const noexcept
The surface's field f at a point, zero on the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7664
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: unbounded.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7717
Vec3T< T > m_cellSize
The cell size.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7733
Kind getKind() const noexcept
Get which surface this is.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7626
LatticeSDF(const LatticeSDF &)=default
Copy constructor.
const T & getThickness() const noexcept
Get the walls' thickness.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7648
LatticeSDF & operator=(LatticeSDF &&)=default
Move assignment.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: never more than the Euclidean distance.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7545
LatticeSDF & operator=(const LatticeSDF &)=default
Copy assignment.
T m_thickness
The walls' thickness.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7738
const Vec3T< T > & getCellSize() const noexcept
Get the cell size.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7637
Kind m_kind
Which surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7728
Ken Perlin's gradient-noise implicit function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1871
PerlinSDF(const T a_noiseAmplitude, const Vec3T< T > a_noiseFrequency, const T a_noisePersistence, const unsigned int a_noiseOctaves)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1896
Array< int, 512 > m_permutationTable
Integer hash permutation table (512 entries: [0..255] mirrored).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2052
unsigned int m_noiseOctaves
Number of noise octaves.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2057
Vec3T< T > m_noiseFrequency
Spatial noise frequency along each Cartesian axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2035
PerlinSDF & operator=(const PerlinSDF &)=default
Copy assignment.
PerlinSDF(const PerlinSDF &)=default
Copy constructor.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: not at all. The value is noise,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1879
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function. Generates a noise value on [0, m_noiseAmplitude] for one octave.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1960
T noise(const Vec3T< T > &a_point) const noexcept
Single-octave Perlin noise evaluation.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2110
T grad(const int hash, const T x, const T y, const T z) const noexcept
Ken Perlin's gradient hash function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2095
T lerp(const T t, const T a, const T b) const noexcept
Ken Perlin's linear interpolation helper.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2068
Array< int, 512 > & getPermutationTable() noexcept
Get the internal permutation table.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2014
PerlinSDF(PerlinSDF &&)=default
Move constructor.
T fade(const T t) const noexcept
Ken Perlin's fade (smoothstep) function: 6t^5 - 15t^4 + 10t^3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2080
PerlinSDF & operator=(PerlinSDF &&)=default
Move assignment.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2026
T m_noiseAmplitude
Noise amplitude (output scale).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2040
PerlinSDF() noexcept
Default constructor. Constructs a single-octave Perlin noise field with unit amplitude,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1885
T m_noisePersistence
Per-octave amplitude decay factor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2045
void shuffle(URNG &g) noexcept
Shuffle the permutation table with the provided uniform random number generator.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1995
Signed distance function for a plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:69
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:76
const Vec3T< T > & getPoint() const noexcept
Get the point on the plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:171
PlaneSDF()=default
Default constructor. Constructs the y = 0 plane with outward normal (0, 1, 0).
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:160
PlaneSDF(const Vec3T< T > &a_point, const Vec3T< T > &a_normal)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:90
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:143
PlaneSDF(const PlaneSDF &)=default
Copy constructor.
const Vec3T< T > & getNormal() const noexcept
Get the unit normal of the plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:182
PlaneSDF & operator=(PlaneSDF &&)=default
Move assignment.
PlaneSDF(PlaneSDF &&)=default
Move constructor.
Vec3T< T > m_point
Point on plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:191
Vec3T< T > m_normal
Plane normal vector (unit length).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:196
PlaneSDF & operator=(const PlaneSDF &)=default
Copy assignment.
Signed distance field for a regular prism: a regular polygon of n sides, extruded between two end cen...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3305
Vec3T< T > m_center2
Center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3577
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the prism.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3494
Vec3T< T > m_side
Unit direction across the axis and m_vertex, cross(m_axis, m_vertex).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3592
T m_length
Distance between the end centers.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3597
Vec3T< T > m_vertex
Unit direction from the axis toward the first vertex.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3587
Vec3T< T > m_axis
Unit axis from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3582
const Vec3T< T > & getCenter2() const noexcept
Get the center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3416
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3557
PolygonPrismSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_radius, const unsigned a_sides, const Vec3T< T > &a_vertexDirection)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3329
Vec3T< T > m_center1
Center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3572
PolygonPrismSDF & operator=(PolygonPrismSDF &&)=default
Move assignment.
T m_radius
Circumradius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3602
unsigned m_sides
Number of sides.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3607
PolygonPrismSDF(const PolygonPrismSDF &)=default
Copy constructor.
PolygonPrismSDF()=default
Default constructor. Constructs a hexagonal prism from (0,-0.5,0) to (0,0.5,0), of circumradius 1,...
const T & getRadius() const noexcept
Get the circumradius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3427
const Vec3T< T > & getCenter1() const noexcept
Get the center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3405
const Vec3T< T > & getVertexDirection() const noexcept
Get the unit direction from the axis toward the first vertex, across the axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3449
PolygonPrismSDF & operator=(const PolygonPrismSDF &)=default
Copy assignment.
T polygonDistance(const T a_u, const T a_v) const noexcept
The signed distance to the polygon in the cross-section, at coordinates a_u along the vertex directio...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3467
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): the sides and the two caps, getSides() + 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3513
unsigned getSides() const noexcept
Get the number of sides.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3438
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): the side k from 0 to getSides() - 1,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3525
PolygonPrismSDF(PolygonPrismSDF &&)=default
Move constructor.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3312
Signed distance field for a quadric of revolution around y: a hyperboloid of one sheet,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6269
QuadricSDF(QuadricSDF &&)=default
Move constructor.
const T & getA() const noexcept
Get the semi-axis across y, a, of a hyperboloid, or the tip radius of a paraboloid.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6406
T m_a
The semi-axis across y, a (a hyperboloid), or the tip radius rho (a paraboloid).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6516
static QuadricSDF hyperboloid(const Vec3T< T > &a_center, const T a_waist, const T a_angle)
A hyperboloid of one sheet around the y axis through the center: a waisted tower, unbounded along y.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6303
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6276
Kind m_kind
Which quadric.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6506
QuadricSDF(const QuadricSDF &)=default
Copy constructor.
const Vec3T< T > & getCenter() const noexcept
Get the center (a hyperboloid) or the tip (a paraboloid).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6395
QuadricSDF & operator=(const QuadricSDF &)=default
Copy assignment.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: unbounded, but above the tip of a paraboloid.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6465
static QuadricSDF paraboloid(const Vec3T< T > &a_tip, const T a_tipRadius)
A paraboloid around the y axis through its tip, opening toward -y, as the cones do,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6343
T m_c
The semi-axis along y, c (a hyperboloid); the tip radius for a paraboloid.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6521
QuadricSDF()=default
Default constructor. Constructs the paraboloid with its tip at the origin, opening toward -y,...
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the quadric.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6429
Vec3T< T > m_center
The center (a hyperboloid) or the tip (a paraboloid).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6511
Kind getKind() const noexcept
Get which quadric this is.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6384
QuadricSDF & operator=(QuadricSDF &&)=default
Move assignment.
static QuadricSDF hyperboloidTwoSheets(const Vec3T< T > &a_center, const T a_tipDistance, const T a_angle)
A hyperboloid of two sheets around the y axis through the center: two cups, with their tips on the ax...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6324
const T & getC() const noexcept
Get the semi-axis along y, c, of a hyperboloid; for a paraboloid, its tip radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6417
static QuadricSDF checked(const Vec3T< T > &a_center, const T a_size, const T a_angle, const char *a_who)
Checks a factory's arguments, and makes a quadric at the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6483
Kind
Which quadric, with r the distance from the axis and y the height above the center (or the tip).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6282
@ HyperboloidOneSheet
r^2 / a^2 - y^2 / c^2 <= 1: a waisted tower, one piece.
@ HyperboloidTwoSheets
y^2 / c^2 - r^2 / a^2 >= 1: two cups facing away from each other.
@ Paraboloid
y <= -r^2 / (2 rho): a cup opening toward -y from its tip.
Signed distance field for a round cone: two spheres, of different radii, and the cone tangent to both...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3051
RoundConeSDF & operator=(RoundConeSDF &&)=default
Move assignment.
const T & getRadius1() const noexcept
Get the radius of the sphere at m_center1.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3160
const T & getRadius2() const noexcept
Get the radius of the sphere at m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3171
T m_cos
Cosine of the cone's half-angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3288
RoundConeSDF()=default
Default constructor. Constructs a round cone from (0,-0.5,0) with radius 0.5 to (0,...
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3058
RoundConeSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_radius1, const T a_radius2)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3074
Vec3T< T > m_axis
Unit axis from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3263
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the slanted side,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3227
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3215
Vec3T< T > m_center2
Center of the other sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3258
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: the box around the two spheres.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3242
RoundConeSDF(RoundConeSDF &&)=default
Move constructor.
RoundConeSDF(const RoundConeSDF &)=default
Copy constructor.
T m_radius2
Radius of the sphere at m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3278
T m_length
Distance between the centers.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3268
const Vec3T< T > & getCenter2() const noexcept
Get the center of the other sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3149
RoundConeSDF & operator=(const RoundConeSDF &)=default
Copy assignment.
T m_sin
Sine of the cone's half-angle, (m_radius1 - m_radius2) / m_length.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3283
Vec3T< T > m_center1
Center of one sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3253
T m_radius1
Radius of the sphere at m_center1.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3273
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the round cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3185
const Vec3T< T > & getCenter1() const noexcept
Get the center of one sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3138
Signed distance field for an axis-aligned box with rounded edges and corners.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1696
RoundedBoxSDF()=default
Default constructor. Constructs a rounded unit cube, [-0.5, 0.5]^3, centered at the origin,...
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1828
T m_curvature
Corner rounding radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1839
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1703
RoundedBoxSDF & operator=(RoundedBoxSDF &&)=default
Move assignment.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the rounded box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1773
RoundedBoxSDF(const Vec3T< T > &a_center, const Vec3T< T > &a_size, const T a_curvature)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1718
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 2 axis + 0 for the face on the negat...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1810
RoundedBoxSDF(const RoundedBoxSDF &)=default
Copy constructor.
Vec3T< T > m_dimensions
Half-extents of the inner box (= 0.5 * outer size - curvature).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1849
Vec3T< T > m_center
Box center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1844
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 6.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1798
RoundedBoxSDF(RoundedBoxSDF &&)=default
Move constructor.
RoundedBoxSDF & operator=(const RoundedBoxSDF &)=default
Copy assignment.
Signed distance field for a cylinder with rounded (toroidal) edges.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2173
RoundedCylinderSDF(RoundedCylinderSDF &&)=default
Move constructor.
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2307
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the side, 1 the cap at -y,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2290
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2180
RoundedCylinderSDF & operator=(RoundedCylinderSDF &&)=default
Move assignment.
RoundedCylinderSDF(const RoundedCylinderSDF &)=default
Copy constructor.
T m_height
Inner half-height (= 0.5*height - curvature).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2334
RoundedCylinderSDF & operator=(const RoundedCylinderSDF &)=default
Copy assignment.
Vec3T< T > m_center
Cylinder center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2319
T m_majorRadius
Inner cylinder radius (= outer radius - curvature).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2324
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the rounded cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2258
RoundedCylinderSDF(const Vec3T< T > &a_center, const T a_radius, const T a_curvature, const T a_height)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2196
T m_minorRadius
Edge rounding radius (= curvature).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2329
RoundedCylinderSDF()=default
Default constructor. Constructs a rounded cylinder centered at the origin, axis along y,...
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 3.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2278
Signed distance field for a solid angle: the part of a ball inside a cone from its center,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6716
SolidAngleSDF(SolidAngleSDF &&)=default
Move constructor.
const T & getAngle() const noexcept
Get the full opening angle, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6808
SolidAngleSDF & operator=(const SolidAngleSDF &)=default
Copy assignment.
T m_cos
Cosine of half the opening angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6920
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6723
SolidAngleSDF()=default
Default constructor. Constructs a solid angle at the origin, with radius 1 and an opening of 60 degre...
SolidAngleSDF(const Vec3T< T > &a_center, const T a_radius, const T a_angle)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6736
const Vec3T< T > & getCenter() const noexcept
Get the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6786
T m_radius
Radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6905
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: that of the ball.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6868
SolidAngleSDF(const SolidAngleSDF &)=default
Copy constructor.
T m_angle
Full opening angle, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6910
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the cap, 1 the cone's side.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6852
const T & getRadius() const noexcept
Get the radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6797
Vec3T< T > m_center
Center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6900
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the solid angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6820
SolidAngleSDF & operator=(SolidAngleSDF &&)=default
Move assignment.
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 2, the spherical cap (0) and the cone's side (1).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6840
T m_sin
Sine of half the opening angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6915
void terms(const Vec3T< T > &a_point, T &a_sphere, T &a_side) const noexcept
The two terms of the distance: to the sphere, and the signed distance to the cone's side segment.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6882
Signed distance field for a sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:208
Vec3T< T > & getCenter() noexcept
Get sphere center (mutable).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:283
SphereSDF()=default
Default constructor. Constructs a unit sphere centered at the origin.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:317
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:333
SphereSDF & operator=(SphereSDF &&)=default
Move assignment.
SphereSDF & operator=(const SphereSDF &)=default
Copy assignment.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:215
const Vec3T< T > & getCenter() const noexcept
Get sphere center (const).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:272
Vec3T< T > m_center
Sphere center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:342
T m_radius
Sphere radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:347
const T & getRadius() const noexcept
Get sphere radius (const).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:294
SphereSDF(SphereSDF &&)=default
Move constructor.
SphereSDF(const SphereSDF &)=default
Copy constructor.
T & getRadius() noexcept
Get sphere radius (mutable).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:305
SphereSDF(const Vec3T< T > &a_center, const T &a_radius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:227
Signed distance field for a superellipsoid (Barr's superquadric): from an ellipsoid to a rounded box,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6538
const Vec3T< T > & getRadii() const noexcept
Get the semi-axes.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6624
SuperellipsoidSDF & operator=(const SuperellipsoidSDF &)=default
Copy assignment.
T gauge(const Vec3T< T > &a_point) const noexcept
The superquadric's gauge at a point: below 1 inside, 1 on the surface, above 1 outside.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6640
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the superellipsoid: a bound.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6659
T m_scale
One over the gauge's largest slope.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6703
SuperellipsoidSDF(const Vec3T< T > &a_center, const Vec3T< T > &a_radii, const T a_exponent1, const T a_exponent2)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6559
T m_exponent2
The exponent across it.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6698
SuperellipsoidSDF()=default
Default constructor. Constructs a superellipsoid at the origin, with semi-axes 1 and both exponents 0...
SuperellipsoidSDF(const SuperellipsoidSDF &)=default
Copy constructor.
SuperellipsoidSDF & operator=(SuperellipsoidSDF &&)=default
Move assignment.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: never more than the Euclidean distance.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6545
SuperellipsoidSDF(SuperellipsoidSDF &&)=default
Move constructor.
Vec3T< T > m_center
Center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6683
Vec3T< T > m_radii
Semi-axes.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6688
T m_exponent1
The exponent through the y axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6693
const Vec3T< T > & getCenter() const noexcept
Get the center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6613
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: the center plus and minus the semi-axes.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6674
Signed distance field for a torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:571
TorusSDF & operator=(const TorusSDF &)=default
Copy assignment.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:710
T m_minorRadius
Minor (tube) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:752
Vec3T< T > & getCenter() noexcept
Get torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:655
T m_majorRadius
Major (ring) radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:747
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:578
const T & getMinorRadius() const noexcept
Get minor radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:688
TorusSDF(TorusSDF &&)=default
Move constructor.
TorusSDF(const TorusSDF &)=default
Copy constructor.
const T & getMajorRadius() const noexcept
Get major radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:666
T & getMajorRadius() noexcept
Get major radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:677
Vec3T< T > m_center
Torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:742
TorusSDF(const Vec3T< T > &a_center, const T &a_majorRadius, const T &a_minorRadius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:591
TorusSDF & operator=(TorusSDF &&)=default
Move assignment.
T & getMinorRadius() noexcept
Get minor radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:699
TorusSDF()=default
Default constructor. Constructs a torus centered at the origin with major radius 1 and minor radius 0...
const Vec3T< T > & getCenter() const noexcept
Get torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:644
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:730
Signed distance field for a tube (a pipe): the space between two coaxial cylinders,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3620
Vec3T< T > m_axis
Unit axis from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3825
TubeSDF & operator=(TubeSDF &&)=default
Move assignment.
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the outer wall,...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3779
TubeSDF & operator=(const TubeSDF &)=default
Copy assignment.
const T & getInnerRadius() const noexcept
Get the inner radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3724
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: the box of the outer cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3800
TubeSDF(const TubeSDF &)=default
Copy constructor.
const Vec3T< T > & getCenter2() const noexcept
Get the center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3713
TubeSDF()=default
Default constructor. Constructs a tube from (0,-0.5,0) to (0,0.5,0), with inner radius 0....
T m_length
Distance between the end centers.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3830
const T & getOuterRadius() const noexcept
Get the outer radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3735
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 4.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3767
TubeSDF(TubeSDF &&)=default
Move constructor.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3627
T m_outerRadius
Outer radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3840
const Vec3T< T > & getCenter1() const noexcept
Get the center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3702
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the tube.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3747
TubeSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_innerRadius, const T a_outerRadius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3642
Vec3T< T > m_center2
Center of the other end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3820
T m_innerRadius
Inner radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3835
Vec3T< T > m_center1
Center of one end.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:3815
Two-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:37
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > max() noexcept
Return the most-positive representable vector.
size_t maxDir(const bool a_doAbs) const noexcept
Return the direction which has the largest component (can be absolute)
T length() const noexcept
Compute vector length.
static constexpr Vec3T< T > ones() noexcept
Return a vector with x = y = z = 1.
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Signed distance field for a revolved vesica: a lens between two tips, the vesica (the overlap of two ...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6933
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7080
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the vesica.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7047
VesicaSDF(VesicaSDF &&)=default
Move constructor.
VesicaSDF()=default
Default constructor. Constructs a vesica from (0,-1,0) to (0,1,0), with radius 0.5.
VesicaSDF & operator=(const VesicaSDF &)=default
Copy assignment.
const Vec3T< T > & getTip2() const noexcept
Get the other tip.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7024
VesicaSDF(const VesicaSDF &)=default
Copy constructor.
Vec3T< T > m_tip2
The other tip.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7095
T m_radius
Radius at the middle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7100
const T & getRadius() const noexcept
Get the radius at the middle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7035
const Vec3T< T > & getTip1() const noexcept
Get one tip.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7013
Vec3T< T > m_tip1
One tip.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:7090
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6940
VesicaSDF(const Vec3T< T > &a_tip1, const Vec3T< T > &a_tip2, const T a_radius)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:6954
VesicaSDF & operator=(VesicaSDF &&)=default
Move assignment.
Signed distance field for an infinite wedge: a knife edge.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4560
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance function for the wedge.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4659
WedgeSDF & operator=(const WedgeSDF &)=default
Copy assignment.
WedgeSDF()=default
Default constructor. Constructs a wedge with its tip at the origin and an opening of 60 degrees.
WedgeSDF(const Vec3T< T > &a_tip, const T a_angle)
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4579
T m_sin
Sine of half the opening angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4730
const T & getAngle() const noexcept
Get the opening angle, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4636
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The shape's axis-aligned bounding box: unbounded but above the tip.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4709
WedgeSDF & operator=(WedgeSDF &&)=default
Move assignment.
WedgeSDF(const WedgeSDF &)=default
Copy constructor.
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part whose term decides the value at a point (see hasParts): 0 the face on the -x side of the tip...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4698
uint32_t getNumParts() const noexcept
How many parts the shape has (see hasParts): 2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4686
Vec3T< T > getFaceNormal() const noexcept
The unit outward normal of the face on the +x side; the other face's is mirrored in x.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4647
Vec3T< T > m_tip
A point on the edge.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4720
WedgeSDF(WedgeSDF &&)=default
Move constructor.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4567
T m_cos
Cosine of half the opening angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4735
const Vec3T< T > & getTip() const noexcept
Get the tip, a point on the edge.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4625
T m_angle
The opening angle, in degrees.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:4725
constexpr T clamp(const T &a_value, const T &a_lo, const T &a_hi) noexcept
A value limited to [lo, hi].
Definition EBGeometry_Math.hpp:78
constexpr T max(const T &a_a, const T &a_b) noexcept
The larger of two values.
Definition EBGeometry_Math.hpp:61
constexpr T min(const T &a_a, const T &a_b) noexcept
The smaller of two values.
Definition EBGeometry_Math.hpp:44
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Vec2T< T > min(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise minimum of two vectors.
T length(const Vec2T< T > &v) noexcept
Euclidean length of a 2D vector.
constexpr Vec3T< T > cross(const Vec3T< T > &u, const Vec3T< T > &v) noexcept
Cross product of two 3D vectors.
T dot(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Dot product of two 2D vectors.
Vec3T< T > normal(const F &a_function, const Vec3T< T > &a_point, const T &a_delta) noexcept
Outward unit normal of a function's level set, by central finite differences.
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
@ Exact
The value's magnitude is the Euclidean distance to the surface.
@ Bound
The value's magnitude never exceeds the distance to the surface: it may underestimate,...
@ NotADistance
Only the sign is meaningful, so the function describes a surface (its zero level set) but says nothin...
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise maximum of two vectors.
A point's coordinates around an axis: its distance from the axis line, and its position along it.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2346
T m_radial
Distance from the axis line (never negative).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2350
T m_axial
Position along the axis, from the axis' start point.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2355
A convex polyhedron's faces, vertices and edges, found on the host from its planes in double precisio...
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5284
std::vector< std::pair< uint32_t, uint32_t > > m_edges
The edges, as pairs of vertex indices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5293
std::vector< Vec3T< double > > m_vertices
The vertices.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:5288
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
constexpr T * begin() noexcept
Iterator to the first element.
Definition EBGeometry_Array.hpp:104
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91