Improve EC_CONVERGING behaviour when lines are almost collinear.

(somewhat)
This commit is contained in:
Alex 2023-03-16 05:41:58 +03:00
parent 98e635869f
commit fc6279a2ea
2 changed files with 15 additions and 2 deletions

View File

@ -148,9 +148,15 @@ EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) :
SEG endSide( end.GetPosition(), nextEnd.GetPosition() ); SEG endSide( end.GetPosition(), nextEnd.GetPosition() );
SEG dragged( origin.GetPosition(), end.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; m_colinearConstraint = m_originSideConstraint;
else if( dragged.Collinear( endSide ) ) else if( m_endCollinear )
m_colinearConstraint = m_endSideConstraint; m_colinearConstraint = m_endSideConstraint;
} }
@ -175,6 +181,9 @@ void EC_CONVERGING::Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid )
m_colinearConstraint->Apply( end, aGrid ); m_colinearConstraint->Apply( end, aGrid );
} }
if( m_originCollinear && m_endCollinear )
return;
// The dragged segment // The dragged segment
SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector ); SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector );

View File

@ -236,6 +236,10 @@ private:
///< Vector that represents the initial direction of the dragged segment. ///< Vector that represents the initial direction of the dragged segment.
VECTOR2I m_draggedVector; VECTOR2I m_draggedVector;
///< Flags to indicate when dragged and neighbouring lines are (almost) collinear.
bool m_originCollinear;
bool m_endCollinear;
}; };