The new test compares both X and Y coordinate. The illegal division by
zero error was caused by coordinate 14.47700000 which was truncated to
14.477 for one point and remained 14.47700000 for another point.

I agree that "abs(a-b) < EPSILON" is correct way to compare floats but
it seems simple a == b works for this case.

On 6/15/08, Martijn van Oosterhout <[EMAIL PROTECTED]> wrote:
> On Wed, Jun 11, 2008 at 8:14 PM, Dirk-Lüder Kreie <[EMAIL PROTECTED]> 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)[EMAIL PROTECTED];
>   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 <[EMAIL PROTECTED]> http://svana.org/kleptog/
>

_______________________________________________
Tilesathome mailing list
[email protected]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/tilesathome

Reply via email to