From deb691614ed87b6f08d93086ded291a2751341ad Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 24 Nov 2010 21:41:50 +0000 Subject: [PATCH] Avoid division by zero in simplication algorithm when two end points we are considering are in the same place. --- TODO.txt | 1 - net/systemeD/potlatch2/tools/Simplify.as | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index c48dbcb8..db30e11f 100644 --- 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 == diff --git a/net/systemeD/potlatch2/tools/Simplify.as b/net/systemeD/potlatch2/tools/Simplify.as index e782e3bf..468923ed 100644 --- a/net/systemeD/potlatch2/tools/Simplify.as +++ b/net/systemeD/potlatch2/tools/Simplify.as @@ -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); -- 2.31.1