From e64755ea0cb6f8014a416eee562e95f241470b3e Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 17 Feb 2026 10:01:00 -0700 Subject: [PATCH] feat: Make rectangle corners snappable Co-authored-by: aider (gemini/gemini-2.5-pro) --- src/ViewportWidget.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ViewportWidget.cpp b/src/ViewportWidget.cpp index 26a470d..ac15fa2 100644 --- a/src/ViewportWidget.cpp +++ b/src/ViewportWidget.cpp @@ -1293,6 +1293,46 @@ void ViewportWidget::mouseMoveEvent(QMouseEvent *event) break; } + if (isClose) { + m_isSnappingVertex = true; + m_snapVertex = vertex; + goto end_snap_check; + } + } + } else if (obj->type() == SketchObject::ObjectType::Rectangle) { + auto rect = static_cast(obj); + const auto& p1 = rect->corner1(); + const auto& p3 = rect->corner2(); + gp_Pnt p2, p4; + + if (sketch->plane() == SketchFeature::SketchPlane::XY) { + p2.SetCoord(p3.X(), p1.Y(), p1.Z()); + p4.SetCoord(p1.X(), p1.Y(), p3.Z()); + } else if (sketch->plane() == SketchFeature::SketchPlane::XZ) { + p2.SetCoord(p3.X(), p1.Y(), p1.Z()); + p4.SetCoord(p1.X(), p3.Y(), p1.Z()); + } else if (sketch->plane() == SketchFeature::SketchPlane::YZ) { + p2.SetCoord(p1.X(), p3.Y(), p1.Z()); + p4.SetCoord(p1.X(), p1.Y(), p3.Z()); + } + + const gp_Pnt vertices[] = {p1, p2, p3, p4}; + for (const auto& vertex : vertices) { + bool isClose = false; + switch (m_currentPlane) { + case SketchPlane::XY: + isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize; + break; + case SketchPlane::XZ: + isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize; + break; + case SketchPlane::YZ: + isClose = qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize; + break; + case SketchPlane::NONE: + break; + } + if (isClose) { m_isSnappingVertex = true; m_snapVertex = vertex;