From 41e8caee2a631ed6be47e47c36a05b53a3b2155c Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 23 Mar 2012 00:46:31 +1100 Subject: [PATCH] Fix #3786 by preventing user trying to circularise problematic shapes like figure-eights. --- net/systemeD/potlatch2/Toolbox.mxml | 15 +++++++++++---- net/systemeD/potlatch2/tools/Circularise.as | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/net/systemeD/potlatch2/Toolbox.mxml b/net/systemeD/potlatch2/Toolbox.mxml index a58c97b0..c808e7b0 100644 --- a/net/systemeD/potlatch2/Toolbox.mxml +++ b/net/systemeD/potlatch2/Toolbox.mxml @@ -91,10 +91,11 @@ import flash.events.MouseEvent; import net.systemeD.halcyon.connection.*; import net.systemeD.halcyon.connection.actions.*; + import net.systemeD.halcyon.AttentionEvent; import net.systemeD.potlatch2.controller.*; import net.systemeD.potlatch2.tools.*; import embedded.*; // for FXG icons - + private var controller:EditController; [Bindable] @@ -294,10 +295,16 @@ public function doCircularise():void { var undo:CompositeUndoableAction = new CompositeUndoableAction("Make objects circular "); - for each (var way:Way in controller.state.selectedWays) { - Circularise.circularise(way, controller.map, undo.push); + try { + + for each (var way:Way in controller.state.selectedWays) { + Circularise.circularise(way, controller.map, undo.push); + } + MainUndoStack.getGlobalStack().addAction(undo); + } catch (e: Error) { + var msg:String = e.message; + controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg)); } - MainUndoStack.getGlobalStack().addAction(undo); } public function doSplit():void { diff --git a/net/systemeD/potlatch2/tools/Circularise.as b/net/systemeD/potlatch2/tools/Circularise.as index 88bf1e84..5abfb910 100644 --- a/net/systemeD/potlatch2/tools/Circularise.as +++ b/net/systemeD/potlatch2/tools/Circularise.as @@ -81,6 +81,11 @@ package net.systemeD.potlatch2.tools { if (clockwise) { if (a2>a1) { a2=a2-360; } diff=a1-a2; + if (diff > 180) { + // If way crosses back on itself, we risk creating lots of extra nodes. + // (Bug 3786) + throw new Error ("This shape is too irregular. Sorry."); + } if (diff>20) { for (ang=a1-20; ang>a2+10; ang-=20) { insertNode(ang, i+1); @@ -90,6 +95,9 @@ package net.systemeD.potlatch2.tools { } else { if (a1>a2) { a1=a1-360; } diff=a2-a1; + if (diff > 180) { + throw new Error ("This shape is too irregular. Sorry."); + } if (diff>20) { for (ang=a1+20; ang