Subject: | _add_segment() trips into endless loop |
I have a problem with an endless loop condition in _add_segment(),
line 2863 (Planar.pm, 1.18) in the containing while loop:
if (($tr[$t]{d0} <= 0) && ($tr[$t]{d1} <= 0)) { # case cannot arise
print "add_segment: error\n";
}
I need to deal with user-supplied coordinates, the offending sample
looks like this (in perl notation)
[
[ 33, 656 ],
[ 34, 1396 ],
[ 747, 1394 ],
[ 731, 1113 ],
[ 390, 1096 ],
[ 387, 617 ],
[ 22, 628 ],
[ 31, 682 ],
[ 0, 677 ],
[ 27, 680 ]
]
My hunch is that one of the last two coordinates triggers the problem.
As this is used in a production system, I hotfixed Planar.pm like thus:
if (($tr[$t]{d0} <= 0) && ($tr[$t]{d1} <= 0)) { # case cannot arise
print "add_segment: error\n";
last; # exit while()
}
My question is: is there a way to prevalidate the above data in order
to produce a more informative error message (other than "bad data")?
Or is this a bug in Planar.pm?
Best regards
Thomas