Commit 46e82e4e authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Move HitTestForCorner and HitTestForEdge code from class_zone to...

Move HitTestForCorner and HitTestForEdge code from class_zone to polygon/PolyLine.cpp, to avoid redundant code.
Fix bug 1264248.
Fix a very minor issue in RemoveTrailingZeros, for countries where the separator in floating numbers is a comma.
parent 5418a083
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ wxString RemoveTrailingZeros( const wxString& aString )
    while( --i > 0 && retv[i] == wxChar( '0' ) )
        retv.RemoveLast();

    if( retv[i] == wxChar( '.' ) )
    if( retv[i] == wxChar( '.' ) || retv[i] == wxChar( ',' ) )
        retv.RemoveLast();

    return retv;
+5 −61
Original line number Diff line number Diff line
@@ -480,32 +480,12 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition )
// Zones outlines have no thickness, so it Hit Test functions
// we must have a default distance between the test point
// and a corner or a zone edge:
#define MIN_DIST_IN_MILS 10
#define MAX_DIST_IN_MM 0.25

bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
{
    m_CornerSelection = -1;         // Set to not found

    // distance (in internal units) to detect a corner in a zone outline.
    int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;

    wxPoint delta;
    unsigned lim = m_Poly->m_CornersList.GetCornersCount();

    for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
    {
        delta.x = refPos.x - m_Poly->m_CornersList.GetX( item_pos );
        delta.y = refPos.y - m_Poly->m_CornersList.GetY( item_pos );

        // Calculate a distance:
        int dist = std::max( abs( delta.x ), abs( delta.y ) );

        if( dist < min_dist )  // this corner is a candidate:
        {
            m_CornerSelection = item_pos;
            min_dist = dist;
        }
    }
    int distmax = Millimeter2iu( MAX_DIST_IN_MM );
    m_CornerSelection = m_Poly->HitTestForCorner( refPos, distmax );

    return m_CornerSelection >= 0;
}
@@ -513,44 +493,8 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )

bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
{
    unsigned lim = m_Poly->m_CornersList.GetCornersCount();

    m_CornerSelection = -1;     // Set to not found

    // distance (in internal units) to detect a zone outline
    int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;

    unsigned first_corner_pos = 0;

    for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
    {
        unsigned end_segm = item_pos + 1;

        /* the last corner of the current outline is tested
         * the last segment of the current outline starts at current corner, and ends
         * at the first corner of the outline
         */
        if( m_Poly->m_CornersList.IsEndContour ( item_pos ) || end_segm >= lim )
        {
            unsigned tmp = first_corner_pos;
            first_corner_pos = end_segm;    // first_corner_pos is now the beginning of the next outline
            end_segm = tmp;                 // end_segm is the beginning of the current outline
        }

        // test the dist between segment and ref point
        int dist = KiROUND( GetPointToLineSegmentDistance(
                    refPos.x, refPos.y,
                    m_Poly->m_CornersList.GetX( item_pos ),
                    m_Poly->m_CornersList.GetY( item_pos ),
                    m_Poly->m_CornersList.GetX( end_segm ),
                    m_Poly->m_CornersList.GetY( end_segm ) ) );

        if( dist < min_dist )
        {
            m_CornerSelection = item_pos;
            min_dist = dist;
        }
    }
    int distmax = Millimeter2iu( MAX_DIST_IN_MM );
    m_CornerSelection = m_Poly->HitTestForEdge( refPos, distmax );

    return m_CornerSelection >= 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem,
        if( aTrackItem->GetShape() == VIA_MICROVIA )
        {
            if( net )
                new_width = net->GetViaSize();
            else
                new_width = net->GetMicroViaSize();
            else
                new_width = GetBoard()->GetCurrentMicroViaSize();
        }
    }

+3 −1
Original line number Diff line number Diff line
@@ -234,6 +234,8 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC,
        }

        nbconnect--;

        if( pt_del )
            pt_del->SetState( IS_LINKED, false );

        pt_del = GetBoard()->MarkTrace( pt_del, &nb_segm, NULL, NULL, true );
+69 −0
Original line number Diff line number Diff line
@@ -1149,6 +1149,75 @@ int CPolyLine::Distance( const wxPoint& aPoint )
}


/* test is the point aPos is near (< aDistMax ) a vertex
 * return int = the index of the first corner of the vertex, or -1 if not found.
 */
int CPolyLine::HitTestForEdge( const wxPoint& aPos, int aDistMax ) const
{
    unsigned lim = m_CornersList.GetCornersCount();
    int corner = -1;     // Set to not found
    unsigned first_corner_pos = 0;

    for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
    {
        unsigned end_segm = item_pos + 1;

        /* the last corner of the current outline is tested
         * the last segment of the current outline starts at current corner, and ends
         * at the first corner of the outline
         */
        if( m_CornersList.IsEndContour ( item_pos ) || end_segm >= lim )
        {
            unsigned tmp = first_corner_pos;
            first_corner_pos = end_segm;    // first_corner_pos is now the beginning of the next outline
            end_segm = tmp;                 // end_segm is the beginning of the current outline
        }

        // test the dist between segment and ref point
        int dist = KiROUND( GetPointToLineSegmentDistance(
                    aPos.x, aPos.y,
                    m_CornersList.GetX( item_pos ),
                    m_CornersList.GetY( item_pos ),
                    m_CornersList.GetX( end_segm ),
                    m_CornersList.GetY( end_segm ) ) );

        if( dist < aDistMax )
        {
            corner = item_pos;
            aDistMax = dist;
        }
    }

    return corner;
}

/* test is the point aPos is near (< aDistMax ) a corner
 * return int = the index of corner of the, or -1 if not found.
 */
int CPolyLine::HitTestForCorner( const wxPoint& aPos, int aDistMax ) const
{
    int corner = -1;         // Set to not found
    wxPoint delta;
    unsigned lim = m_CornersList.GetCornersCount();

    for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
    {
        delta.x = aPos.x - m_CornersList.GetX( item_pos );
        delta.y = aPos.y - m_CornersList.GetY( item_pos );

        // Calculate a distance:
        int dist = std::max( abs( delta.x ), abs( delta.y ) );

        if( dist < aDistMax )  // this corner is a candidate:
        {
            corner = item_pos;
            aDistMax = dist;
        }
    }

    return corner;
}

/*
 * Copy the contours to a KI_POLYGON_WITH_HOLES
 * The first contour is the main outline, others are holes
Loading