Commit 342fd6e1 authored by Maciej Suminski's avatar Maciej Suminski

EC_CONVERGING handles colinear lines properly.

parent 4d6f628a
...@@ -244,14 +244,14 @@ public: ...@@ -244,14 +244,14 @@ public:
*/ */
bool Collinear( const SEG& aSeg ) const bool Collinear( const SEG& aSeg ) const
{ {
ecoord qa1 = A.y - B.y; ecoord qa = A.y - B.y;
ecoord qb1 = B.x - A.x; ecoord qb = B.x - A.x;
ecoord qc1 = -qa1 * A.x - qb1 * A.y; ecoord qc = -qa * A.x - qb * A.y;
ecoord qa2 = aSeg.A.y - aSeg.B.y;
ecoord qb2 = aSeg.B.x - aSeg.A.x; ecoord d1 = std::abs( aSeg.A.x * qa + aSeg.A.y * qb + qc );
ecoord qc2 = -qa2 * aSeg.A.x - qb2 * aSeg.A.y; ecoord d2 = std::abs( aSeg.B.x * qa + aSeg.B.y * qb + qc );
return ( qa1 == qa2 ) && ( qb1 == qb2 ) && ( qc1 == qc2 ); return ( d1 <= 1 && d2 <= 1 );
} }
/** /**
......
...@@ -194,7 +194,8 @@ void EC_CIRCLE::Apply( EDIT_POINT& aHandle ) ...@@ -194,7 +194,8 @@ void EC_CIRCLE::Apply( EDIT_POINT& aHandle )
EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) :
EDIT_CONSTRAINT<EDIT_POINT>( aLine.GetOrigin() ), m_line( aLine ), m_editPoints( aPoints ) EDIT_CONSTRAINT<EDIT_POINT>( aLine.GetOrigin() ),
m_colinearConstraint( NULL ), m_line( aLine ), m_editPoints( aPoints )
{ {
// Dragged segment endings // Dragged segment endings
EDIT_POINT& origin = aLine.GetOrigin(); EDIT_POINT& origin = aLine.GetOrigin();
...@@ -209,7 +210,17 @@ EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : ...@@ -209,7 +210,17 @@ EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) :
m_endSideConstraint = new EC_LINE( end, nextEnd ); m_endSideConstraint = new EC_LINE( end, nextEnd );
// Store the current vector of the line // Store the current vector of the line
m_draggedVector = end.GetPosition() - origin.GetPosition() ; m_draggedVector = end.GetPosition() - origin.GetPosition();
// Check for colinearity
SEG originSide( origin.GetPosition(), prevOrigin.GetPosition() );
SEG endSide( end.GetPosition(), nextEnd.GetPosition() );
SEG dragged( origin.GetPosition(), end.GetPosition() );
if( dragged.Collinear( originSide ) )
m_colinearConstraint = m_originSideConstraint;
else if( dragged.Collinear( endSide ) )
m_colinearConstraint = m_endSideConstraint;
} }
...@@ -217,18 +228,25 @@ EC_CONVERGING::~EC_CONVERGING() ...@@ -217,18 +228,25 @@ EC_CONVERGING::~EC_CONVERGING()
{ {
delete m_originSideConstraint; delete m_originSideConstraint;
delete m_endSideConstraint; delete m_endSideConstraint;
// m_colinearConstraint should not be freed, it is a pointer to one of the above
} }
void EC_CONVERGING::Apply( EDIT_POINT& aHandle ) void EC_CONVERGING::Apply( EDIT_POINT& aHandle )
{ {
// The dragged segment
SEG dragged( m_line.GetPosition(), m_line.GetPosition() + m_draggedVector );
// The dragged segment endpoints // The dragged segment endpoints
EDIT_POINT& origin = m_line.GetOrigin(); EDIT_POINT& origin = m_line.GetOrigin();
EDIT_POINT& end = m_line.GetEnd(); EDIT_POINT& end = m_line.GetEnd();
if( m_colinearConstraint )
{
m_colinearConstraint->Apply( origin );
m_colinearConstraint->Apply( end );
}
// The dragged segment
SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector );
// Do not allow points on the adjacent segments move freely // Do not allow points on the adjacent segments move freely
m_originSideConstraint->Apply(); m_originSideConstraint->Apply();
m_endSideConstraint->Apply(); m_endSideConstraint->Apply();
......
...@@ -622,6 +622,10 @@ private: ...@@ -622,6 +622,10 @@ private:
///> Constraint for end side segment. ///> Constraint for end side segment.
EDIT_CONSTRAINT<EDIT_POINT>* m_endSideConstraint; EDIT_CONSTRAINT<EDIT_POINT>* m_endSideConstraint;
///> Additional constriant, applied when at least two points are collinear. It is a pointer to
///> m_[origin/end]SideConstraint, so it should not be freed.
EDIT_CONSTRAINT<EDIT_POINT>* m_colinearConstraint;
///> Dragged segment. ///> Dragged segment.
EDIT_LINE& m_line; EDIT_LINE& m_line;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment