Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
distance.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Francesco Barrale <francesco.barrale@mail.polimi.it>
22// Author: Matteo Caldana <matteo.caldana@polimi.it>
23// Author: Pedro Peixoto <ppeixoto@usp.br>
24
25#ifndef VULPES_GEOMETRY_DISTANCE_HPP_
26#define VULPES_GEOMETRY_DISTANCE_HPP_
27
28#include <algorithm>
29#include <array>
30#include <cassert>
31#include <cmath>
32#include <cstdint>
33#include <limits>
34#include <random>
35#include <stdexcept>
36#include <vector>
37
38#include <Eigen/Dense>
39
44
45namespace vulpes {
46namespace geometry {
47
64template <typename FloatType, int32_t Dim, typename Distance>
66 public:
71 static constexpr bool is_leaf = false;
72
82 static constexpr size_t size() { return Distance::size(); }
83
96 const Point<FloatType, Dim>& point, FloatType* distance_buffer) const {
97 static_cast<const Distance&>(*this)(point, distance_buffer);
98 }
99
108 std::array<Point<FloatType, Dim>, 2> bbox() const {
109 return static_cast<const Distance*>(this)->bbox();
110 }
111};
112
113namespace dist2d {
114
123template <typename FloatType>
125 : public DistanceExpression<FloatType, 2, RectangleDistance<FloatType>> {
126 public:
131 static constexpr bool is_leaf = true;
137 static constexpr size_t size() { return 5; }
138
146 const Point<FloatType, 2>& corner_a, const Point<FloatType, 2>& corner_b)
147 : m_corner_a(corner_a), m_corner_b(corner_b) {}
148
157 const Point<FloatType, 2>& point, FloatType* distance_buffer) const {
158 distance_buffer[0] = m_corner_a[0] - point[0];
159 distance_buffer[1] = point[0] - m_corner_b[0];
160 distance_buffer[2] = m_corner_a[1] - point[1];
161 distance_buffer[3] = point[1] - m_corner_b[1];
162 distance_buffer[4] =
163 *std::max_element(distance_buffer, distance_buffer + 4);
164 }
165
171 std::array<Point<FloatType, 2>, 2> bbox() const {
172 return {m_corner_a, m_corner_b};
173 }
174
175 private:
178};
179
195template <typename FloatType>
197 : public DistanceExpression<FloatType, 2, PolygonDistance<FloatType>> {
198 public:
200 static constexpr size_t max_edges = 2000;
201
206 static constexpr bool is_leaf = true;
213 static constexpr size_t size() { return max_edges + 1; }
214
224 explicit PolygonDistance(const std::vector<Point<FloatType, 2>>& vertices)
225 : m_vertices(vertices) {
226 if (m_vertices.size() < 3) {
227 throw std::invalid_argument(
228 "A polygon must have at least three vertices");
229 }
230 if (m_vertices.size() > max_edges) {
231 throw std::invalid_argument("Polygon has too many edges");
232 }
233 // Determine the vertex ordering so every edge distance points outward.
234 FloatType signed_area = 0.;
235 for (size_t i = 0; i < m_vertices.size(); ++i) {
236 const auto& start = m_vertices[i];
237 const auto& end = m_vertices[(i + 1) % m_vertices.size()];
238 signed_area += start[0] * end[1] - end[0] * start[1];
239 }
240 if (signed_area == FloatType(0.)) {
241 throw std::invalid_argument("Polygon has zero area");
242 }
243 if (hasIntersectingEdges()) {
244 throw std::invalid_argument("Polygon has edges that cross or touch");
245 }
246 m_outward_sign = signed_area > 0. ? -1. : 1.;
247 }
248
257 const Point<FloatType, 2>& point, FloatType* distance_buffer) const {
258 // Find the minimum Euclidean distance from the point to the polygon edges.
259 const FloatType infinity = std::numeric_limits<FloatType>::max();
260 FloatType min_distance = infinity;
261 bool point_on_boundary = false;
262 bool point_inside = false;
263
264 // Unused edge slots must not be considered by VulPoly.
265 std::fill(distance_buffer, distance_buffer + max_edges, infinity);
266
267 // Process every edge, including the closing edge from the last vertex to
268 // the first one.
269 for (size_t i = 0; i < m_vertices.size(); ++i) {
270 const auto& start = m_vertices[i];
271 const auto& end = m_vertices[(i + 1) % m_vertices.size()];
272 const FloatType dx = end[0] - start[0];
273 const FloatType dy = end[1] - start[1];
274 const FloatType edge_length_squared = dx * dx + dy * dy;
275
276 // Project the point onto the edge and clamp the projection to the
277 // segment endpoints.
278 FloatType projection = 0.;
279 if (edge_length_squared > 0.) {
280 projection = ((point[0] - start[0]) * dx + (point[1] - start[1]) * dy) /
281 edge_length_squared;
282 projection = std::clamp(projection, FloatType(0.), FloatType(1.));
283 }
284
285 const FloatType closest_x = start[0] + projection * dx;
286 const FloatType closest_y = start[1] + projection * dy;
287 const FloatType diff_x = point[0] - closest_x;
288 const FloatType diff_y = point[1] - closest_y;
289 const FloatType edge_distance =
290 std::sqrt(diff_x * diff_x + diff_y * diff_y);
291 min_distance = std::min(min_distance, edge_distance);
292
293 // Store the signed distance to the line through this edge.
294 const FloatType cross =
295 dx * (point[1] - start[1]) - dy * (point[0] - start[0]);
296 distance_buffer[i] =
297 edge_length_squared > 0.
298 ? m_outward_sign * cross / std::sqrt(edge_length_squared)
299 : infinity;
300
301 // Use a scale-aware tolerance to classify points very close to an edge
302 // as boundary points despite floating-point roundoff.
303 const FloatType scale = std::max(
304 {FloatType(1.), std::abs(point[0]), std::abs(point[1]),
305 std::abs(start[0]), std::abs(start[1]), std::abs(end[0]),
306 std::abs(end[1])});
307 if (edge_distance <=
308 FloatType(8.) * std::numeric_limits<FloatType>::epsilon() * scale) {
309 point_on_boundary = true;
310 }
311
312 // Ray casting: each crossing of the horizontal ray toggles the
313 // inside/outside state. An odd number of crossings means inside.
314 if ((start[1] > point[1]) != (end[1] > point[1]) &&
315 point[0] < (end[0] - start[0]) * (point[1] - start[1]) /
316 (end[1] - start[1]) +
317 start[0]) {
318 point_inside = !point_inside;
319 }
320 }
321
322 // Inside and boundary points are negative; outside points are positive.
323 const FloatType signed_distance =
324 point_on_boundary || point_inside ? -min_distance : min_distance;
325 distance_buffer[max_edges] = signed_distance;
326 }
327
333 std::array<Point<FloatType, 2>, 2> bbox() const {
334 Point<FloatType, 2> lower = m_vertices.front();
335 Point<FloatType, 2> upper = m_vertices.front();
336 for (const auto& vertex : m_vertices) {
337 lower[0] = std::min(lower[0], vertex[0]);
338 lower[1] = std::min(lower[1], vertex[1]);
339 upper[0] = std::max(upper[0], vertex[0]);
340 upper[1] = std::max(upper[1], vertex[1]);
341 }
342 return {lower, upper};
343 }
344
345 private:
347 bool hasIntersectingEdges() const {
348 using Point2 = Point<FloatType, 2>;
349 const auto orientation = [](const Point2& a, const Point2& b,
350 const Point2& c) {
351 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
352 };
353 // For c collinear with a and b: true if c is on the segment between them
354 const auto onSegment = [](const Point2& a, const Point2& b,
355 const Point2& c) {
356 return std::min(a[0], b[0]) <= c[0] && c[0] <= std::max(a[0], b[0]) &&
357 std::min(a[1], b[1]) <= c[1] && c[1] <= std::max(a[1], b[1]);
358 };
359 const size_t n = m_vertices.size();
360 for (size_t i = 0; i < n; ++i) {
361 const auto& a = m_vertices[i];
362 const auto& b = m_vertices[(i + 1) % n];
363 for (size_t j = i + 2; j < n; ++j) {
364 // the first and the last edges share a vertex
365 if (i == 0 && j == n - 1) {
366 continue;
367 }
368 const auto& c = m_vertices[j];
369 const auto& d = m_vertices[(j + 1) % n];
370 const FloatType side_c = orientation(a, b, c);
371 const FloatType side_d = orientation(a, b, d);
372 const FloatType side_a = orientation(c, d, a);
373 const FloatType side_b = orientation(c, d, b);
374 if (side_c * side_d < 0. && side_a * side_b < 0.) {
375 return true;
376 }
377 if ((side_c == 0. && onSegment(a, b, c)) ||
378 (side_d == 0. && onSegment(a, b, d)) ||
379 (side_a == 0. && onSegment(c, d, a)) ||
380 (side_b == 0. && onSegment(c, d, b))) {
381 return true;
382 }
383 }
384 }
385 return false;
386 }
387
388 const std::vector<Point<FloatType, 2>>
390 FloatType m_outward_sign;
391};
392
401template <typename FloatType>
403 : public DistanceExpression<FloatType, 2, CircleDistance<FloatType>> {
404 public:
409 static constexpr bool is_leaf = true;
410
416 static constexpr size_t size() { return 2; }
417
424 CircleDistance(const Point<FloatType, 2>& center, FloatType radius)
425 : m_center(center), m_radius(radius) {}
426
435 const Point<FloatType, 2>& point, FloatType* distance_buffer) const {
436 const FloatType dx = point[0] - m_center[0];
437 const FloatType dy = point[1] - m_center[1];
438 distance_buffer[0] = std::sqrt(dx * dx + dy * dy) - m_radius;
439 distance_buffer[1] = distance_buffer[0];
440 }
441
447 std::array<Point<FloatType, 2>, 2> bbox() const {
448 return {m_center.array() - m_radius, m_center.array() + m_radius};
449 }
450
451 private:
453 const FloatType m_radius;
454};
455} // namespace dist2d
456
457namespace dist3d {
466template <typename FloatType>
468 : public DistanceExpression<FloatType, 3, HexahedronDistance<FloatType>> {
469 public:
474 static constexpr bool is_leaf = true;
480 static constexpr size_t size() { return 7; }
481
489 const Point<FloatType, 3>& corner_a, const Point<FloatType, 3>& corner_b)
490 : m_corner_a(corner_a), m_corner_b(corner_b) {}
491
500 const Point<FloatType, 3>& point, FloatType* distance_buffer) const {
501 distance_buffer[0] = m_corner_a[0] - point[0];
502 distance_buffer[1] = point[0] - m_corner_b[0];
503 distance_buffer[2] = m_corner_a[1] - point[1];
504 distance_buffer[3] = point[1] - m_corner_b[1];
505 distance_buffer[4] = m_corner_a[2] - point[2];
506 distance_buffer[5] = point[2] - m_corner_b[2];
507 distance_buffer[6] =
508 *std::max_element(distance_buffer, distance_buffer + 6);
509 }
510
516 std::array<Point<FloatType, 3>, 2> bbox() const {
517 return {m_corner_a, m_corner_b};
518 }
519
520 private:
523};
524
533template <typename FloatType>
535 : public DistanceExpression<FloatType, 3, SphereDistance<FloatType>> {
536 public:
541 static constexpr bool is_leaf = true;
547 static constexpr size_t size() { return 2; }
548
555 SphereDistance(const Point<FloatType, 3>& center, FloatType radius)
556 : m_center(center), m_radius(radius) {}
557
566 const Point<FloatType, 3>& point, FloatType* distance_buffer) const {
567 const FloatType dx = point[0] - m_center[0];
568 const FloatType dy = point[1] - m_center[1];
569 const FloatType dz = point[2] - m_center[2];
570 distance_buffer[0] = std::sqrt(dx * dx + dy * dy + dz * dz) - m_radius;
571 distance_buffer[1] = distance_buffer[0];
572 }
573
579 std::array<Point<FloatType, 3>, 2> bbox() const {
580 return {m_center.array() - m_radius, m_center.array() + m_radius};
581 }
582
583 private:
585 const FloatType m_radius;
586};
587} // namespace dist3d
588
602template <typename FloatType, int32_t Dim, typename D1, typename D2>
604 FloatType,
605 Dim,
606 UnionDistance<FloatType, Dim, D1, D2>> {
609 typename std::conditional_t<D1::is_leaf, const D1&, const D1> m_u;
612 typename std::conditional_t<D2::is_leaf, const D2&, const D2> m_v;
613
614 public:
615 static constexpr bool is_leaf = false;
616
623 UnionDistance(D1 const& u, D2 const& v) : m_u(u), m_v(v) {}
624
633 static constexpr size_t size() {
634 return std::decay_t<decltype(m_v)>::size() +
635 std::decay_t<decltype(m_u)>::size() - 1;
636 }
637
649 const Point<FloatType, Dim>& point, FloatType* distance_buffer) const {
650 constexpr auto u_distance_size = std::decay_t<decltype(m_u)>::size();
651 constexpr auto this_size = std::decay_t<decltype(*this)>::size();
652 m_u(point, distance_buffer);
653 FloatType tmp = distance_buffer[u_distance_size - 1];
654 m_v(point, distance_buffer + u_distance_size - 1);
655 distance_buffer[this_size - 1] =
656 std::min(tmp, distance_buffer[this_size - 1]);
657 }
658
666 std::array<Point<FloatType, Dim>, 2> bbox() const {
667 const auto bbox_u = m_u.bbox();
668 const auto bbox_v = m_v.bbox();
669 Point<FloatType, Dim> corner_low;
670 Point<FloatType, Dim> corner_high;
671 for (size_t d = 0; d < Dim; ++d) {
672 corner_low[d] = std::min(bbox_u[0][d], bbox_v[0][d]);
673 corner_high[d] = std::max(bbox_u[1][d], bbox_v[1][d]);
674 }
675 return {corner_low, corner_high};
676 }
677};
678
690template <typename FloatType, int32_t Dim, typename D1, typename D2>
695 *static_cast<const D1*>(&u), *static_cast<const D2*>(&v));
696}
697
710template <typename FloatType, int32_t Dim, typename D1, typename D2>
712 FloatType,
713 Dim,
714 IntersectDistance<FloatType, Dim, D1, D2>> {
717 typename std::conditional_t<D1::is_leaf, const D1&, const D1> m_u;
720 typename std::conditional_t<D2::is_leaf, const D2&, const D2> m_v;
721
722 public:
727 static constexpr bool is_leaf = false;
728
735 IntersectDistance(D1 const& u, D2 const& v) : m_u(u), m_v(v) {}
736
745 static constexpr size_t size() {
746 return std::decay_t<decltype(m_v)>::size() +
747 std::decay_t<decltype(m_u)>::size() - 1;
748 }
749
761 const Point<FloatType, Dim>& point, FloatType* distance_buffer) const {
762 constexpr auto u_distance_size = std::decay_t<decltype(m_u)>::size();
763 constexpr auto this_size = std::decay_t<decltype(*this)>::size();
764 m_u(point, distance_buffer);
765 FloatType tmp = distance_buffer[u_distance_size - 1];
766 m_v(point, distance_buffer + u_distance_size - 1);
767 distance_buffer[this_size - 1] =
768 std::max(tmp, distance_buffer[this_size - 1]);
769 }
770
776 std::array<Point<FloatType, Dim>, 2> bbox() const {
777 const auto bbox_u = m_u.bbox();
778 const auto bbox_v = m_v.bbox();
779 Point<FloatType, Dim> corner_low;
780 Point<FloatType, Dim> corner_high;
781 for (size_t d = 0; d < Dim; ++d) {
782 corner_low[d] = std::max(bbox_u[0][d], bbox_v[0][d]);
783 corner_high[d] = std::min(bbox_u[1][d], bbox_v[1][d]);
784 }
785 return {corner_low, corner_high};
786 }
787};
788
801template <typename FloatType, int32_t Dim, typename D1, typename D2>
806 *static_cast<const D1*>(&u), *static_cast<const D2*>(&v));
807}
808
822template <typename FloatType, int32_t Dim, typename D1, typename D2>
824 FloatType,
825 Dim,
826 DifferenceDistance<FloatType, Dim, D1, D2>> {
829 typename std::conditional_t<D1::is_leaf, const D1&, const D1> m_u;
832 typename std::conditional_t<D2::is_leaf, const D2&, const D2> m_v;
833
834 public:
839 static constexpr bool is_leaf = false;
840
847 DifferenceDistance(D1 const& u, D2 const& v) : m_u(u), m_v(v) {}
848
857 static constexpr size_t size() {
858 return std::decay_t<decltype(m_v)>::size() +
859 std::decay_t<decltype(m_u)>::size() - 1;
860 }
861
874 const Point<FloatType, Dim>& point, FloatType* distance_buffer) const {
875 constexpr auto u_distance_size = std::decay_t<decltype(m_u)>::size();
876 constexpr auto this_size = std::decay_t<decltype(*this)>::size();
877 m_u(point, distance_buffer);
878 FloatType tmp = distance_buffer[u_distance_size - 1];
879 m_v(point, distance_buffer + u_distance_size - 1);
880 distance_buffer[this_size - 1] =
881 std::max(tmp, -distance_buffer[this_size - 1]);
882 }
883
891 std::array<Point<FloatType, Dim>, 2> bbox() const { return m_u.bbox(); }
892};
893
906template <typename FloatType, int32_t Dim, typename D1, typename D2>
911 *static_cast<const D1*>(&u), *static_cast<const D2*>(&v));
912}
913
935template <typename FloatType, int32_t Dim, typename D>
937 const Point<FloatType, Dim>& point,
938 const DistanceExpression<FloatType, Dim, D>& distance_function) {
939 constexpr size_t distance_size =
941 std::array<FloatType, distance_size> distance_buffer;
942 distance_function(point, distance_buffer.data());
943 return distance_buffer;
944}
945
946} // namespace geometry
947} // namespace vulpes
948
949#endif // VULPES_GEOMETRY_DISTANCE_HPP_
Represents the difference of two signed distance functions.
Definition distance.hpp:826
static constexpr size_t size()
Get the size of the distance buffer for this difference operation.
Definition distance.hpp:857
std::conditional_t< D2::is_leaf, const D2 &, const D2 > m_v
Definition distance.hpp:832
std::array< Point< FloatType, Dim >, 2 > bbox() const
Get the bounding box of the difference of two shapes.
Definition distance.hpp:891
DifferenceDistance(D1 const &u, D2 const &v)
Constructor for the difference distance function.
Definition distance.hpp:847
static constexpr bool is_leaf
A flag indicating that this is a non-leaf node in a composite expression.
Definition distance.hpp:839
void operator()(const Point< FloatType, Dim > &point, FloatType *distance_buffer) const
Compute the distance between a point and the difference of two shapes.
Definition distance.hpp:873
std::conditional_t< D1::is_leaf, const D1 &, const D1 > m_u
Definition distance.hpp:829
Template class representing a generic signed distance expression.
Definition distance.hpp:65
void operator()(const Point< FloatType, Dim > &point, FloatType *distance_buffer) const
Evaluate the distance function for the given point.
Definition distance.hpp:95
static constexpr bool is_leaf
A flag indicating whether this is a leaf node in a composite expression.
Definition distance.hpp:71
std::array< Point< FloatType, Dim >, 2 > bbox() const
Get the bounding box (bbox) of the shape.
Definition distance.hpp:108
static constexpr size_t size()
Get the size of the distance buffer required for this expression.
Definition distance.hpp:82
Represents the intersection of two signed distance functions.
Definition distance.hpp:714
static constexpr bool is_leaf
A flag indicating that this is a non-leaf node in a composite expression.
Definition distance.hpp:727
std::array< Point< FloatType, Dim >, 2 > bbox() const
Get the bounding box of the intersection of two shapes.
Definition distance.hpp:776
static constexpr size_t size()
Get the size of the distance buffer for this intersection operation.
Definition distance.hpp:745
std::conditional_t< D2::is_leaf, const D2 &, const D2 > m_v
Definition distance.hpp:720
std::conditional_t< D1::is_leaf, const D1 &, const D1 > m_u
Definition distance.hpp:717
void operator()(const Point< FloatType, Dim > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the intersection of two shapes.
Definition distance.hpp:760
IntersectDistance(D1 const &u, D2 const &v)
Constructor for the intersection distance function.
Definition distance.hpp:735
Represents the union of two signed distance functions.
Definition distance.hpp:606
void operator()(const Point< FloatType, Dim > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the union of two shapes.
Definition distance.hpp:648
static constexpr bool is_leaf
Definition distance.hpp:615
UnionDistance(D1 const &u, D2 const &v)
Constructor for the union distance function.
Definition distance.hpp:623
static constexpr size_t size()
Get the size of the distance buffer for this union operation.
Definition distance.hpp:633
std::conditional_t< D2::is_leaf, const D2 &, const D2 > m_v
Definition distance.hpp:612
std::conditional_t< D1::is_leaf, const D1 &, const D1 > m_u
Definition distance.hpp:609
std::array< Point< FloatType, Dim >, 2 > bbox() const
Get the bounding box of the union of two shapes.
Definition distance.hpp:666
static constexpr bool is_leaf
A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit form...
Definition distance.hpp:409
static constexpr size_t size()
Get the size of the distance buffer for this distance function.
Definition distance.hpp:416
const FloatType m_radius
The radius of the circle.
Definition distance.hpp:453
const Point< FloatType, 2 > m_center
The center of the circle.
Definition distance.hpp:452
std::array< Point< FloatType, 2 >, 2 > bbox() const
Get the bounding box of the circle.
Definition distance.hpp:447
CircleDistance(const Point< FloatType, 2 > &center, FloatType radius)
Constructor for the circle distance function.
Definition distance.hpp:424
void operator()(const Point< FloatType, 2 > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the circle.
Definition distance.hpp:434
std::array< Point< FloatType, 2 >, 2 > bbox() const
Get the bounding box of the polygon.
Definition distance.hpp:333
static constexpr bool is_leaf
A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit form...
Definition distance.hpp:206
const std::vector< Point< FloatType, 2 > > m_vertices
The vertices of the polygon.
Definition distance.hpp:389
bool hasIntersectingEdges() const
True if two edges that are not consecutive cross or touch.
Definition distance.hpp:347
FloatType m_outward_sign
Makes the edge distances positive outward.
Definition distance.hpp:390
void operator()(const Point< FloatType, 2 > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the polygon.
Definition distance.hpp:256
static constexpr size_t max_edges
Largest number of edges: the buffer size is a compile-time constant.
Definition distance.hpp:200
static constexpr size_t size()
Get the size of the distance buffer for this distance function.
Definition distance.hpp:213
PolygonDistance(const std::vector< Point< FloatType, 2 > > &vertices)
Constructor for the polygon distance function.
Definition distance.hpp:224
const Point< FloatType, 2 > m_corner_b
Opposite corner of the rectangle.
Definition distance.hpp:177
std::array< Point< FloatType, 2 >, 2 > bbox() const
Get the bounding box of the rectangle.
Definition distance.hpp:171
RectangleDistance(const Point< FloatType, 2 > &corner_a, const Point< FloatType, 2 > &corner_b)
Constructor for the rectangle distance function.
Definition distance.hpp:145
static constexpr size_t size()
Get the size of the distance buffer for this distance function.
Definition distance.hpp:137
const Point< FloatType, 2 > m_corner_a
One corner of the rectangle.
Definition distance.hpp:176
void operator()(const Point< FloatType, 2 > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the rectangle.
Definition distance.hpp:156
static constexpr bool is_leaf
A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit form...
Definition distance.hpp:131
std::array< Point< FloatType, 3 >, 2 > bbox() const
Get the bounding box of the hexahedron.
Definition distance.hpp:516
static constexpr bool is_leaf
A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit form...
Definition distance.hpp:474
static constexpr size_t size()
Get the size of the distance buffer for this distance function.
Definition distance.hpp:480
const Point< FloatType, 3 > m_corner_a
Smallest corner of the hexahedron.
Definition distance.hpp:521
const Point< FloatType, 3 > m_corner_b
Largest corner of the hexahedron.
Definition distance.hpp:522
void operator()(const Point< FloatType, 3 > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the hexahedron.
Definition distance.hpp:499
HexahedronDistance(const Point< FloatType, 3 > &corner_a, const Point< FloatType, 3 > &corner_b)
Constructor for the hexahedron distance function.
Definition distance.hpp:488
void operator()(const Point< FloatType, 3 > &point, FloatType *distance_buffer) const
Compute the signed distance between a point and the sphere.
Definition distance.hpp:565
static constexpr size_t size()
Get the size of the distance buffer for this distance function.
Definition distance.hpp:547
static constexpr bool is_leaf
A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit form...
Definition distance.hpp:541
std::array< Point< FloatType, 3 >, 2 > bbox() const
Get the bounding box of the sphere.
Definition distance.hpp:579
const FloatType m_radius
The radius of the sphere.
Definition distance.hpp:585
const Point< FloatType, 3 > m_center
The center of the sphere.
Definition distance.hpp:584
SphereDistance(const Point< FloatType, 3 > &center, FloatType radius)
Constructor for the sphere distance function.
Definition distance.hpp:555
Definition distance.hpp:113
Definition distance.hpp:457
Definition abs_agg_model.cpp:40
Eigen::Matrix< DataType, Dim, 1, Eigen::ColMajor > Point
Definition traits.hpp:34
IntersectDistance< FloatType, Dim, D1, D2 > operator&(const DistanceExpression< FloatType, Dim, D1 > &u, const DistanceExpression< FloatType, Dim, D2 > &v)
Create an intersection of two signed distance functions.
Definition distance.hpp:802
DifferenceDistance< FloatType, Dim, D1, D2 > operator-(const DistanceExpression< FloatType, Dim, D1 > &u, const DistanceExpression< FloatType, Dim, D2 > &v)
Create a difference of two distance functions.
Definition distance.hpp:907
auto computeDistance(const Point< FloatType, Dim > &point, const DistanceExpression< FloatType, Dim, D > &distance_function)
Computes the signed distance between a point and a shape defined by a distance function.
Definition distance.hpp:936
UnionDistance< FloatType, Dim, D1, D2 > operator|(const DistanceExpression< FloatType, Dim, D1 > &u, const DistanceExpression< FloatType, Dim, D2 > &v)
Create a union of two signed distance functions.
Definition distance.hpp:691
Definition cell_manager.hpp:38