Avoid division by zero in simplication algorithm when two end points
authorTom Hughes <tom@compton.nu>
Wed, 24 Nov 2010 21:41:50 +0000 (21:41 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 24 Nov 2010 21:41:50 +0000 (21:41 +0000)
we are considering are in the same place.

TODO.txt
net/systemeD/potlatch2/tools/Simplify.as

index c48dbcb..db30e11 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -14,7 +14,6 @@ Potlatch 2: main outstanding issues
 * Connectivity isn't preserved when bringing ways through (e.g. from OSM layer)
 * Alt-click on lines from GPX appears to prevent anything from being selected.
 * z-ordering - areas in editing layer prevent background layers from being clicked.
-* GPX of a closed shape (i.e. lat/lon are the same at start and end) 'disappears' when simplified
 
 == Tag editing ==
 
index e782e3b..468923e 100644 (file)
@@ -65,7 +65,12 @@ package net.systemeD.potlatch2.tools {
                private static function getDistance(ax:Number,ay:Number,bx:Number,by:Number,l:Number,cx:Number,cy:Number):Number {
                        // l=length of line
                        // r=proportion along AB line (0-1) of nearest point
-                       var r:Number=((cx-ax)*(bx-ax)+(cy-ay)*(by-ay))/(l*l);
+                       var r:Number;
+                        if (l > 0) {
+                                r=((cx-ax)*(bx-ax)+(cy-ay)*(by-ay))/(l*l);
+                        } else {
+                                r=0;
+                        }
                        // now find the length from cx,cy to ax+r*(bx-ax),ay+r*(by-ay)
                        var px:Number=(ax+r*(bx-ax)-cx);
                        var py:Number=(ay+r*(by-ay)-cy);