PNS: Apply co-linear seg merging to drag operations

This commit is contained in:
Jon Evans 2021-04-11 22:32:11 -04:00
parent 1c431d9929
commit 49a91414d7
3 changed files with 18 additions and 7 deletions

View File

@ -402,9 +402,12 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& aDragged, const LINE& aOrig, c
OPTIMIZER optimizer( m_lastNode );
optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS |
OPTIMIZER::KEEP_TOPOLOGY |
OPTIMIZER::RESTRICT_AREA );
int effort = OPTIMIZER::MERGE_SEGMENTS | OPTIMIZER::KEEP_TOPOLOGY | OPTIMIZER::RESTRICT_AREA;
if( Settings().SmoothDraggedSegments() )
effort |= OPTIMIZER::MERGE_COLINEAR;
optimizer.SetEffortLevel( effort );
OPT_BOX2I affectedArea = aDragged.ChangedArea( &aOrig );
VECTOR2I anchor( aP );

View File

@ -963,8 +963,8 @@ const LINE NODE::AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex,
const SHAPE_ARC* sa = static_cast<const SHAPE_ARC*>( arc->Shape() );
int nSegs = line.PointCount();
VECTOR2I last = line.CPoint( -1 );
ssize_t lastShape = line.CShapes()[nSegs - 1];
VECTOR2I last = nSegs ? line.CPoint( -1 ) : VECTOR2I();
ssize_t lastShape = nSegs ? line.CShapes()[nSegs - 1] : -1;
line.Append( arcReversed[i] ? sa->Reversed() : *sa );

View File

@ -571,8 +571,16 @@ bool OPTIMIZER::mergeColinear( LINE* aLine )
SEG s1 = line.CSegment( segIdx );
SEG s2 = line.CSegment( segIdx + 1 );
if( shapes[segIdx] < 0 && shapes[segIdx + 1] < 0 && s1.Collinear( s2 ) )
line.Replace( segIdx, segIdx + 1, s1.A );
// Skip zero-length segs caused by abutting arcs
if( s1.SquaredLength() == 0 || s2.SquaredLength() == 0 )
continue;
if( s1.Collinear( s2 ) )
{
// We should not see a collinear vertex inside an arc
wxASSERT( shapes[segIdx + 1] < 0 );
line.Remove( segIdx + 1 );
}
}
return line.SegmentCount() < nSegs;