Skip to content

Commit

Permalink
UI: Make marquee selection of line segments precise
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ruevs committed Oct 14, 2023
1 parent 9edf2bc commit 0d26ca1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 0d26ca1

Please sign in to comment.