2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pns_utils.h"
|
|
|
|
#include "pns_line.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_via.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_router.h"
|
2022-06-09 18:51:14 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
#include <geometry/shape_arc.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-05-28 16:46:29 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const SHAPE_LINE_CHAIN OctagonalHull( const VECTOR2I& aP0, const VECTOR2I& aSize,
|
|
|
|
int aClearance, int aChamfer )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN s;
|
|
|
|
|
|
|
|
s.SetClosed( true );
|
|
|
|
|
|
|
|
s.Append( aP0.x - aClearance, aP0.y - aClearance + aChamfer );
|
2021-06-07 20:54:30 +00:00
|
|
|
|
|
|
|
if( aChamfer )
|
|
|
|
s.Append( aP0.x - aClearance + aChamfer, aP0.y - aClearance );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
s.Append( aP0.x + aSize.x + aClearance - aChamfer, aP0.y - aClearance );
|
2021-06-07 20:54:30 +00:00
|
|
|
|
|
|
|
if( aChamfer )
|
|
|
|
s.Append( aP0.x + aSize.x + aClearance, aP0.y - aClearance + aChamfer );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
s.Append( aP0.x + aSize.x + aClearance, aP0.y + aSize.y + aClearance - aChamfer );
|
2021-06-07 20:54:30 +00:00
|
|
|
|
|
|
|
if( aChamfer )
|
|
|
|
s.Append( aP0.x + aSize.x + aClearance - aChamfer, aP0.y + aSize.y + aClearance );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
s.Append( aP0.x - aClearance + aChamfer, aP0.y + aSize.y + aClearance );
|
2021-06-07 20:54:30 +00:00
|
|
|
|
|
|
|
if( aChamfer )
|
|
|
|
s.Append( aP0.x - aClearance, aP0.y + aSize.y + aClearance - aChamfer );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return s;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
const SHAPE_LINE_CHAIN ArcHull( const SHAPE_ARC& aSeg, int aClearance, int aWalkaroundThickness )
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
2022-06-03 21:22:15 +00:00
|
|
|
int d = aSeg.GetWidth() / 2 + aClearance + aWalkaroundThickness / 2
|
2022-01-21 23:23:20 +00:00
|
|
|
+ SHAPE_ARC::DefaultAccuracyForPCB();
|
|
|
|
int x = (int) ( 2.0 / ( 1.0 + M_SQRT2 ) * d ) / 2;
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
auto line = aSeg.ConvertToPolyline();
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN s;
|
|
|
|
s.SetClosed( true );
|
|
|
|
std::vector<VECTOR2I> reverse_line;
|
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
auto seg = line.Segment( 0 );
|
2019-05-17 00:13:21 +00:00
|
|
|
VECTOR2I dir = seg.B - seg.A;
|
2022-01-21 23:23:20 +00:00
|
|
|
VECTOR2I p0 = -dir.Perpendicular().Resize( d );
|
|
|
|
VECTOR2I ds = -dir.Perpendicular().Resize( x );
|
2019-05-17 00:13:21 +00:00
|
|
|
VECTOR2I pd = dir.Resize( x );
|
|
|
|
VECTOR2I dp = dir.Resize( d );
|
|
|
|
|
|
|
|
// Append the first curve
|
|
|
|
s.Append( seg.A + p0 - pd );
|
|
|
|
s.Append( seg.A - dp + ds );
|
|
|
|
s.Append( seg.A - dp - ds );
|
|
|
|
s.Append( seg.A - p0 - pd );
|
|
|
|
|
|
|
|
for( int i = 1; i < line.SegmentCount(); i++ )
|
|
|
|
{
|
2022-01-21 23:23:20 +00:00
|
|
|
// calculate a vertex normal (average of segment normals)
|
|
|
|
auto pp =
|
|
|
|
( line.CSegment( i - 1 ).B - line.CSegment( i - 1 ).A ).Perpendicular().Resize( d );
|
|
|
|
auto pp2 = ( line.CSegment( i ).B - line.CSegment( i ).A ).Perpendicular().Resize( d );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
auto sa_out = line.CSegment( i - 1 ), sa_in = line.CSegment( i - 1 );
|
|
|
|
auto sb_out = line.CSegment( i ), sb_in = line.CSegment( i );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
sa_out.A += pp;
|
|
|
|
sa_out.B += pp;
|
|
|
|
sb_out.A += pp2;
|
|
|
|
sb_out.B += pp2;
|
|
|
|
|
|
|
|
sa_in.A -= pp;
|
|
|
|
sa_in.B -= pp;
|
|
|
|
sb_in.A -= pp2;
|
|
|
|
sb_in.B -= pp2;
|
|
|
|
|
|
|
|
auto ip_out = sa_out.IntersectLines( sb_out );
|
|
|
|
auto ip_in = sa_in.IntersectLines( sb_in );
|
|
|
|
|
|
|
|
seg = line.CSegment( i );
|
|
|
|
auto lead = ( pp + pp2 ) / 2;
|
|
|
|
|
|
|
|
s.Append( *ip_out );
|
|
|
|
reverse_line.push_back( *ip_in );
|
2019-05-17 00:13:21 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
seg = line.CSegment( -1 );
|
|
|
|
dir = seg.B - seg.A;
|
|
|
|
p0 = -dir.Perpendicular().Resize( d );
|
|
|
|
ds = -dir.Perpendicular().Resize( x );
|
2019-05-17 00:13:21 +00:00
|
|
|
pd = dir.Resize( x );
|
|
|
|
dp = dir.Resize( d );
|
|
|
|
s.Append( seg.B - p0 + pd );
|
|
|
|
s.Append( seg.B + dp - ds );
|
|
|
|
s.Append( seg.B + dp + ds );
|
|
|
|
s.Append( seg.B + p0 + pd );
|
|
|
|
|
|
|
|
for( int i = reverse_line.size() - 1; i >= 0; i-- )
|
|
|
|
s.Append( reverse_line[i] );
|
|
|
|
|
2022-01-21 23:23:20 +00:00
|
|
|
// make sure the hull outline is always clockwise
|
2019-05-17 00:13:21 +00:00
|
|
|
// make sure the hull outline is always clockwise
|
|
|
|
if( s.CSegment( 0 ).Side( line.Segment( 0 ).A ) < 0 )
|
|
|
|
return s.Reverse();
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-07 21:22:35 +00:00
|
|
|
static bool IsSegment45Degree( const SEG& aS )
|
|
|
|
{
|
2022-06-09 18:51:14 +00:00
|
|
|
VECTOR2I dir( aS.B - aS.A );
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2022-06-09 18:51:14 +00:00
|
|
|
if( std::abs( dir.x ) <= 1 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( std::abs( dir.y ) <= 1 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
int delta = std::abs(dir.x) - std::abs(dir.y);
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2022-06-09 18:51:14 +00:00
|
|
|
if( delta >= -1 && delta <= 1)
|
|
|
|
return true;
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2022-06-09 18:51:14 +00:00
|
|
|
return false;
|
2022-06-07 21:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> int sgn(T val) {
|
|
|
|
return (T(0) < val) - (val < T(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const SHAPE_LINE_CHAIN SegmentHull ( const SHAPE_SEGMENT& aSeg, int aClearance,
|
|
|
|
int aWalkaroundThickness )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-06-09 18:51:14 +00:00
|
|
|
const int kinkThreshold = aClearance / 10;
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2022-06-03 21:22:15 +00:00
|
|
|
int cl = aClearance + aWalkaroundThickness / 2;
|
2022-06-07 21:22:35 +00:00
|
|
|
double d = (double)aSeg.GetWidth() / 2.0 + cl;
|
2022-06-08 22:33:06 +00:00
|
|
|
double x = 2.0 / ( 1.0 + M_SQRT2 ) * d;
|
2022-06-07 21:22:35 +00:00
|
|
|
int dr = KiROUND( d );
|
|
|
|
int xr = KiROUND( x );
|
|
|
|
int xr2 = KiROUND( x / 2.0 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
const VECTOR2I a = aSeg.GetSeg().A;
|
2022-06-07 21:22:35 +00:00
|
|
|
VECTOR2I b = aSeg.GetSeg().B;
|
|
|
|
int len = aSeg.GetSeg().Length();
|
2022-06-09 18:51:14 +00:00
|
|
|
int w = b.x - a.x;
|
|
|
|
int h = b.y - a.y;
|
|
|
|
|
|
|
|
/*
|
|
|
|
auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2022-06-09 18:51:14 +00:00
|
|
|
if( len < kinkThreshold )
|
2022-06-07 21:22:35 +00:00
|
|
|
{
|
2022-06-09 18:51:14 +00:00
|
|
|
PNS_DBG( dbg, AddShape, &aSeg, CYAN, 10000, wxString::Format( "kinky-seg 45 %d l %d dx %d dy %d", !!IsSegment45Degree( aSeg.GetSeg() ), len, w, h ) );
|
|
|
|
}
|
|
|
|
*/
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2023-01-09 22:21:58 +00:00
|
|
|
if( a != b )
|
2022-06-09 18:51:14 +00:00
|
|
|
{
|
2023-01-09 22:21:58 +00:00
|
|
|
if ( !IsSegment45Degree( aSeg.GetSeg() ) )
|
2022-06-09 18:51:14 +00:00
|
|
|
{
|
2023-01-09 22:21:58 +00:00
|
|
|
if ( len <= kinkThreshold && len > 0 )
|
|
|
|
{
|
|
|
|
int ll = std::max( std::abs( w ), std::abs( h ) );
|
2022-06-07 21:22:35 +00:00
|
|
|
|
2023-01-09 22:21:58 +00:00
|
|
|
b = a + VECTOR2I( sgn( w ) * ll, sgn( h ) * ll );
|
|
|
|
}
|
2022-06-09 18:51:14 +00:00
|
|
|
}
|
2023-01-09 22:21:58 +00:00
|
|
|
else
|
2022-06-09 18:51:14 +00:00
|
|
|
{
|
2023-01-09 22:21:58 +00:00
|
|
|
if( len <= kinkThreshold )
|
2022-06-09 18:51:14 +00:00
|
|
|
{
|
2023-01-09 22:21:58 +00:00
|
|
|
int delta45 = std::abs( std::abs(w) - std::abs(h) );
|
|
|
|
if( std::abs(w) <= 1 ) // almost vertical
|
|
|
|
{
|
|
|
|
w = 0;
|
|
|
|
cl ++;
|
|
|
|
}
|
|
|
|
else if ( std::abs(h) <= 1 ) // almost horizontal
|
|
|
|
{
|
|
|
|
h = 0;
|
|
|
|
cl ++;
|
|
|
|
}
|
|
|
|
else if ( delta45 <= 2 ) // almost 45 degree
|
|
|
|
{
|
|
|
|
int newW = sgn( w ) * std::max( std::abs(w), std::abs( h ) );
|
|
|
|
int newH = sgn( h ) * std::max( std::abs(w), std::abs( h ) );
|
|
|
|
w = newW;
|
|
|
|
h = newH;
|
|
|
|
cl += 2;
|
|
|
|
//PNS_DBG( dbg, AddShape, &aSeg, CYAN, 10000, wxString::Format( "almostkinky45 45 %d l %d dx %d dy %d", !!IsSegment45Degree( aSeg.GetSeg() ), len, w, h ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b.x = a.x + w;
|
|
|
|
b.y = a.y + h;
|
2022-06-09 18:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 21:22:35 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( a == b )
|
|
|
|
{
|
2023-01-09 22:21:58 +00:00
|
|
|
int xx2 = KiROUND( 2.0 * ( 1.0 - M_SQRT1_2 ) * d );
|
2022-06-08 22:33:06 +00:00
|
|
|
|
2023-01-09 22:21:58 +00:00
|
|
|
auto ohull = OctagonalHull( a - VECTOR2I( aSeg.GetWidth() / 2, aSeg.GetWidth() / 2 ),
|
2021-01-01 00:29:05 +00:00
|
|
|
VECTOR2I( aSeg.GetWidth(), aSeg.GetWidth() ),
|
2022-06-03 21:22:15 +00:00
|
|
|
cl,
|
2022-06-08 22:33:06 +00:00
|
|
|
xx2 );
|
2023-01-09 22:21:58 +00:00
|
|
|
|
|
|
|
return ohull;
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
VECTOR2I dir = b - a;
|
2022-06-07 21:22:35 +00:00
|
|
|
VECTOR2I p0 = dir.Perpendicular().Resize( dr );
|
|
|
|
VECTOR2I ds = dir.Perpendicular().Resize( xr2 );
|
|
|
|
VECTOR2I pd = dir.Resize( xr2 );
|
|
|
|
VECTOR2I dp = dir.Resize( dr );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN s;
|
|
|
|
|
|
|
|
s.SetClosed( true );
|
|
|
|
|
|
|
|
s.Append( b + p0 + pd );
|
|
|
|
s.Append( b + dp + ds );
|
|
|
|
s.Append( b + dp - ds );
|
|
|
|
s.Append( b - p0 + pd );
|
|
|
|
s.Append( a - p0 - pd );
|
|
|
|
s.Append( a - dp - ds );
|
|
|
|
s.Append( a - dp + ds );
|
|
|
|
s.Append( a + p0 - pd );
|
|
|
|
|
|
|
|
// make sure the hull outline is always clockwise
|
|
|
|
if( s.CSegment( 0 ).Side( a ) < 0 )
|
|
|
|
return s.Reverse();
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
static void MoveDiagonal( SEG& aDiagonal, const SHAPE_LINE_CHAIN& aVertices, int aClearance )
|
2015-07-02 14:09:43 +00:00
|
|
|
{
|
|
|
|
int dist;
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
aVertices.NearestPoint( aDiagonal, dist );
|
|
|
|
VECTOR2I moveBy = ( aDiagonal.A - aDiagonal.B ).Perpendicular().Resize( dist - aClearance );
|
|
|
|
aDiagonal.A += moveBy;
|
|
|
|
aDiagonal.B += moveBy;
|
2015-07-02 14:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
const SHAPE_LINE_CHAIN ConvexHull( const SHAPE_SIMPLE& aConvex, int aClearance )
|
2015-07-02 14:09:43 +00:00
|
|
|
{
|
|
|
|
// this defines the horizontal and vertical lines in the hull octagon
|
2022-06-03 21:22:15 +00:00
|
|
|
BOX2I box = aConvex.BBox( aClearance );
|
2015-07-02 14:09:43 +00:00
|
|
|
box.Normalize();
|
|
|
|
|
|
|
|
SEG topline = SEG( VECTOR2I( box.GetX(), box.GetY() + box.GetHeight() ),
|
|
|
|
VECTOR2I( box.GetX() + box.GetWidth(), box.GetY() + box.GetHeight() ) );
|
|
|
|
SEG rightline = SEG( VECTOR2I( box.GetX() + box.GetWidth(), box.GetY() + box.GetHeight() ),
|
|
|
|
VECTOR2I( box.GetX() + box.GetWidth(), box.GetY() ) );
|
|
|
|
SEG bottomline = SEG( VECTOR2I( box.GetX() + box.GetWidth(), box.GetY() ),
|
|
|
|
box.GetOrigin() );
|
|
|
|
SEG leftline = SEG( box.GetOrigin(), VECTOR2I( box.GetX(), box.GetY() + box.GetHeight() ) );
|
|
|
|
|
2017-06-22 07:01:29 +00:00
|
|
|
const SHAPE_LINE_CHAIN& vertices = aConvex.Vertices();
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
// top right diagonal
|
|
|
|
VECTOR2I corner = box.GetOrigin() + box.GetSize();
|
|
|
|
SEG toprightline = SEG( corner,
|
|
|
|
corner + VECTOR2I( box.GetHeight(), -box.GetHeight() ) );
|
2015-07-02 14:11:15 +00:00
|
|
|
MoveDiagonal( toprightline, vertices, aClearance );
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
// bottom right diagonal
|
|
|
|
corner = box.GetOrigin() + VECTOR2I( box.GetWidth(), 0 );
|
|
|
|
SEG bottomrightline = SEG( corner + VECTOR2I( box.GetHeight(), box.GetHeight() ),
|
|
|
|
corner );
|
2015-07-02 14:11:15 +00:00
|
|
|
MoveDiagonal( bottomrightline, vertices, aClearance );
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
// bottom left diagonal
|
|
|
|
corner = box.GetOrigin();
|
|
|
|
SEG bottomleftline = SEG( corner,
|
|
|
|
corner + VECTOR2I( -box.GetHeight(), box.GetHeight() ) );
|
2015-07-02 14:11:15 +00:00
|
|
|
MoveDiagonal( bottomleftline, vertices, aClearance );
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
// top left diagonal
|
|
|
|
corner = box.GetOrigin() + VECTOR2I( 0, box.GetHeight() );
|
|
|
|
SEG topleftline = SEG( corner + VECTOR2I( -box.GetHeight(), -box.GetHeight() ),
|
|
|
|
corner );
|
2015-07-02 14:11:15 +00:00
|
|
|
MoveDiagonal( topleftline, vertices, aClearance );
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN octagon;
|
|
|
|
octagon.SetClosed( true );
|
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
octagon.Append( *leftline.IntersectLines( bottomleftline ) );
|
|
|
|
octagon.Append( *bottomline.IntersectLines( bottomleftline ) );
|
|
|
|
octagon.Append( *bottomline.IntersectLines( bottomrightline ) );
|
|
|
|
octagon.Append( *rightline.IntersectLines( bottomrightline ) );
|
|
|
|
octagon.Append( *rightline.IntersectLines( toprightline ) );
|
|
|
|
octagon.Append( *topline.IntersectLines( toprightline ) );
|
|
|
|
octagon.Append( *topline.IntersectLines( topleftline ) );
|
|
|
|
octagon.Append( *leftline.IntersectLines( topleftline ) );
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
return octagon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_RECT ApproximateSegmentAsRect( const SHAPE_SEGMENT& aSeg )
|
|
|
|
{
|
|
|
|
SHAPE_RECT r;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I delta( aSeg.GetWidth() / 2, aSeg.GetWidth() / 2 );
|
|
|
|
VECTOR2I p0( aSeg.GetSeg().A - delta );
|
|
|
|
VECTOR2I p1( aSeg.GetSeg().B + delta );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return SHAPE_RECT( std::min( p0.x, p1.x ), std::min( p0.y, p1.y ),
|
|
|
|
std::abs( p1.x - p0.x ), std::abs( p1.y - p0.y ) );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_BOX2I ChangedArea( const ITEM* aItemA, const ITEM* aItemB )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( aItemA->OfKind( ITEM::VIA_T ) && aItemB->OfKind( ITEM::VIA_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const VIA* va = static_cast<const VIA*>( aItemA );
|
|
|
|
const VIA* vb = static_cast<const VIA*>( aItemB );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
return va->ChangedArea( vb );
|
|
|
|
}
|
2016-08-29 17:31:13 +00:00
|
|
|
else if( aItemA->OfKind( ITEM::LINE_T ) && aItemB->OfKind( ITEM::LINE_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE* la = static_cast<const LINE*> ( aItemA );
|
|
|
|
const LINE* lb = static_cast<const LINE*> ( aItemB );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
return la->ChangedArea( lb );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return OPT_BOX2I();
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
OPT_BOX2I ChangedArea( const LINE& aLineA, const LINE& aLineB )
|
|
|
|
{
|
|
|
|
return aLineA.ChangedArea( &aLineB );
|
|
|
|
}
|
|
|
|
|
2021-05-27 21:57:28 +00:00
|
|
|
|
|
|
|
void HullIntersection( const SHAPE_LINE_CHAIN& hull, const SHAPE_LINE_CHAIN& line,
|
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS& ips )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS ips_raw;
|
|
|
|
|
2021-05-30 22:20:32 +00:00
|
|
|
if( line.PointCount() < 2 )
|
|
|
|
return;
|
|
|
|
|
2021-05-27 21:57:28 +00:00
|
|
|
hull.Intersect( line, ips_raw );
|
|
|
|
|
2021-06-03 20:33:38 +00:00
|
|
|
for( auto& p : ips_raw )
|
2021-05-27 21:57:28 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN::INTERSECTION ipp;
|
|
|
|
|
|
|
|
SEG d1[2];
|
|
|
|
VECTOR2I d2[2];
|
|
|
|
int d1_idx = 0, d2_idx = 0;
|
|
|
|
|
|
|
|
ipp = p;
|
|
|
|
ipp.valid = false;
|
|
|
|
|
|
|
|
if( !p.is_corner_our && !p.is_corner_their )
|
|
|
|
{
|
|
|
|
ipp.valid = true;
|
|
|
|
ips.push_back( ipp );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-03 20:33:38 +00:00
|
|
|
if( p.index_our >= hull.SegmentCount() )
|
|
|
|
p.index_our -= hull.SegmentCount();
|
|
|
|
|
2021-05-27 21:57:28 +00:00
|
|
|
if( p.is_corner_our )
|
|
|
|
{
|
|
|
|
d1[0] = hull.CSegment( p.index_our );
|
|
|
|
d1[1] = hull.CSegment( p.index_our - 1 );
|
|
|
|
d1_idx = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d1[0] = hull.CSegment( p.index_our );
|
|
|
|
d1_idx = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( p.is_corner_their )
|
|
|
|
{
|
|
|
|
if( p.index_their > 0 )
|
|
|
|
{
|
|
|
|
d2[d2_idx++] = line.CSegment( p.index_their - 1 ).A;
|
|
|
|
}
|
|
|
|
if( p.index_their < line.PointCount() - 1 )
|
|
|
|
{
|
|
|
|
d2[d2_idx++] = line.CSegment( p.index_their ).B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d2[d2_idx++] = line.CSegment( p.index_their ).A;
|
|
|
|
d2[d2_idx++] = line.CSegment( p.index_their ).B;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 0; i < d1_idx; i++ )
|
|
|
|
{
|
|
|
|
for( int j = 0; j < d2_idx; j++ )
|
|
|
|
{
|
|
|
|
if( d1[i].Side( d2[j] ) > 0 )
|
|
|
|
{
|
|
|
|
ipp.valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TOM_EXTRA_DEBUG
|
|
|
|
printf("p %d %d hi %d their %d co %d ct %d ipv %d\n", p.p.x, p.p.y, p.index_our, p.index_their, p.is_corner_our?1:0, p.is_corner_their?1:0, ipp.valid ?1:0);
|
|
|
|
printf("d1 %d d2 %d\n", d1_idx, d2_idx );
|
|
|
|
#endif
|
|
|
|
if( ipp.valid )
|
|
|
|
{
|
|
|
|
ips.push_back( ipp );
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
2021-05-27 21:57:28 +00:00
|
|
|
|
2021-06-03 20:33:38 +00:00
|
|
|
}
|