Prevent drag index from exceeding full line count

Simplification removes segments, so we might lose our valid index.
Ideally, we would simplify during the assembly or pass the input index
to the simplify routine to maintain the proper value.

Fixes https://gitlab.com/kicad/code/kicad/issues/12137

(cherry picked from commit 6c617d84ca)
This commit is contained in:
Seth Hillbrand 2022-08-01 08:56:11 -07:00
parent 5207a8d8b4
commit 17fdb7c6a8
1 changed files with 4 additions and 0 deletions

View File

@ -1056,6 +1056,10 @@ const LINE NODE::AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex,
// Remove duplicate verts, but do NOT remove colinear segments here!
pl.Line().Simplify( false );
// TODO: maintain actual segment index under simplifcation system
if( aOriginSegmentIndex && *aOriginSegmentIndex >= pl.SegmentCount() )
*aOriginSegmentIndex = pl.SegmentCount() - 1;
assert( pl.SegmentCount() != 0 );
return pl;