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 c48dbcb8e25db30cb84b5ada427b9057ce3c9e82..db30e11fdb8a9d8a6b22a41b863e2bd26da7aa1f 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 e782e3bf33eb82513b6b830034a10b150e1d623c..468923edc349523ec36e951d3bd860f2b0c711cd 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);