2020-07-03 16:37:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pad.h>
|
|
|
|
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <geometry/polygon_test_point_inside.h>
|
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
|
|
|
|
#include <drc_proto/drc_engine.h>
|
|
|
|
#include <drc_proto/drc_test_provider_clearance_base.h>
|
|
|
|
#include <drc_proto/drc_item.h>
|
|
|
|
#include <drc_proto/drc_rule.h>
|
|
|
|
|
|
|
|
const int UI_EPSILON = Mils2iu( 5 );
|
|
|
|
|
|
|
|
wxPoint test::DRC_TEST_PROVIDER_CLEARANCE_BASE::getLocation( TRACK* aTrack, ZONE_CONTAINER* aConflictZone )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET* conflictOutline;
|
|
|
|
|
2020-07-03 16:37:08 +00:00
|
|
|
PCB_LAYER_ID l = aTrack->GetLayer();
|
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
if( aConflictZone->IsFilled() )
|
2020-07-03 16:37:08 +00:00
|
|
|
conflictOutline = const_cast<SHAPE_POLY_SET*>( &aConflictZone->GetFilledPolysList( l ) );
|
2020-06-19 21:34:19 +00:00
|
|
|
else
|
|
|
|
conflictOutline = aConflictZone->Outline();
|
|
|
|
|
2020-07-03 16:37:08 +00:00
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
wxPoint pt1 = aTrack->GetPosition();
|
|
|
|
wxPoint pt2 = aTrack->GetEnd();
|
|
|
|
|
|
|
|
// If the mid-point is in the zone, then that's a fine place for the marker
|
|
|
|
if( conflictOutline->SquaredDistance( ( pt1 + pt2 ) / 2 ) == 0 )
|
|
|
|
return ( pt1 + pt2 ) / 2;
|
|
|
|
|
|
|
|
// Otherwise do a binary search for a "good enough" marker location
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( GetLineLength( pt1, pt2 ) > UI_EPSILON )
|
|
|
|
{
|
|
|
|
if( conflictOutline->SquaredDistance( pt1 ) < conflictOutline->SquaredDistance( pt2 ) )
|
|
|
|
pt2 = ( pt1 + pt2 ) / 2;
|
|
|
|
else
|
|
|
|
pt1 = ( pt1 + pt2 ) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once we're within UI_EPSILON pt1 and pt2 are "equivalent"
|
|
|
|
return pt1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPoint test::DRC_TEST_PROVIDER_CLEARANCE_BASE::getLocation( TRACK* aTrack, const SEG& aConflictSeg )
|
|
|
|
{
|
|
|
|
wxPoint pt1 = aTrack->GetPosition();
|
|
|
|
wxPoint pt2 = aTrack->GetEnd();
|
|
|
|
|
|
|
|
// Do a binary search along the track for a "good enough" marker location
|
|
|
|
while( GetLineLength( pt1, pt2 ) > UI_EPSILON )
|
|
|
|
{
|
|
|
|
if( aConflictSeg.SquaredDistance( pt1 ) < aConflictSeg.SquaredDistance( pt2 ) )
|
|
|
|
pt2 = ( pt1 + pt2 ) / 2;
|
|
|
|
else
|
|
|
|
pt1 = ( pt1 + pt2 ) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once we're within UI_EPSILON pt1 and pt2 are "equivalent"
|
|
|
|
return pt1;
|
|
|
|
}
|
|
|
|
|