[Tilesathome] Illegal division by zero

Martijn van Oosterhout kleptog at gmail.com
Sun Jun 15 07:03:15 BST 2008


On Wed, Jun 11, 2008 at 8:14 PM, Dirk-Lüder Kreie <osm-list at deelkar.net> wrote:
> Jiri Klement schrieb:
>>
>> I've run into the same error today. Following patch makes it work for me:
>>
>> Index: lines2curves.pl
>> ===================================================================
>> --- lines2curves.pl     (revision 8167)
>> +++ lines2curves.pl     (working copy)
>> @@ -147,8 +147,7 @@
>>     shift @$points_ref;
>>
>>     foreach my $point_ref (@$points_ref) {
>> -        if ($point_ref->[0].$point_ref->[1] eq
>> -                $clean_points_ref->[-1][0].$clean_points_ref->[-1][1]) {
>> +        if (($point_ref->[0] == $clean_points_ref->[-1][0]) &&
>> ($point_ref->[1] == $clean_points_ref->[-1][1])) {
>>                 next;
>>         }
>>
>> I don't understand why numeric values were compared using eq operator.
>> There are other places in lines2curves.pl comparing points this way.
>
> I don't understand either why this was converted into a string comparison,
> but if this really fixes the issue (i.e. by making a comparison work that
> wouldn't work when used as string comparison) I'm all for it.

I suppose the string concatination is because it wants to compare the
X and Y coordinates simultaneously whereas the new test only compares
the X coordinates. My guess is the original problem was caused by two
point close enough to cause a division by zero but far enugh (in the
order the machine precision) to make the test fail.

If there are more places comparing like this I'd suggest making a
function ComparePoints like so:

use constant EPSILON => 1e-6;
sub ComparePoints
{
   my($a,$b)=@_;
  if( abs($a->[0] - $b->[0]) < EPSILON and
      abs($a->[1] - $b->[1]) < EPSILON )
  { return 1; }
  return 0;
}

Have a nice day,
-- 
Martijn van Oosterhout <kleptog at gmail.com> http://svana.org/kleptog/




More information about the Tilesathome mailing list