HerdSoftware  0.4.0
IntersectionUtils.hpp
Go to the documentation of this file.
1 /*
2  * IntersectionUtils.hpp
3  *
4  * Created on: 6 Apr 2023
5  * Author: Valerio Formato
6  */
7 
8 #ifndef HERD_INTERSECTION_UTILS
9 #define HERD_INTERSECTION_UTILS
10 
11 namespace Herd::Geom {
13  size_t volID;
14  std::array<Point, 2> points;
15 };
16 
24 template <class GeoParams>
25 [[nodiscard]] std::vector<IntersectionResult> Intersect(const Line &line, const GeoParams &geoParams) {
26  std::vector<IntersectionResult> result;
27 
28  // First, check if the line intersects the geoparams bounding box
29  if (const auto &bb_intersections = geoParams.BoundingBox().Intersections(line); !bb_intersections) {
30  return result;
31  }
32 
33  for (size_t id = 0; id < geoParams.NTotElements(); ++id) {
34  if (auto intersections = geoParams.ElementShape(id).Intersections(line); intersections) {
35  result.push_back(IntersectionResult{id, intersections.value()});
36  }
37  }
38 
39  return result;
40 }
41 } // namespace Herd::Geom
42 
43 #endif // HERD_INTERSECTION_UTILS
Herd::Line
Class describing a line in the 3D space.
Definition: Line.h:37
Herd::Geom
Definition: GeomUtils.h:18
Herd::Geom::IntersectionResult::volID
size_t volID
Definition: IntersectionUtils.hpp:13
Herd::Geom::IntersectionResult::points
std::array< Point, 2 > points
Definition: IntersectionUtils.hpp:14
Herd::Geom::Intersect
std::vector< IntersectionResult > Intersect(const Line &line, const GeoParams &geoParams)
compute intersections between a line and a given geoparams object
Definition: IntersectionUtils.hpp:25
Herd::Geom::IntersectionResult
Definition: IntersectionUtils.hpp:12