Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#15327 closed enhancement (fixed)

[PATCH] small cleanup and "fix" for CreateCircleAction

Reported by: naoliv Owned by: team
Priority: normal Milestone: 17.09
Component: Core Version:
Keywords: Cc:

Description (last modified by naoliv)

Patch below does two things: use functions/methods when possible (instead calculating distances and centers by hand) and "fix" a small issue with circles that have an odd number of nodes.

An odd number of nodes creates an uneven distribution of the nodes in the circle (which we can see by using o to redistribute the nodes)

Since I am not keen to find the problematic part, I am simply adding +1 when the number is odd.
This should also make people with OCD happier (we will always have an even number of nodes now)

We didn't spot this problem before because we were always using a fixed even number of nodes (16).

  • src/org/openstreetmap/josm/actions/CreateCircleAction.java

     
    161161
    162162        if (nodes.size() == 2) {
    163163            // diameter: two single nodes needed or a way with two nodes
    164             Node n1 = nodes.get(0);
    165             double x1 = n1.getEastNorth().east();
    166             double y1 = n1.getEastNorth().north();
    167             Node n2 = nodes.get(1);
    168             double x2 = n2.getEastNorth().east();
    169             double y2 = n2.getEastNorth().north();
     164            EastNorth n1 = nodes.get(0).getEastNorth();
     165            EastNorth n2 = nodes.get(1).getEastNorth();
    170166
    171             // calculate the center (xc/yc)
    172             double xc = 0.5 * (x1 + x2);
    173             double yc = 0.5 * (y1 + y2);
    174             center = new EastNorth(xc, yc);
     167            center = n1.getCenter(n2);
    175168        } else {
    176169            // triangle: three single nodes needed or a way with three nodes
    177170            center = Geometry.getCenter(nodes);
     
    183176
    184177        // calculate the radius (r)
    185178        EastNorth n1 = nodes.get(0).getEastNorth();
    186         double r = Math.sqrt(Math.pow(center.east()-n1.east(), 2) +
    187                 Math.pow(center.north()-n1.north(), 2));
     179        double r = n1.distance(center);
    188180
    189181        // see #10777
    190182        LatLon ll1 = Main.getProjection().eastNorth2latlon(n1);
     
    193185        double radiusInMeters = ll1.greatCircleDistance(ll2);
    194186
    195187        int numberOfNodesInCircle = (int) Math.ceil(6.0 * Math.pow(radiusInMeters, 0.5));
     188        // FIXME an odd number of nodes makes the distribution uneven
     189        if ((numberOfNodesInCircle % 2) == 1) {
     190            numberOfNodesInCircle += 1;
     191        }
    196192        if (numberOfNodesInCircle < 6) {
    197            numberOfNodesInCircle = 6;
     193            numberOfNodesInCircle = 6;
    198194        }
    199195
    200196        // Order nodes by angle

Attachments (0)

Change History (3)

comment:1 by naoliv, 6 years ago

Description: modified (diff)

comment:2 by bastiK, 6 years ago

Resolution: fixed
Status: newclosed

In 12879/josm:

applied #15327 - small cleanup and "fix" for CreateCircleAction (patch by naoliv)

comment:3 by Don-vip, 6 years ago

Milestone: 17.09

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.