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
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 2016-2020 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
|
|
|
*/
|
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
|
|
|
#include "pns_walkaround.h"
|
|
|
|
#include "pns_optimizer.h"
|
|
|
|
#include "pns_utils.h"
|
|
|
|
#include "pns_router.h"
|
2020-02-19 17:22:37 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void WALKAROUND::start( const LINE& aInitialPath )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_iteration = 0;
|
2014-05-16 11:37:31 +00:00
|
|
|
m_iterationLimit = 50;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE WALKAROUND::nearestObstacle( const LINE& aPath )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE obs = m_world->NearestObstacle( &aPath, m_itemMask, m_restrictedSet.empty() ? NULL : &m_restrictedSet );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
if( m_restrictedSet.empty() )
|
|
|
|
return obs;
|
|
|
|
|
|
|
|
else if( obs && m_restrictedSet.find ( obs->m_item ) != m_restrictedSet.end() )
|
|
|
|
return obs;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
return NODE::OPT_OBSTACLE();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND::WALKAROUND_STATUS WALKAROUND::singleStep( LINE& aPath,
|
2014-05-16 11:37:31 +00:00
|
|
|
bool aWindingDirection )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
OPT<OBSTACLE>& current_obs =
|
2013-09-26 21:53:54 +00:00
|
|
|
aWindingDirection ? m_currentObstacle[0] : m_currentObstacle[1];
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !current_obs )
|
|
|
|
return DONE;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN path_pre[2], path_walk[2], path_post[2];
|
|
|
|
|
2020-07-22 21:06:53 +00:00
|
|
|
if( aPath.PointCount() > 1 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-07-22 21:06:53 +00:00
|
|
|
VECTOR2I last = aPath.CPoint( -1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-07-22 21:06:53 +00:00
|
|
|
if( ( current_obs->m_hull ).PointInside( last ) || ( current_obs->m_hull ).PointOnEdge( last ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-07-22 21:06:53 +00:00
|
|
|
m_recursiveBlockageCount++;
|
|
|
|
|
|
|
|
if( m_recursiveBlockageCount < 3 )
|
|
|
|
aPath.Line().Append( current_obs->m_hull.NearestPoint( last ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aPath = aPath.ClipToNearestObstacle( m_world );
|
|
|
|
return DONE;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 21:06:53 +00:00
|
|
|
aPath.Walkaround( current_obs->m_hull, path_pre[0], path_walk[0],
|
2020-02-19 17:22:37 +00:00
|
|
|
path_post[0], aWindingDirection );
|
|
|
|
aPath.Walkaround( current_obs->m_hull, path_pre[1], path_walk[1],
|
|
|
|
path_post[1], !aWindingDirection );
|
2018-05-02 22:05:39 +00:00
|
|
|
|
2020-07-22 21:06:53 +00:00
|
|
|
if( !aPath.Walkaround( current_obs->m_hull, path_pre[1], path_walk[1],
|
2018-05-02 22:05:39 +00:00
|
|
|
path_post[1], !aWindingDirection ) )
|
|
|
|
return STUCK;
|
2020-02-19 17:22:37 +00:00
|
|
|
auto l =aPath.CLine();
|
2020-04-16 22:29:28 +00:00
|
|
|
|
|
|
|
#if 0
|
2020-02-19 17:22:37 +00:00
|
|
|
if( m_logger )
|
|
|
|
{
|
|
|
|
m_logger->NewGroup( aWindingDirection ? "walk-cw" : "walk-ccw", m_iteration );
|
|
|
|
m_logger->Log( &path_walk[0], 0, "path_walk" );
|
|
|
|
m_logger->Log( &path_pre[0], 1, "path_pre" );
|
|
|
|
m_logger->Log( &path_post[0], 4, "path_post" );
|
|
|
|
m_logger->Log( ¤t_obs->m_hull, 2, "hull" );
|
|
|
|
m_logger->Log( current_obs->m_item, 3, "item" );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
if ( Dbg() )
|
|
|
|
{
|
|
|
|
char name[128];
|
|
|
|
snprintf(name, sizeof(name), "hull-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
|
|
|
|
Dbg()->AddLine( current_obs->m_hull, 0, 1, name);
|
|
|
|
snprintf(name, sizeof(name), "path-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
|
|
|
|
Dbg()->AddLine( aPath.CLine(), 1, 1, name );
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
int len_pre = path_walk[0].Length();
|
|
|
|
int len_alt = path_walk[1].Length();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE walk_path( aPath, path_walk[1] );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-22 08:46:45 +00:00
|
|
|
bool alt_collides = static_cast<bool>( m_world->CheckColliding( &walk_path, m_itemMask ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN pnew;
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
/*if( !m_forceLongerPath && len_alt < len_pre && !alt_collides && !prev_recursive )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
pnew = path_pre[1];
|
|
|
|
pnew.Append( path_walk[1] );
|
|
|
|
pnew.Append( path_post[1] );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !path_post[1].PointCount() || !path_walk[1].PointCount() )
|
2016-08-29 17:31:13 +00:00
|
|
|
current_obs = nearestObstacle( LINE( aPath, path_pre[1] ) );
|
2014-11-14 18:17:01 +00:00
|
|
|
else
|
2016-08-29 17:31:13 +00:00
|
|
|
current_obs = nearestObstacle( LINE( aPath, path_post[1] ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2020-02-19 17:22:37 +00:00
|
|
|
else*/
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
pnew = path_pre[0];
|
|
|
|
pnew.Append( path_walk[0] );
|
|
|
|
pnew.Append( path_post[0] );
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
if( path_post[0].PointCount() == 0 || path_walk[0].PointCount() == 0 )
|
2016-08-29 17:31:13 +00:00
|
|
|
current_obs = nearestObstacle( LINE( aPath, path_pre[0] ) );
|
2014-11-14 18:17:01 +00:00
|
|
|
else
|
2016-08-29 17:31:13 +00:00
|
|
|
current_obs = nearestObstacle( LINE( aPath, path_walk[0] ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( !current_obs )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
current_obs = nearestObstacle( LINE( aPath, path_post[0] ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pnew.Simplify();
|
|
|
|
aPath.SetShape( pnew );
|
|
|
|
|
|
|
|
return IN_PROGRESS;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
|
|
|
|
bool clipToLoopStart( SHAPE_LINE_CHAIN& l )
|
|
|
|
{
|
|
|
|
auto ip = l.SelfIntersecting();
|
|
|
|
|
|
|
|
if(!ip)
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
int pidx = l.Split( ip->p );
|
|
|
|
auto lead = l.Slice(0, pidx);
|
|
|
|
auto tail = l.Slice(pidx + 1, -1);
|
|
|
|
|
|
|
|
int pidx2 = tail.Split( ip->p );
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
|
|
|
dbg->AddPoint( ip->p, 5 );
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
l = lead;
|
|
|
|
l.Append( tail.Slice( 0, pidx2 ) );
|
|
|
|
//l = l.Slice(0, pidx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath )
|
|
|
|
{
|
|
|
|
LINE path_cw( aInitialPath ), path_ccw( aInitialPath );
|
|
|
|
WALKAROUND_STATUS s_cw = IN_PROGRESS, s_ccw = IN_PROGRESS;
|
|
|
|
SHAPE_LINE_CHAIN best_path;
|
|
|
|
RESULT result;
|
|
|
|
|
|
|
|
// special case for via-in-the-middle-of-track placement
|
|
|
|
if( aInitialPath.PointCount() <= 1 )
|
|
|
|
{
|
|
|
|
if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
|
|
|
|
return RESULT( STUCK, STUCK );
|
|
|
|
|
|
|
|
return RESULT( DONE, DONE, aInitialPath, aInitialPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
start( aInitialPath );
|
|
|
|
|
|
|
|
m_currentObstacle[0] = m_currentObstacle[1] = nearestObstacle( aInitialPath );
|
|
|
|
m_recursiveBlockageCount = 0;
|
|
|
|
|
|
|
|
result.lineCw = aInitialPath;
|
|
|
|
result.lineCcw = aInitialPath;
|
|
|
|
|
|
|
|
if( m_forceWinding )
|
|
|
|
{
|
|
|
|
s_cw = m_forceCw ? IN_PROGRESS : STUCK;
|
|
|
|
s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
|
|
|
|
m_forceSingleDirection = true;
|
|
|
|
} else {
|
|
|
|
m_forceSingleDirection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( m_iteration < m_iterationLimit )
|
|
|
|
{
|
|
|
|
if( s_cw != STUCK )
|
|
|
|
s_cw = singleStep( path_cw, true );
|
|
|
|
|
|
|
|
if( s_ccw != STUCK )
|
|
|
|
s_ccw = singleStep( path_ccw, false );
|
|
|
|
|
|
|
|
auto old = path_cw.CLine();
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( clipToLoopStart( path_cw.Line() ) )
|
2020-02-19 17:22:37 +00:00
|
|
|
s_cw = ALMOST_DONE;
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( clipToLoopStart( path_ccw.Line() ) )
|
2020-02-19 17:22:37 +00:00
|
|
|
s_ccw = ALMOST_DONE;
|
|
|
|
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
if( s_cw != IN_PROGRESS )
|
|
|
|
{
|
|
|
|
result.lineCw = path_cw;
|
|
|
|
result.statusCw = s_cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( s_ccw != IN_PROGRESS )
|
|
|
|
{
|
|
|
|
result.lineCcw = path_ccw;
|
|
|
|
result.statusCcw = s_ccw;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( s_cw != IN_PROGRESS && s_ccw != IN_PROGRESS )
|
|
|
|
break;
|
|
|
|
|
|
|
|
m_iteration++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( s_cw == IN_PROGRESS )
|
|
|
|
{
|
|
|
|
result.lineCw = path_cw;
|
|
|
|
result.statusCw = ALMOST_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( s_ccw == IN_PROGRESS )
|
|
|
|
{
|
|
|
|
result.lineCcw = path_ccw;
|
|
|
|
result.statusCcw = ALMOST_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.lineCw.Line().Simplify();
|
|
|
|
result.lineCcw.Line().Simplify();
|
|
|
|
|
|
|
|
if( result.lineCw.SegmentCount() < 1 || result.lineCw.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
|
|
|
|
{
|
|
|
|
result.statusCw = STUCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.lineCw.PointCount() > 0 && result.lineCw.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
|
|
|
|
{
|
|
|
|
result.statusCw = ALMOST_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.lineCcw.SegmentCount() < 1 || result.lineCcw.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
|
|
|
|
{
|
|
|
|
result.statusCcw = STUCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.lineCcw.PointCount() > 0 && result.lineCcw.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
|
|
|
|
{
|
|
|
|
result.statusCcw = ALMOST_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
|
|
|
|
LINE& aWalkPath, bool aOptimize )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE path_cw( aInitialPath ), path_ccw( aInitialPath );
|
2015-03-03 11:59:26 +00:00
|
|
|
WALKAROUND_STATUS s_cw = IN_PROGRESS, s_ccw = IN_PROGRESS;
|
2013-09-26 21:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN best_path;
|
|
|
|
|
2015-07-02 14:09:24 +00:00
|
|
|
// special case for via-in-the-middle-of-track placement
|
|
|
|
if( aInitialPath.PointCount() <= 1 )
|
|
|
|
{
|
2015-07-10 21:42:05 +00:00
|
|
|
if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
|
|
|
|
return STUCK;
|
2015-07-02 14:09:24 +00:00
|
|
|
|
|
|
|
aWalkPath = aInitialPath;
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
start( aInitialPath );
|
|
|
|
|
|
|
|
m_currentObstacle[0] = m_currentObstacle[1] = nearestObstacle( aInitialPath );
|
|
|
|
m_recursiveBlockageCount = 0;
|
|
|
|
|
|
|
|
aWalkPath = aInitialPath;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_forceWinding )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
s_cw = m_forceCw ? IN_PROGRESS : STUCK;
|
|
|
|
s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
|
|
|
|
m_forceSingleDirection = true;
|
|
|
|
} else {
|
|
|
|
m_forceSingleDirection = false;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
while( m_iteration < m_iterationLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
if( s_cw != STUCK )
|
|
|
|
s_cw = singleStep( path_cw, true );
|
|
|
|
|
|
|
|
if( s_ccw != STUCK )
|
|
|
|
s_ccw = singleStep( path_ccw, false );
|
|
|
|
|
|
|
|
if( ( s_cw == DONE && s_ccw == DONE ) || ( s_cw == STUCK && s_ccw == STUCK ) )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int len_cw = path_cw.CLine().Length();
|
|
|
|
int len_ccw = path_ccw.CLine().Length();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_forceLongerPath )
|
2015-02-18 16:53:46 +00:00
|
|
|
aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
|
2013-09-26 21:53:54 +00:00
|
|
|
else
|
2015-02-18 16:53:46 +00:00
|
|
|
aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( s_cw == DONE && !m_forceLongerPath )
|
|
|
|
{
|
|
|
|
aWalkPath = path_cw;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( s_ccw == DONE && !m_forceLongerPath )
|
|
|
|
{
|
|
|
|
aWalkPath = path_ccw;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_iteration++;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_iteration == m_iterationLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int len_cw = path_cw.CLine().Length();
|
|
|
|
int len_ccw = path_ccw.CLine().Length();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( m_forceLongerPath )
|
2014-05-16 11:37:31 +00:00
|
|
|
aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
|
2013-09-26 21:53:54 +00:00
|
|
|
else
|
2014-05-16 11:37:31 +00:00
|
|
|
aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_cursorApproachMode )
|
|
|
|
{
|
|
|
|
// int len_cw = path_cw.GetCLine().Length();
|
|
|
|
// int len_ccw = path_ccw.GetCLine().Length();
|
|
|
|
bool found = false;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN l = aWalkPath.CLine();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const SEG s = l.Segment( i );
|
|
|
|
|
|
|
|
VECTOR2I nearest = s.NearestPoint( m_cursorPos );
|
2013-10-14 18:40:36 +00:00
|
|
|
VECTOR2I::extended_type dist_a = ( s.A - m_cursorPos ).SquaredEuclideanNorm();
|
|
|
|
VECTOR2I::extended_type dist_b = ( s.B - m_cursorPos ).SquaredEuclideanNorm();
|
2013-10-14 14:13:35 +00:00
|
|
|
VECTOR2I::extended_type dist_n = ( nearest - m_cursorPos ).SquaredEuclideanNorm();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( dist_n <= dist_a && dist_n < dist_b )
|
|
|
|
{
|
|
|
|
l.Remove( i + 1, -1 );
|
|
|
|
l.Append( nearest );
|
|
|
|
l.Simplify();
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
{
|
|
|
|
aWalkPath = aInitialPath;
|
|
|
|
aWalkPath.SetShape( l );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aWalkPath.Line().Simplify();
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aWalkPath.SegmentCount() < 1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return STUCK;
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aWalkPath.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
|
2020-02-19 17:22:37 +00:00
|
|
|
return ALMOST_DONE;
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aWalkPath.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return STUCK;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
WALKAROUND_STATUS st = s_ccw == DONE || s_cw == DONE ? DONE : STUCK;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( st == DONE )
|
|
|
|
{
|
|
|
|
if( aOptimize )
|
2016-08-29 17:31:13 +00:00
|
|
|
OPTIMIZER::Optimize( &aWalkPath, OPTIMIZER::MERGE_OBTUSE, m_world );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return st;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|