Changeset 1912 in josm for trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
- Timestamp:
- 2009-08-05T10:25:23+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1899 r1912 128 128 return; 129 129 switch(c) { 130 case way: 131 Main.map.mapView.setCursor(cursorJoinWay); 130 case way: 131 Main.map.mapView.setCursor(cursorJoinWay); 132 break; 133 case node: 134 Main.map.mapView.setCursor(cursorJoinNode); 135 break; 136 default: 137 Main.map.mapView.setCursor(cursorCrosshair); 132 138 break; 133 case node:134 Main.map.mapView.setCursor(cursorJoinNode);135 break;136 default:137 Main.map.mapView.setCursor(cursorCrosshair);138 break;139 139 } 140 140 } … … 503 503 504 504 // Connected to a node that's already in the way 505 if(way. getNodes().contains(n)) {505 if(way.containsNode(n)) { 506 506 wayIsFinished = true; 507 507 selection.clear(); … … 810 810 811 811 switch (segs.size()) { 812 case 0: 813 return; 814 case 2: 815 // This computes the intersection between 816 // the two segments and adjusts the node position. 817 Iterator<Pair<Node,Node>> i = segs.iterator(); 818 Pair<Node,Node> seg = i.next(); 819 EastNorth A = seg.a.getEastNorth(); 820 EastNorth B = seg.b.getEastNorth(); 821 seg = i.next(); 822 EastNorth C = seg.a.getEastNorth(); 823 EastNorth D = seg.b.getEastNorth(); 824 825 double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north()); 826 827 // Check for parallel segments and do nothing if they are 828 // In practice this will probably only happen when a way has been duplicated 829 830 if (u == 0) return; 831 832 // q is a number between 0 and 1 833 // It is the point in the segment where the intersection occurs 834 // if the segment is scaled to lenght 1 835 836 double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u; 837 EastNorth intersection = new EastNorth( 838 B.east() + q * (A.east() - B.east()), 839 B.north() + q * (A.north() - B.north())); 840 841 int snapToIntersectionThreshold 842 = Main.pref.getInteger("edit.snap-intersection-threshold",10); 843 844 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise 845 // fall through to default action. 846 // (for semi-parallel lines, intersection might be miles away!) 847 if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) { 848 n.setEastNorth(intersection); 812 case 0: 849 813 return; 850 } 851 852 default: 853 EastNorth P = n.getEastNorth(); 854 seg = segs.iterator().next(); 855 A = seg.a.getEastNorth(); 856 B = seg.b.getEastNorth(); 857 double a = P.distanceSq(B); 858 double b = P.distanceSq(A); 859 double c = A.distanceSq(B); 860 q = (a - b + c) / (2*c); 861 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()))); 814 case 2: 815 // This computes the intersection between 816 // the two segments and adjusts the node position. 817 Iterator<Pair<Node,Node>> i = segs.iterator(); 818 Pair<Node,Node> seg = i.next(); 819 EastNorth A = seg.a.getEastNorth(); 820 EastNorth B = seg.b.getEastNorth(); 821 seg = i.next(); 822 EastNorth C = seg.a.getEastNorth(); 823 EastNorth D = seg.b.getEastNorth(); 824 825 double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north()); 826 827 // Check for parallel segments and do nothing if they are 828 // In practice this will probably only happen when a way has been duplicated 829 830 if (u == 0) return; 831 832 // q is a number between 0 and 1 833 // It is the point in the segment where the intersection occurs 834 // if the segment is scaled to lenght 1 835 836 double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u; 837 EastNorth intersection = new EastNorth( 838 B.east() + q * (A.east() - B.east()), 839 B.north() + q * (A.north() - B.north())); 840 841 int snapToIntersectionThreshold 842 = Main.pref.getInteger("edit.snap-intersection-threshold",10); 843 844 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise 845 // fall through to default action. 846 // (for semi-parallel lines, intersection might be miles away!) 847 if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) { 848 n.setEastNorth(intersection); 849 return; 850 } 851 852 default: 853 EastNorth P = n.getEastNorth(); 854 seg = segs.iterator().next(); 855 A = seg.a.getEastNorth(); 856 B = seg.b.getEastNorth(); 857 double a = P.distanceSq(B); 858 double b = P.distanceSq(A); 859 double c = A.distanceSq(B); 860 q = (a - b + c) / (2*c); 861 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()))); 862 862 } 863 863 }
Note:
See TracChangeset
for help on using the changeset viewer.