Changeset 4651 in osm for applications/editors/josm/plugins/duplicateway
- Timestamp:
- 2007-09-22T03:17:53+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/duplicateway
- Files:
-
- 1 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/duplicateway/src/org/openstreetmap/josm/plugins/duplicateway/DuplicateWayPlugin.java
r4246 r4651 31 31 if (toolsMenu == null) { 32 32 toolsMenu = new JMenu(name); 33 toolsMenu.add(new JMenuItem(new DuplicateWayAction( name)));33 toolsMenu.add(new JMenuItem(new DuplicateWayAction())); 34 34 Main.main.menu.add(toolsMenu, 2); 35 35 } 36 36 else { 37 37 toolsMenu.addSeparator(); 38 toolsMenu.add(new JMenuItem(new DuplicateWayAction( name)));38 toolsMenu.add(new JMenuItem(new DuplicateWayAction())); 39 39 } 40 40 -
applications/editors/josm/plugins/duplicateway/src/org/openstreetmap/josm/plugins/duplicateway/JVector.java
r4246 r4651 1 2 // License: GPL. Copyright 2007 by Brent Easton 3 1 4 package org.openstreetmap.josm.plugins.duplicateway; 2 5 … … 8 11 import org.openstreetmap.josm.data.osm.Segment; 9 12 10 public class JosmVector extends Line2D.Double { 13 /** 14 * 15 * A class encapsulating a line Segment treating it as a Vector ( 16 * direction and length). Includes Utility routines to perform various 17 * transformations and Trigonometric operations 18 * 19 * @author Brent Easton 20 * 21 */ 22 public class JVector extends Line2D.Double { 11 23 12 24 public static final double EARTH_CIRCUMFERENCE = 40041455; … … 15 27 protected Point2D.Double rtheta = null; 16 28 17 public JosmVector(double x1, double y1, double x2, double y2) { 29 /** 30 * Create new JVector joining two points 31 * 32 * @param x1 33 * @param y1 34 * @param x2 35 * @param y2 36 */ 37 public JVector(double x1, double y1, double x2, double y2) { 18 38 super(x1, y1, x2, y2); 19 39 } 20 40 21 public JosmVector(JosmVector ls) { 41 /** 42 * Create new JVector from another JVector 43 * 44 * @param v JVector to copy 45 */ 46 public JVector(JVector v) { 22 47 super(); 23 x1 = ls.x1; 24 x2 = ls.x2; 25 y1 = ls.y1; 26 y2 = ls.y2; 27 } 28 29 public JosmVector (Segment s) { 48 x1 = v.x1; 49 x2 = v.x2; 50 y1 = v.y1; 51 y2 = v.y2; 52 } 53 54 /** 55 * Create a new JVector based on a JOSM Segment object 56 * 57 * @param s 58 */ 59 public JVector (Segment s) { 30 60 super(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north()); 31 61 } 32 62 33 /* 63 /** 34 64 * Calculate slope/intersect from cartesian co-ords 65 * 35 66 */ 36 67 protected void calculateSlopeIntercept() { … … 40 71 } 41 72 73 /** 74 * Return the slope of the JVector 75 * @return slope 76 */ 42 77 public double getSlope() { 43 78 if (slopeIntercept == null) { … … 47 82 } 48 83 84 /** 85 * Return the Y intercept of the JVector 86 * @return intercept 87 */ 49 88 public double getIntercept() { 50 89 if (slopeIntercept == null) { … … 54 93 } 55 94 56 /* 95 /** 57 96 * Calculate the polar coordinates for this line as a ray with 58 97 * the from point as origin … … 66 105 } 67 106 107 /** 108 * Return the length of the line segment 109 * @return length 110 */ 68 111 public double getLength() { 69 112 if (rtheta == null) { … … 73 116 } 74 117 118 /** 119 * Return the angle of the line segment 120 * @return theta 121 */ 75 122 public double getTheta() { 76 123 if (rtheta == null) { … … 80 127 } 81 128 82 /* 83 * Set the Cartesian co-ords of the to point from thePolar co-ords129 /** 130 * Convert Polar co-ords to cartesian 84 131 */ 85 132 protected void polarToCartesian() { … … 91 138 } 92 139 140 /** 141 * Set the line segment using Polar co-ordinates 142 * 143 * @param r line length 144 * @param theta angle 145 */ 93 146 protected void setPolar(double r, double theta) { 94 147 rtheta = new Point2D.Double(r, theta); … … 96 149 } 97 150 151 /** 152 * Set the length of the line segment 153 * @param l length 154 */ 98 155 protected void setLength(double l) { 99 156 rtheta.x = l; 100 157 polarToCartesian(); 101 158 } 102 /* 159 160 /** 103 161 * Reverse the direction of the segment 104 162 */ … … 114 172 } 115 173 116 /* 117 * Rotate the line 174 /** 175 * Rotate the line segment about the origin 176 * @param rot angle to rotate 118 177 */ 119 178 protected void rotate(double rot) { … … 125 184 } 126 185 186 /** 187 * Rotate 90 degrees clockwise 188 * 189 */ 127 190 protected void rotate90CW() { 128 191 rotate(-PI_ON_2); 129 192 } 130 193 194 /** 195 * Rotate 90 degrees counterclockwise 196 * 197 */ 131 198 protected void rotate90CCW() { 132 199 rotate(PI_ON_2); 133 200 } 134 201 135 /* 202 /** 136 203 * Normalize theta to be in the range -PI < theta < PI 204 * @param theta 205 * @return normalized angle 137 206 */ 138 207 protected double normalize(double theta) { … … 147 216 return theta; 148 217 } 149 150 // /*151 // * Rotate vector and set lenngth. If offset is positive,152 // * rotate so the vector points more towards the right,153 // * otherwise towards the left154 // */155 // protected void rotate(double theta, double offset) {156 // if (getTheta() > 0) {157 // if (offset > 0) {158 // rotate(-theta);159 // }160 // else {161 // rotate(theta);162 // }163 // }164 // else {165 // if (offset > 0) {166 // rotate(theta);167 // }168 // else {169 // rotate(-theta);170 // }171 // }172 // setLength(Math.abs(offset));173 // }174 218 219 /** 220 * Rotate the line segment 90 degrees and set the length. 221 * @param offset length 222 */ 175 223 protected void rotate90(double offset) { 176 224 rotate(PI_ON_2 * (offset < 0 ? 1 : -1)); … … 182 230 * -ve if the point is to the left of the line, or +ve if to the right 183 231 */ 232 233 234 /** 235 * Return the distance of the given point from this line. Offset is 236 * -ve if the point is to the left of the line, or +ve if to the right 237 * @param target 238 */ 184 239 protected double calculateOffset(EastNorth target) { 185 240 186 241 // Calculate the perpendicular interceptor to this point 187 242 EastNorth intersectPoint = perpIntersect(target); 188 J osmVector intersectRay = new JosmVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north());243 JVector intersectRay = new JVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north()); 189 244 190 245 // Offset is equal to the length of the interceptor … … 201 256 202 257 203 /* 258 /** 204 259 * Return the Perpendicular distance between a point 205 260 * and this line. Units is degrees. 261 * @param n Node 206 262 */ 207 263 public double perpDistance(Node n) { … … 209 265 } 210 266 267 /** 268 * Calculate the perpendicular distance from the supplied 269 * point to this line 270 * @param en point 271 * @return distance 272 */ 211 273 public double perpDistance(EastNorth en) { 212 274 return ptLineDist(en.east(), en.north()); 213 275 } 214 276 277 /** 278 * Calculate the perpendicular distance from the given point 279 * to a JOSM segment. 280 * @param s 281 * @param en 282 * @return 283 */ 215 284 public static double perpDistance(Segment s, EastNorth en) { 216 285 return Line2D.ptSegDist(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north(), en.east(), en.north()); 217 286 } 218 /* 287 288 /** 219 289 * Calculate the bisector between this and another Vector. A positive offset means 220 290 * the bisector must point to the right of the Vectors. 221 */ 222 public JosmVector bisector(JosmVector ls, double offset) { 223 JosmVector newSeg = new JosmVector(ls); 291 * @param ls Other vector to create angle to bisect 292 * @param offset length of bisecing vector 293 * @return the bisecting vector 294 */ 295 public JVector bisector(JVector ls, double offset) { 296 JVector newSeg = new JVector(ls); 224 297 double newTheta = Math.PI + ls.getTheta() - getTheta(); 225 298 newSeg.setPolar(Math.abs(offset), newSeg.getTheta() - newTheta/2.0); … … 229 302 newSeg.rotate(Math.PI); 230 303 } 231 232 // if (newSeg.getTheta() < -PI_ON_2) {233 // if (offset > 0) {234 // newSeg.rotate(Math.PI);235 // }236 // }237 // else if (newSeg.getTheta() > PI_ON_2) {238 // if (offset > 0) {239 // newSeg.rotate(-Math.PI);240 // }241 // }242 // else {243 // if (offset < 0) {244 // newSeg.rotate(Math.PI);245 // }246 // }247 304 return newSeg; 248 305 } 249 306 250 /* 307 /** 251 308 * Return the Perpendicular Intersector from a point to this line 309 * @param n a JOSM node 310 * @return the point on our line closest to n 252 311 */ 253 312 public EastNorth perpIntersect(Node n) { … … 255 314 } 256 315 316 /** 317 * Calculate the point on our line closest to the supplied point 318 * @param en point 319 * @return return closest point 320 */ 257 321 public EastNorth perpIntersect(EastNorth en) { 258 322 … … 277 341 return new EastNorth(intersectE, intersectN); 278 342 } 279 //280 // /*281 // * Return a compass heading282 // */283 // public String direction() {284 // double theta = getTheta();285 // String direction = "";286 // if (theta >= 0) {287 // if (theta < PI_ON_2) {288 // direction = "ne";289 // }290 // else {291 // direction = "nw";292 // }293 // }294 // else {295 // if (theta < -PI_ON_2) {296 // direction = "sw";297 // }298 // else {299 // direction = "se";300 // }301 // }302 // return direction;303 // }304 343 }
Note:
See TracChangeset
for help on using the changeset viewer.