Ignore:
Timestamp:
2007-09-22T03:17:53+02:00 (17 years ago)
Author:
brent
Message:

Improved Version

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  
    3131    if (toolsMenu == null) {
    3232      toolsMenu = new JMenu(name);
    33       toolsMenu.add(new JMenuItem(new DuplicateWayAction(name)));
     33      toolsMenu.add(new JMenuItem(new DuplicateWayAction()));
    3434      Main.main.menu.add(toolsMenu, 2);
    3535    }
    3636    else {
    3737      toolsMenu.addSeparator();
    38       toolsMenu.add(new JMenuItem(new DuplicateWayAction(name)));
     38      toolsMenu.add(new JMenuItem(new DuplicateWayAction()));
    3939    }
    4040   
  • 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
    14package org.openstreetmap.josm.plugins.duplicateway;
    25
     
    811import org.openstreetmap.josm.data.osm.Segment;
    912
    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 */
     22public class JVector extends Line2D.Double {
    1123 
    1224  public static final double EARTH_CIRCUMFERENCE = 40041455;
     
    1527  protected Point2D.Double rtheta = null;
    1628 
    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) {
    1838    super(x1, y1, x2, y2);
    1939  }
    2040 
    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) {
    2247    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) {
    3060    super(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north());
    3161  }
    3262 
    33   /*
     63  /**
    3464   * Calculate slope/intersect from cartesian co-ords
     65   *
    3566   */
    3667  protected void calculateSlopeIntercept() {
     
    4071  }
    4172 
     73  /**
     74   * Return the slope of the JVector
     75   * @return slope
     76   */
    4277  public double getSlope() {
    4378    if (slopeIntercept == null) {
     
    4782  }
    4883 
     84  /**
     85   * Return the Y intercept of the JVector
     86   * @return intercept
     87   */
    4988  public double getIntercept() {
    5089    if (slopeIntercept == null) {
     
    5493  }
    5594 
    56   /*
     95  /**
    5796   * Calculate the polar coordinates for this line as a ray with
    5897   * the from point as origin
     
    66105  }
    67106 
     107  /**
     108   * Return the length of the line segment
     109   * @return length
     110   */
    68111  public double getLength() {
    69112    if (rtheta == null) {
     
    73116  }
    74117 
     118  /**
     119   * Return the angle of the line segment
     120   * @return theta
     121   */
    75122  public double getTheta() {
    76123    if (rtheta == null) {
     
    80127  }
    81128 
    82   /*
    83    * Set the Cartesian co-ords of the to point from the Polar co-ords
     129  /**
     130   * Convert Polar co-ords to cartesian
    84131   */
    85132  protected void polarToCartesian() {
     
    91138  }
    92139 
     140  /**
     141   * Set the line segment using Polar co-ordinates
     142   *
     143   * @param r line length
     144   * @param theta angle
     145   */
    93146  protected void setPolar(double r, double theta) {
    94147    rtheta = new Point2D.Double(r, theta);
     
    96149  }
    97150 
     151  /**
     152   * Set the length of the line segment
     153   * @param l length
     154   */
    98155  protected void setLength(double l) {
    99156    rtheta.x = l;
    100157    polarToCartesian();
    101158  }
    102   /*
     159 
     160  /**
    103161   * Reverse the direction of the segment
    104162   */
     
    114172  }
    115173 
    116   /*
    117    * Rotate the line
     174  /**
     175   * Rotate the line segment about the origin
     176   * @param rot angle to rotate
    118177   */
    119178  protected void rotate(double rot) {
     
    125184  }
    126185 
     186  /**
     187   * Rotate 90 degrees clockwise
     188   *
     189   */
    127190  protected void rotate90CW() {
    128191    rotate(-PI_ON_2);
    129192  }
    130193 
     194  /**
     195   * Rotate 90 degrees counterclockwise
     196   *
     197   */
    131198  protected void rotate90CCW() {
    132199    rotate(PI_ON_2);
    133200  }
    134201 
    135   /*
     202  /**
    136203   * Normalize theta to be in the range -PI < theta < PI
     204   * @param theta
     205   * @return normalized angle
    137206   */
    138207  protected double normalize(double theta) {
     
    147216    return theta;
    148217  }
    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 left
    154 //   */
    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 //  }
    174218 
     219  /**
     220   * Rotate the line segment 90 degrees and set the length. 
     221   * @param offset length
     222   */
    175223  protected void rotate90(double offset) {
    176224    rotate(PI_ON_2 * (offset < 0 ? 1 : -1));
     
    182230   * -ve if the point is to the left of the line, or +ve if to the right
    183231   */
     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   */
    184239  protected double calculateOffset(EastNorth target) {
    185240   
    186241    // Calculate the perpendicular interceptor to this point
    187242    EastNorth intersectPoint = perpIntersect(target);
    188     JosmVector intersectRay = new JosmVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north());
     243    JVector intersectRay = new JVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north());
    189244   
    190245    // Offset is equal to the length of the interceptor
     
    201256 
    202257
    203   /*
     258  /**
    204259   * Return the Perpendicular distance between a point
    205260   * and this line. Units is degrees.
     261   * @param n Node
    206262   */
    207263  public double perpDistance(Node n) {
     
    209265  }
    210266
     267  /**
     268   * Calculate the perpendicular distance from the supplied
     269   * point to this line
     270   * @param en point
     271   * @return distance
     272   */
    211273  public double perpDistance(EastNorth en) {
    212274   return ptLineDist(en.east(), en.north());
    213275  }
    214276
     277  /**
     278   * Calculate the perpendicular distance from the given point
     279   * to a JOSM segment.
     280   * @param s
     281   * @param en
     282   * @return
     283   */
    215284  public static double perpDistance(Segment s, EastNorth en) { 
    216285   return Line2D.ptSegDist(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north(), en.east(), en.north());
    217286  }
    218   /*
     287 
     288  /**
    219289   * Calculate the bisector between this and another Vector. A positive offset means
    220290   * 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);
    224297    double newTheta = Math.PI + ls.getTheta() - getTheta();
    225298    newSeg.setPolar(Math.abs(offset), newSeg.getTheta() - newTheta/2.0);
     
    229302      newSeg.rotate(Math.PI);
    230303    }
    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 //    }
    247304    return newSeg;
    248305  }
    249306 
    250   /*
     307  /**
    251308   * 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
    252311   */
    253312  public EastNorth perpIntersect(Node n) {
     
    255314  }
    256315 
     316  /**
     317   * Calculate the point on our line closest to the supplied point
     318   * @param en point
     319   * @return return closest point
     320   */
    257321  public EastNorth perpIntersect(EastNorth en) {
    258322   
     
    277341    return new EastNorth(intersectE, intersectN);
    278342  }
    279 // 
    280 //  /*
    281 //   * Return a compass heading 
    282 //   */
    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 //  }
    304343}
Note: See TracChangeset for help on using the changeset viewer.