From 0d26ca17f750f62fee917a88101bdb03cf5225dd Mon Sep 17 00:00:00 2001 From: ruevs Date: Sun, 24 Sep 2023 22:50:14 +0300 Subject: [PATCH] UI: Make marquee selection of line segments precise Before marquee selection worked by checking whether the Axis Aligned Bounding Box of an entity and the selection marquee overlap. This selects (slanted) line segments even though the marquee did not "touch" them. To fix this for line segments actually check that the selection marque intersects the line segment. --- src/draw.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/draw.cpp b/src/draw.cpp index f364b28d..9fa964fa 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -220,6 +220,21 @@ void GraphicsWindow::SelectByMarquee() { bool entityHasBBox; BBox entityBBox = e.GetOrGenerateScreenBBox(&entityHasBBox); if(entityHasBBox && entityBBox.Overlaps(marqueeBBox)) { + if(e.type == Entity::Type::LINE_SEGMENT) { + Vector p0 = SS.GW.ProjectPoint3(e.EndpointStart()); + Vector p1 = SS.GW.ProjectPoint3(e.EndpointFinish()); + if((!marqueeBBox.Contains({p0.x, p0.y}, 0)) && + (!marqueeBBox.Contains({p1.x, p1.y}, 0))) { + // The selection marquee does not contain either of the line segment end points. + // This means that either the segment is entirely outside the marquee or that + // it intersects it. Check if it does... + if(!Vector::BoundingBoxIntersectsLine(marqueeBBox.maxp, marqueeBBox.minp, p0, + p1, true)) { + // ... it does not so it is outside. + continue; + } + } + } MakeSelected(e.h); } }