From fc6279a2eaf63ff55fcdf8f110a07e0e41be71ae Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Mar 2023 05:41:58 +0300 Subject: [PATCH] Improve EC_CONVERGING behaviour when lines are almost collinear. (somewhat) --- common/tool/edit_constraints.cpp | 13 +++++++++++-- include/tool/edit_constraints.h | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/tool/edit_constraints.cpp b/common/tool/edit_constraints.cpp index b1191d6650..93dcd00bab 100644 --- a/common/tool/edit_constraints.cpp +++ b/common/tool/edit_constraints.cpp @@ -148,9 +148,15 @@ EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : SEG endSide( end.GetPosition(), nextEnd.GetPosition() ); SEG dragged( origin.GetPosition(), end.GetPosition() ); - if( dragged.Collinear( originSide ) ) + // Used to align lines that are almost collinear + const int alignAngle = 10; + + m_originCollinear = dragged.Angle( originSide ).AsDegrees() < alignAngle; + m_endCollinear = dragged.Angle( endSide ).AsDegrees() < alignAngle; + + if( m_originCollinear ) m_colinearConstraint = m_originSideConstraint; - else if( dragged.Collinear( endSide ) ) + else if( m_endCollinear ) m_colinearConstraint = m_endSideConstraint; } @@ -175,6 +181,9 @@ void EC_CONVERGING::Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid ) m_colinearConstraint->Apply( end, aGrid ); } + if( m_originCollinear && m_endCollinear ) + return; + // The dragged segment SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector ); diff --git a/include/tool/edit_constraints.h b/include/tool/edit_constraints.h index e81d81f2e6..89c5b9a27a 100644 --- a/include/tool/edit_constraints.h +++ b/include/tool/edit_constraints.h @@ -236,6 +236,10 @@ private: ///< Vector that represents the initial direction of the dragged segment. VECTOR2I m_draggedVector; + + ///< Flags to indicate when dragged and neighbouring lines are (almost) collinear. + bool m_originCollinear; + bool m_endCollinear; };