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

EC_CONVERGING handles colinear lines properly.

parent 4d6f628a
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -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 );
    }
    }


    /**
    /**
+23 −5
Original line number Original line Diff line number Diff line
@@ -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();
@@ -210,6 +211,16 @@ EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) :


    // 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()
{
{
    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();
+4 −0
Original line number Original line Diff line number Diff line
@@ -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;