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.
pull/1419/head
ruevs 2023-09-24 22:50:14 +03:00
parent 9edf2bcc34
commit 0d26ca17f7
1 changed files with 15 additions and 0 deletions

View File

@ -220,6 +220,21 @@ void GraphicsWindow::SelectByMarquee() {
bool entityHasBBox; bool entityHasBBox;
BBox entityBBox = e.GetOrGenerateScreenBBox(&entityHasBBox); BBox entityBBox = e.GetOrGenerateScreenBBox(&entityHasBBox);
if(entityHasBBox && entityBBox.Overlaps(marqueeBBox)) { 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); MakeSelected(e.h);
} }
} }