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; }