File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -2495,8 +2495,35 @@ namespace olc::utils::geom2d
2495
2495
template <typename T1, typename T2, typename T3>
2496
2496
inline std::optional<olc::v_2d<T2>> project (const circle<T1>& c, const triangle<T2>& t, const ray<T3>& q)
2497
2497
{
2498
- // TODO:
2499
- return std::nullopt;
2498
+ const auto s1 = project (c, t.side (0 ), q);
2499
+ const auto s2 = project (c, t.side (1 ), q);
2500
+ const auto s3 = project (c, t.side (2 ), q);
2501
+
2502
+ std::vector<olc::v_2d<T2>> vAllIntersections;
2503
+ if (s1.has_value ()) vAllIntersections.push_back (s1.value ());
2504
+ if (s2.has_value ()) vAllIntersections.push_back (s2.value ());
2505
+ if (s3.has_value ()) vAllIntersections.push_back (s3.value ());
2506
+
2507
+ if (vAllIntersections.size () == 0 )
2508
+ {
2509
+ // No intersections at all, so
2510
+ return std::nullopt;
2511
+ }
2512
+
2513
+ // Find closest
2514
+ double dClosest = std::numeric_limits<double >::max ();
2515
+ olc::v_2d<T2> vClosest;
2516
+ for (const auto & vContact : vAllIntersections)
2517
+ {
2518
+ double dDistance = (vContact - q.origin ).mag2 ();
2519
+ if (dDistance < dClosest)
2520
+ {
2521
+ dClosest = dDistance;
2522
+ vClosest = vContact;
2523
+ }
2524
+ }
2525
+
2526
+ return vClosest;
2500
2527
}
2501
2528
2502
2529
You can’t perform that action at this time.
0 commit comments