straighten ways
authorRichard Fairhurst <richard@systemed.net>
Fri, 26 Mar 2010 16:56:26 +0000 (16:56 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 26 Mar 2010 16:56:26 +0000 (16:56 +0000)
net/systemeD/halcyon/connection/Node.as
net/systemeD/potlatch2/Toolbox.as
net/systemeD/potlatch2/tools/Straighten.as [new file with mode: 0644]
potlatch2.mxml

index 853c0db07f001d6e512fc106721b8c602264a32d..88f7f6461db51157e0f3a58ebcd6013fe2183293 100644 (file)
@@ -51,6 +51,17 @@ package net.systemeD.halcyon.connection {
             dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, _lat, oldLon));
          }
 
+               public function setLonLatp(lon:Number,latproj:Number):void {
+                       // move both lon and latp but only fire one event
+                       var oldLon:Number = this._lon;
+                       var oldLat:Number = this._lat;
+                       this._latproj = latproj;
+                       this._lat = latp2lat(latproj);
+                       this._lon = lon;
+                       markDirty();
+            dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, oldLat, oldLon));
+               }
+
         public override function toString():String {
             return "Node("+id+"@"+version+"): "+lat+","+lon+" "+getTagList();
         }
index c1aceb958964953c6410977dbff9e9794b9a7e20..4d93a8cf82693719aa139893014d86ac52b63463 100644 (file)
@@ -5,7 +5,7 @@ package net.systemeD.potlatch2 {
        import mx.containers.Panel;
        import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.controller.*;
-    import net.systemeD.potlatch2.tools.Quadrilateralise;
+    import net.systemeD.potlatch2.tools.*;
 
        /*
                Floating toolbox palette
@@ -71,5 +71,11 @@ package net.systemeD.potlatch2 {
                        }
                }
 
+               public function doStraighten():void {
+                       if (entity is Way) {
+                               Straighten.straighten(Way(entity),controller.map);
+                       }
+               }
+
        }
 }
\ No newline at end of file
diff --git a/net/systemeD/potlatch2/tools/Straighten.as b/net/systemeD/potlatch2/tools/Straighten.as
new file mode 100644 (file)
index 0000000..88ed441
--- /dev/null
@@ -0,0 +1,46 @@
+package net.systemeD.potlatch2.tools {
+       import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.connection.Way;
+       import net.systemeD.halcyon.connection.Node;
+       import net.systemeD.halcyon.Globals;
+
+       public class Straighten {
+
+               public static function straighten(way:Way,map:Map):void {
+                       if (way.length<3) { return; }
+
+                       var a:Node=way.getNode(0);
+                       var b:Node=way.getNode(way.length-1);
+                       if (a==b) { return; }
+                       
+                       // ** could potentially do the 'too bendy?' check here as per Potlatch 1
+                       
+                       var todelete:Array=[];
+                       var n:Node;
+               
+                       for (var i:uint=1; i<way.length-1; i++) {
+                               n=way.getNode(i);
+                               if (n.parentWays.length>1 || n.hasTags() ||
+                                   n.lon<map.edge_l || n.lon>map.edge_r ||
+                                   n.lat<map.edge_b || n.lat>map.edge_t) {
+
+                                       // junction node, tagged, or off-screen - so retain and move
+                                       var u:Number=((n.lon -a.lon )*(b.lon -a.lon )+
+                                                     (n.latp-a.latp)*(b.latp-a.latp))/
+                                                    (Math.pow(b.lon-a.lon,2)+Math.pow(b.latp-a.latp,2));
+                                       n.setLonLatp(a.lon +u*(b.lon -a.lon ),
+                                                    a.latp+u*(b.latp-a.latp));
+                                       for each (var o:Way in n.parentWays) {
+                                               if (todraw.indexOf(o)==-1) { todraw.push(o); }
+                                       }
+                                       
+                               } else {
+                                       // safe to delete
+                                       Globals.vars.root.addDebug("removing node "+n);
+                                       if (todelete.indexOf(n)==-1) { todelete.push(n); }
+                               }
+                       }
+                       for each (n in todelete) { n.remove(); }
+               }
+       }
+}
index 522f886c2c72aca1b67d48d3ea88461204fba6d3..13050cc362af8a459550daf668ecaf3437f433c5 100755 (executable)
@@ -63,6 +63,7 @@
                <mx:Button icon="@Embed('embedded/direction.svg')" 
                                width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/straighten.svg')" 
+                               click='toolbox.doStraighten();' 
                                width="28" height="28" textAlign="left" paddingLeft="5" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/circle.svg')" 
                                width="28" height="28" textAlign="left" paddingLeft="4" paddingRight="0" />