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
|
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 <boost/foreach.hpp>
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_utils.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
using boost::optional;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_LINE::PNS_LINE( const PNS_LINE& aOther ) :
|
|
|
|
PNS_ITEM( aOther ),
|
|
|
|
m_line( aOther.m_line ),
|
|
|
|
m_width( aOther.m_width )
|
|
|
|
{
|
|
|
|
m_net = aOther.m_net;
|
|
|
|
m_movable = aOther.m_movable;
|
|
|
|
m_layers = aOther.m_layers;
|
|
|
|
m_owner = aOther.m_owner;
|
|
|
|
m_via = aOther.m_via;
|
|
|
|
m_hasVia = aOther.m_hasVia;
|
|
|
|
m_marker = aOther.m_marker;
|
|
|
|
m_rank = aOther.m_rank;
|
|
|
|
|
|
|
|
copyLinks ( &aOther );
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_LINE::~PNS_LINE()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
if( m_segmentRefs )
|
|
|
|
delete m_segmentRefs;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const PNS_LINE& PNS_LINE::operator=( const PNS_LINE& aOther )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_line = aOther.m_line;
|
|
|
|
m_width = aOther.m_width;
|
|
|
|
m_net = aOther.m_net;
|
|
|
|
m_movable = aOther.m_movable;
|
|
|
|
m_owner = aOther.m_owner;
|
|
|
|
m_layers = aOther.m_layers;
|
|
|
|
m_via = aOther.m_via;
|
|
|
|
m_hasVia = aOther.m_hasVia;
|
|
|
|
m_marker = aOther.m_marker;
|
|
|
|
m_rank = aOther.m_rank;
|
|
|
|
|
|
|
|
copyLinks ( &aOther );
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
PNS_LINE* PNS_LINE::Clone() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
PNS_LINE* l = new PNS_LINE( *this );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return l;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_LINE::Mark( int aMarker )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_marker = aMarker;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
BOOST_FOREACH( PNS_SEGMENT* s, *m_segmentRefs )
|
|
|
|
s->Mark( aMarker );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::Unmark ()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
BOOST_FOREACH( PNS_SEGMENT* s, *m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
s->Unmark();
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_marker = 0;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int PNS_LINE::Marker()const
|
|
|
|
{
|
|
|
|
int marker = m_marker;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
BOOST_FOREACH( PNS_SEGMENT* s, *m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
marker |= s->Marker();
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return marker;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::copyLinks( const PNS_LINE *aParent )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aParent->m_segmentRefs == NULL )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_segmentRefs = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_segmentRefs = new SEGMENT_REFS();
|
2014-05-14 13:53:54 +00:00
|
|
|
*m_segmentRefs = *aParent->m_segmentRefs;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_SEGMENT* PNS_SEGMENT::Clone( ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_SEGMENT* s = new PNS_SEGMENT;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
s->m_seg = m_seg;
|
2013-09-26 21:53:54 +00:00
|
|
|
s->m_net = m_net;
|
|
|
|
s->m_layers = m_layers;
|
2014-05-14 13:53:54 +00:00
|
|
|
s->m_marker = m_marker;
|
|
|
|
s->m_rank = m_rank;
|
|
|
|
s->m_owner = m_owner;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return s;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int PNS_LINE::CountCorners( int aAngles )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int count = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
for( int i = 0; i < m_line.SegmentCount() - 1; i++ )
|
|
|
|
{
|
|
|
|
const SEG seg1 = m_line.CSegment( i );
|
|
|
|
const SEG seg2 = m_line.CSegment( i + 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const DIRECTION_45 dir1( seg1 );
|
|
|
|
const DIRECTION_45 dir2( seg2 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
DIRECTION_45::AngleType a = dir1.Angle( dir2 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( a & aAngles )
|
|
|
|
count++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return count;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_LINE::Walkaround( SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN& aPre,
|
|
|
|
SHAPE_LINE_CHAIN& aWalk, SHAPE_LINE_CHAIN& aPost, bool aCw ) const
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& line ( CLine() );
|
|
|
|
VECTOR2I ip_start;
|
|
|
|
VECTOR2I ip_end;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( line.SegmentCount() < 1 )
|
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aObstacle.PointInside( line.CPoint( 0 ) ) || aObstacle.PointInside( line.CPoint( -1 ) ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS ips, ips2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
line.Intersect( aObstacle, ips );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int nearest_dist = INT_MAX;
|
|
|
|
int farthest_dist = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN::INTERSECTION nearest, farthest;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < (int) ips.size(); i++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
const VECTOR2I p = ips[i].p;
|
2014-05-16 11:37:31 +00:00
|
|
|
int dist = line.PathLength( p );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dist <= nearest_dist )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
nearest_dist = dist;
|
|
|
|
nearest = ips[i];
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dist >= farthest_dist )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
farthest_dist = dist;
|
|
|
|
farthest = ips[i];
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( ips.size() <= 1 || nearest.p == farthest.p )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
aPre = line;
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aPre = line.Slice( 0, nearest.our.Index() );
|
|
|
|
aPre.Append( nearest.p );
|
|
|
|
aPre.Simplify();
|
|
|
|
|
|
|
|
aWalk.Clear();
|
2014-05-16 11:37:31 +00:00
|
|
|
aWalk.SetClosed( false );
|
2014-05-14 13:53:54 +00:00
|
|
|
aWalk.Append( nearest.p );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int i = nearest.their.Index();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
assert( nearest.their.Index() >= 0 );
|
|
|
|
assert( farthest.their.Index() >= 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
assert( nearest_dist <= farthest_dist );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aObstacle.Split( nearest.p );
|
|
|
|
aObstacle.Split( farthest.p );
|
|
|
|
|
|
|
|
int i_first = aObstacle.Find( nearest.p );
|
|
|
|
int i_last = aObstacle.Find( farthest.p );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
i = i_first;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
while( i != i_last )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
aWalk.Append( aObstacle.CPoint( i ) );
|
|
|
|
i += ( aCw ? 1 : -1 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( i < 0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
i = aObstacle.PointCount() - 1;
|
2014-05-16 11:37:31 +00:00
|
|
|
else if( i == aObstacle.PointCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
aWalk.Append( farthest.p );
|
|
|
|
aWalk.Simplify();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aPost.Clear();
|
|
|
|
aPost.Append( farthest.p );
|
|
|
|
aPost.Append( line.Slice( farthest.our.Index() + 1, -1 ) );
|
|
|
|
aPost.Simplify();
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
|
|
|
|
SHAPE_LINE_CHAIN& aPath,
|
|
|
|
bool aCw ) const
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN walk, post;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
Walkaround( aObstacle, aPath, walk, post, aCw );
|
|
|
|
aPath.Append( walk );
|
|
|
|
aPath.Append( post );
|
|
|
|
aPath.Simplify();
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN PNS_SEGMENT::Hull( int aClearance, int aWalkaroundThickness ) const
|
|
|
|
{
|
|
|
|
return SegmentHull ( m_seg, aClearance, aWalkaroundThickness );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_LINE::Is45Degree()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < m_line.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const SEG& s = m_line.CSegment( i );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
double angle = 180.0 / M_PI *
|
|
|
|
atan2( (double) s.B.y - (double) s.A.y,
|
|
|
|
(double) s.B.x - (double) s.A.x );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( angle < 0 )
|
|
|
|
angle += 360.0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
double angle_a = fabs( fmod( angle, 45.0 ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( angle_a > 1.0 && angle_a < 44.0 )
|
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const PNS_LINE PNS_LINE::ClipToNearestObstacle( PNS_NODE* aNode ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_LINE l( *this );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::OPT_OBSTACLE obs = aNode->NearestObstacle( &l );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( obs )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
l.RemoveVia();
|
2014-05-16 11:37:31 +00:00
|
|
|
int p = l.Line().Split( obs->m_ipFirst );
|
2014-05-14 13:53:54 +00:00
|
|
|
l.Line().Remove( p + 1, -1 );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return l;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::ShowLinks()
|
|
|
|
{
|
|
|
|
if( !m_segmentRefs )
|
|
|
|
{
|
|
|
|
printf( "line %p: no links\n", this );
|
|
|
|
return;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
printf( "line %p: %d linked segs\n", this, (int) m_segmentRefs->size() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
for( int i = 0; i < (int) m_segmentRefs->size(); i++ )
|
|
|
|
printf( "seg %d: %p\n", i, (*m_segmentRefs)[i] );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHAPE_LINE_CHAIN dragCornerInternal( const SHAPE_LINE_CHAIN& aOrigin, const VECTOR2I& aP )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
optional<SHAPE_LINE_CHAIN> picked;
|
|
|
|
int i;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int d = 2;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aOrigin.CSegment( -1 ).Length() > 100000 * 30 ) // fixme: constant/parameter?
|
2014-05-14 13:53:54 +00:00
|
|
|
d = 1;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( i = aOrigin.SegmentCount() - d; i >= 0; i-- )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
DIRECTION_45 d_start ( aOrigin.CSegment( i ) );
|
|
|
|
VECTOR2I p_start = aOrigin.CPoint( i );
|
|
|
|
SHAPE_LINE_CHAIN paths[2];
|
2014-05-14 13:53:54 +00:00
|
|
|
DIRECTION_45 dirs[2];
|
2014-05-16 11:37:31 +00:00
|
|
|
DIRECTION_45 d_prev = ( i > 0 ? DIRECTION_45( aOrigin.CSegment( i - 1 ) ) : DIRECTION_45() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int j = 0; j < 2; j++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
paths[j] = d_start.BuildInitialTrace( p_start, aP, j );
|
|
|
|
dirs[j] = DIRECTION_45( paths[j].CSegment( 0 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int j = 0; j < 2; j++ )
|
|
|
|
{
|
|
|
|
if( dirs[j] == d_start )
|
|
|
|
{
|
|
|
|
picked = paths[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( picked )
|
2014-05-14 13:53:54 +00:00
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int j = 0; j < 2; j++ )
|
|
|
|
{
|
|
|
|
if( dirs[j].IsObtuse( d_prev ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
picked = paths[j];
|
|
|
|
break;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( picked )
|
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( picked )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SHAPE_LINE_CHAIN path = aOrigin.Slice( 0, i );
|
|
|
|
path.Append( *picked );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return path;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return DIRECTION_45().BuildInitialTrace( aOrigin.CPoint( 0 ), aP, true );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::DragCorner ( const VECTOR2I& aP, int aIndex, int aSnappingThreshold )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN path;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
VECTOR2I snapped = snapDraggedCorner( m_line, aP, aIndex, aSnappingThreshold );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aIndex == 0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
path = dragCornerInternal( m_line.Reverse(), snapped ).Reverse();
|
|
|
|
else if ( aIndex == m_line.SegmentCount() )
|
|
|
|
path = dragCornerInternal( m_line, snapped );
|
2014-05-16 11:37:31 +00:00
|
|
|
else
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
// fixme: awkward behaviour for "outwards" drags
|
2014-05-16 11:37:31 +00:00
|
|
|
path = dragCornerInternal( m_line.Slice( 0, aIndex ), snapped );
|
|
|
|
SHAPE_LINE_CHAIN path_rev = dragCornerInternal( m_line.Slice( aIndex, -1 ).Reverse(),
|
|
|
|
snapped ).Reverse();
|
|
|
|
path.Append( path_rev );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
path.Simplify();
|
|
|
|
m_line = path;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
VECTOR2I PNS_LINE::snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
|
|
|
|
int aIndex, int aThreshold ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
int s_start = std::max( aIndex - 2, 0 );
|
|
|
|
int s_end = std::min( aIndex + 2, aPath.SegmentCount() - 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int i, j;
|
|
|
|
int best_dist = INT_MAX;
|
|
|
|
VECTOR2I best_snap = aP;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aThreshold <= 0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return aP;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( i = s_start; i <= s_end; i++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
const SEG& a = aPath.CSegment( i );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( j = s_start; j < i; j++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
const SEG& b = aPath.CSegment( j );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !( DIRECTION_45( a ).IsObtuse(DIRECTION_45( b ) ) ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
OPT_VECTOR2I ip = a.IntersectLines(b);
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( ip )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
int dist = ( *ip - aP ).EuclideanNorm();
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( dist < aThreshold && dist < best_dist )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
best_dist = dist;
|
|
|
|
best_snap = *ip;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return best_snap;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I PNS_LINE::snapToNeighbourSegments( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
|
|
|
|
int aIndex, int aThreshold ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
VECTOR2I snap_p[2];
|
2014-05-16 11:37:31 +00:00
|
|
|
DIRECTION_45 dragDir( aPath.CSegment( aIndex ) );
|
|
|
|
int snap_d[2] = { -1, -1 };
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( aThreshold == 0 )
|
|
|
|
return aP;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aIndex >= 2 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG s = aPath.CSegment( aIndex - 2 );
|
|
|
|
|
|
|
|
if( DIRECTION_45( s ) == dragDir )
|
|
|
|
snap_d[0] = s.LineDistance( aP );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
snap_p[0] = s.A;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aIndex < aPath.SegmentCount() - 2 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG s = aPath.CSegment( aIndex + 2 );
|
|
|
|
|
|
|
|
if( DIRECTION_45( s ) == dragDir )
|
2014-05-14 13:53:54 +00:00
|
|
|
snap_d[1] = s.LineDistance(aP);
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
snap_p[1] = s.A;
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I best = aP;
|
|
|
|
int minDist = INT_MAX;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
if( snap_d[i] >= 0 && snap_d[i] < minDist && snap_d[i] <= aThreshold )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
minDist = snap_d[i];
|
|
|
|
best = snap_p[i];
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return best;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::DragSegment ( const VECTOR2I& aP, int aIndex, int aSnappingThreshold )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SHAPE_LINE_CHAIN path( m_line );
|
|
|
|
VECTOR2I target( aP );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SEG guideA[2], guideB[2];
|
|
|
|
int index = aIndex;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
target = snapToNeighbourSegments( path, aP, aIndex, aSnappingThreshold );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( index == 0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
path.Insert( 0, path.CPoint( 0 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
index++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( index == path.SegmentCount() - 1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
path.Insert( path.PointCount() - 1, path.CPoint( -1 ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG dragged = path.CSegment( index );
|
|
|
|
DIRECTION_45 drag_dir( dragged );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG s_prev = path.CSegment( index - 1 );
|
|
|
|
SEG s_next = path.CSegment( index + 1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
DIRECTION_45 dir_prev( s_prev );
|
|
|
|
DIRECTION_45 dir_next( s_next );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dir_prev == drag_dir )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
dir_prev = dir_prev.Left();
|
2014-05-16 11:37:31 +00:00
|
|
|
path.Insert( index, path.CPoint( index ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
index++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dir_next == drag_dir )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
dir_next = dir_next.Right();
|
2014-05-16 11:37:31 +00:00
|
|
|
path.Insert( index + 1, path.CPoint( index + 1 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
s_prev = path.CSegment( index - 1 );
|
|
|
|
s_next = path.CSegment( index + 1 );
|
|
|
|
dragged = path.CSegment( index );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool lockEndpointA = true;
|
|
|
|
bool lockEndpointB = true;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aIndex == 0 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !lockEndpointA )
|
2014-05-14 13:53:54 +00:00
|
|
|
guideA[0] = guideA[1] = SEG( dragged.A, dragged.A + drag_dir.Right().Right().ToVector() );
|
2014-05-16 11:37:31 +00:00
|
|
|
else
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
guideA[0] = SEG( dragged.A, dragged.A + drag_dir.Right().ToVector() );
|
|
|
|
guideA[1] = SEG( dragged.A, dragged.A + drag_dir.Left().ToVector() );
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( dir_prev.IsObtuse(drag_dir ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
guideA[0] = SEG( s_prev.A, s_prev.A + drag_dir.Left().ToVector() );
|
|
|
|
guideA[1] = SEG( s_prev.A, s_prev.A + drag_dir.Right().ToVector() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
guideA[0] = guideA[1] = SEG( dragged.A, dragged.A + dir_prev.ToVector() );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aIndex == m_line.SegmentCount() - 1 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !lockEndpointB )
|
2014-05-14 13:53:54 +00:00
|
|
|
guideB[0] = guideB[1] = SEG( dragged.B, dragged.B + drag_dir.Right().Right().ToVector() );
|
2014-05-16 11:37:31 +00:00
|
|
|
else
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
guideB[0] = SEG( dragged.B, dragged.B + drag_dir.Right().ToVector() );
|
|
|
|
guideB[1] = SEG( dragged.B, dragged.B + drag_dir.Left().ToVector() );
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( dir_next.IsObtuse( drag_dir ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
guideB[0] = SEG( s_next.B, s_next.B + drag_dir.Left().ToVector() );
|
|
|
|
guideB[1] = SEG( s_next.B, s_next.B + drag_dir.Right().ToVector() );
|
|
|
|
}
|
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
guideB[0] = guideB[1] = SEG( dragged.B, dragged.B + dir_next.ToVector() );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG s_current( target, target + drag_dir.ToVector() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int best_len = INT_MAX;
|
|
|
|
SHAPE_LINE_CHAIN best;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int j = 0; j < 2; j++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
OPT_VECTOR2I ip1 = s_current.IntersectLines( guideA[i] );
|
|
|
|
OPT_VECTOR2I ip2 = s_current.IntersectLines( guideB[j] );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHAPE_LINE_CHAIN np;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !ip1 || !ip2 )
|
|
|
|
continue;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SEG s1( s_prev.A, *ip1 );
|
|
|
|
SEG s2( *ip1, *ip2 );
|
|
|
|
SEG s3( *ip2, s_next.B );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
OPT_VECTOR2I ip;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-06-05 10:40:26 +00:00
|
|
|
if( (ip = s1.Intersect( s_next )) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
np.Append ( s1.A );
|
|
|
|
np.Append ( *ip );
|
|
|
|
np.Append ( s_next.B );
|
|
|
|
}
|
2014-06-05 10:40:26 +00:00
|
|
|
else if( (ip = s3.Intersect( s_prev )) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
np.Append ( s_prev.A );
|
|
|
|
np.Append ( *ip );
|
|
|
|
np.Append ( s3.B );
|
|
|
|
}
|
2014-06-05 10:40:26 +00:00
|
|
|
else if( (ip = s1.Intersect( s3 )) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
np.Append( s_prev.A );
|
|
|
|
np.Append( *ip );
|
|
|
|
np.Append( s_next.B );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
np.Append( s_prev.A );
|
|
|
|
np.Append( *ip1 );
|
|
|
|
np.Append( *ip2 );
|
|
|
|
np.Append( s_next.B );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( np.Length() < best_len )
|
|
|
|
{
|
|
|
|
best_len = np.Length();
|
|
|
|
best = np;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !lockEndpointA && aIndex == 0 )
|
|
|
|
best.Remove( 0, 0 );
|
|
|
|
if( !lockEndpointB && aIndex == m_line.SegmentCount() - 1 )
|
|
|
|
best.Remove( -1, -1 );
|
|
|
|
|
|
|
|
if( m_line.PointCount() == 1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
m_line = best;
|
2014-05-16 11:37:31 +00:00
|
|
|
else if( aIndex == 0 )
|
|
|
|
m_line.Replace( 0, 1, best );
|
|
|
|
else if( aIndex == m_line.SegmentCount() - 1 )
|
|
|
|
m_line.Replace( -2, -1, best );
|
2014-05-14 13:53:54 +00:00
|
|
|
else
|
2014-05-16 11:37:31 +00:00
|
|
|
m_line.Replace( aIndex, aIndex + 1, best );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_line.Simplify();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_LINE::CompareGeometry( const PNS_LINE& aOther )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
return m_line.CompareGeometry( aOther.m_line );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::Reverse()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
m_line = m_line.Reverse();
|
|
|
|
|
|
|
|
if( m_segmentRefs )
|
|
|
|
std::reverse( m_segmentRefs->begin(), m_segmentRefs->end() );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_LINE::AppendVia( const PNS_VIA& aVia )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aVia.Pos() == m_line.CPoint( 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
Reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_hasVia = true;
|
|
|
|
m_via = aVia;
|
|
|
|
m_via.SetNet( m_net );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_LINE::SetRank( int aRank )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_rank = aRank;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( m_segmentRefs )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
BOOST_FOREACH( PNS_SEGMENT* s, *m_segmentRefs )
|
|
|
|
s->SetRank( aRank );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int PNS_LINE::Rank() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int min_rank = INT_MAX;
|
|
|
|
int rank;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( m_segmentRefs )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
BOOST_FOREACH( PNS_SEGMENT *s, *m_segmentRefs )
|
2014-05-16 11:37:31 +00:00
|
|
|
min_rank = std::min( min_rank, s->Rank() );
|
|
|
|
rank = ( min_rank == INT_MAX ) ? -1 : min_rank;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
rank = m_rank;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rank;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_LINE::ClipVertexRange( int aStart, int aEnd )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
m_line = m_line.Slice( aStart, aEnd );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_segmentRefs )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SEGMENT_REFS* snew = new SEGMENT_REFS( m_segmentRefs->begin() + aStart,
|
|
|
|
m_segmentRefs->begin() + aEnd );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
delete m_segmentRefs;
|
|
|
|
m_segmentRefs = snew;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_LINE::HasLoops() const
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < PointCount(); i++ )
|
|
|
|
{
|
|
|
|
for( int j = 0; j < PointCount(); j++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( ( std::abs( i - j ) > 1 ) && CPoint( i ) == CPoint( j ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_LINE::ClearSegmentLinks()
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_segmentRefs;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_segmentRefs = NULL;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|