From bf80a934434da629a641ed72eb1cada36ad5fd7f Mon Sep 17 00:00:00 2001 From: Abrar Mahmud Hasan Date: Thu, 6 Aug 2026 21:37:27 +0600 Subject: [PATCH] Implemented closest (ray, point) --- olcUTIL_Geometry2D.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/olcUTIL_Geometry2D.h b/olcUTIL_Geometry2D.h index 0482473..e075ba2 100644 --- a/olcUTIL_Geometry2D.h +++ b/olcUTIL_Geometry2D.h @@ -887,8 +887,8 @@ namespace olc::utils::geom2d template inline olc::v_2d closest(const ray& r, const olc::v_2d& p) { - // TODO: implement - return p; + double u = std::max(0.0, double(r.direction.dot(p - r.origin)) / r.direction.mag2()); + return r.origin + u * r.direction; }