From 1ebe10dcee2ea3c5ebc2e18b7b8f812eea62bd3e Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 16 Feb 2026 16:40:22 -0700 Subject: [PATCH] feat: Render unattached sketch vertices as circles Co-authored-by: aider (gemini/gemini-2.5-pro) --- src/ViewportWidget.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/ViewportWidget.cpp b/src/ViewportWidget.cpp index ed55a15..ec0a9bd 100644 --- a/src/ViewportWidget.cpp +++ b/src/ViewportWidget.cpp @@ -24,6 +24,18 @@ #include #include #include +#include + +struct PntComparator { + bool operator()(const gp_Pnt& a, const gp_Pnt& b) const { + // A tolerance is needed for floating point comparisons + double tol = 1e-9; + if (std::abs(a.X() - b.X()) > tol) return a.X() < b.X(); + if (std::abs(a.Y() - b.Y()) > tol) return a.Y() < b.Y(); + if (std::abs(a.Z() - b.Z()) > tol) return a.Z() < b.Z(); + return false; // They are considered equal + } +}; ViewportWidget::ViewportWidget(QWidget *parent) : QOpenGLWidget(parent) @@ -735,7 +747,7 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch) glPointSize(5.0f); QVector lineVertices; - QVector pointVertices; + QMap vertexCounts; for (const auto& obj : sketch->objects()) { if (obj->type() == SketchObject::ObjectType::Line) { @@ -745,8 +757,16 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch) lineVertices << start.X() << start.Y() << start.Z(); lineVertices << end.X() << end.Y() << end.Z(); - pointVertices << start.X() << start.Y() << start.Z(); - pointVertices << end.X() << end.Y() << end.Z(); + vertexCounts[start]++; + vertexCounts[end]++; + } + } + + QVector pointVertices; + for (auto it = vertexCounts.constBegin(); it != vertexCounts.constEnd(); ++it) { + if (it.value() == 1) { + const gp_Pnt& p = it.key(); + pointVertices << p.X() << p.Y() << p.Z(); } } @@ -758,8 +778,13 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch) glDrawArrays(GL_LINES, 0, lineVertices.size() / 3); } if (!pointVertices.isEmpty()) { + glEnable(GL_POINT_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); m_vbo.allocate(pointVertices.constData(), pointVertices.size() * sizeof(GLfloat)); glDrawArrays(GL_POINTS, 0, pointVertices.size() / 3); + glDisable(GL_BLEND); + glDisable(GL_POINT_SMOOTH); } glEnable(GL_DEPTH_TEST);