Commit 2d761f30 authored by Marco Mattila's avatar Marco Mattila
Browse files

Fix drawsegment bounding box and hittest issues in pcbnew.

parent 8db19bbd
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -856,7 +856,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly )
    // Check segments, dimensions, texts, and fiducials
    // Check segments, dimensions, texts, and fiducials
    for( BOARD_ITEM* item = m_Drawings; item != NULL; item = item->Next() )
    for( BOARD_ITEM* item = m_Drawings; item != NULL; item = item->Next() )
    {
    {
        if( aBoardEdgesOnly && item->Type() != TYPE_DRAWSEGMENT && item->GetLayer() != EDGE_N )
        if( aBoardEdgesOnly && (item->Type() != TYPE_DRAWSEGMENT || item->GetLayer() != EDGE_N ) )
            continue;
            continue;


        if( !hasItems )
        if( !hasItems )
+16 −13
Original line number Original line Diff line number Diff line
@@ -435,7 +435,10 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const


    case S_ARC:
    case S_ARC:
    {
    {
        bbox.Inflate( GetRadius() + 1 );
        bbox.Merge( m_End );
        wxPoint end = m_End;
        RotatePoint( &end, m_Start, -m_Angle );
        bbox.Merge( end );
    }
    }
    break;
    break;


@@ -492,17 +495,17 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aRefPos )
            if( m_Shape == S_CIRCLE )
            if( m_Shape == S_CIRCLE )
                return true;
                return true;


            int mouseAngle = ArcTangente( relPos.y, relPos.x );
            wxPoint startVec = wxPoint( m_End.x - m_Start.x, m_End.y - m_Start.y );
            int stAngle    = ArcTangente( m_End.y - m_Start.y, m_End.x - m_Start.x );
            wxPoint endVec = m_End - m_Start;
            int endAngle   = stAngle + m_Angle;
            RotatePoint( &endVec, -m_Angle );


            if( endAngle > 3600 )
            // Check dot products
            {
            if( (long long)relPos.x*startVec.x + (long long)relPos.y*startVec.y < 0 )
                stAngle  -= 3600;
                return false;
                endAngle -= 3600;

            }
            if( (long long)relPos.x*endVec.x + (long long)relPos.y*endVec.y < 0 )
                return false;


            if( mouseAngle >= stAngle && mouseAngle <= endAngle )
            return true;
            return true;
        }
        }
    }
    }