File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed
Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -2192,8 +2192,35 @@ namespace olc::utils::geom2d
21922192 template <typename T1, typename T2, typename T3>
21932193 inline std::optional<olc::v_2d<T2>> project (const circle<T1>& c, const triangle<T2>& t, const ray<T3>& q)
21942194 {
2195- // TODO:
2196- return std::nullopt ;
2195+ const auto s1 = project (c, t.side (0 ), q);
2196+ const auto s2 = project (c, t.side (1 ), q);
2197+ const auto s3 = project (c, t.side (2 ), q);
2198+
2199+ std::vector<olc::v_2d<T2>> vAllIntersections;
2200+ if (s1.has_value ()) vAllIntersections.push_back (s1.value ());
2201+ if (s2.has_value ()) vAllIntersections.push_back (s2.value ());
2202+ if (s3.has_value ()) vAllIntersections.push_back (s3.value ());
2203+
2204+ if (vAllIntersections.size () == 0 )
2205+ {
2206+ // No intersections at all, so
2207+ return std::nullopt ;
2208+ }
2209+
2210+ // Find closest
2211+ double dClosest = std::numeric_limits<double >::max ();
2212+ olc::v_2d<T2> vClosest;
2213+ for (const auto & vContact : vAllIntersections)
2214+ {
2215+ double dDistance = (vContact - q.origin ).mag2 ();
2216+ if (dDistance < dClosest)
2217+ {
2218+ dClosest = dDistance;
2219+ vClosest = vContact;
2220+ }
2221+ }
2222+
2223+ return vClosest;
21972224 }
21982225
21992226
You can’t perform that action at this time.
0 commit comments