Opened 4 years ago

Closed 4 years ago

# [PATCH] small cleanup and "fix" for CreateCircleAction

Reported by: Owned by: naoliv team normal 17.09 Core

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

 if (nodes.size() == 2) { // diameter: two single nodes needed or a way with two nodes Node n1 = nodes.get(0); double x1 = n1.getEastNorth().east(); double y1 = n1.getEastNorth().north(); Node n2 = nodes.get(1); double x2 = n2.getEastNorth().east(); double y2 = n2.getEastNorth().north(); EastNorth n1 = nodes.get(0).getEastNorth(); EastNorth n2 = nodes.get(1).getEastNorth(); // calculate the center (xc/yc) double xc = 0.5 * (x1 + x2); double yc = 0.5 * (y1 + y2); center = new EastNorth(xc, yc); center = n1.getCenter(n2); } else { // triangle: three single nodes needed or a way with three nodes center = Geometry.getCenter(nodes); // calculate the radius (r) EastNorth n1 = nodes.get(0).getEastNorth(); double r = Math.sqrt(Math.pow(center.east()-n1.east(), 2) + Math.pow(center.north()-n1.north(), 2)); double r = n1.distance(center); // see #10777 LatLon ll1 = Main.getProjection().eastNorth2latlon(n1); double radiusInMeters = ll1.greatCircleDistance(ll2); int numberOfNodesInCircle = (int) Math.ceil(6.0 * Math.pow(radiusInMeters, 0.5)); // FIXME an odd number of nodes makes the distribution uneven if ((numberOfNodesInCircle % 2) == 1) { numberOfNodesInCircle += 1; } if (numberOfNodesInCircle < 6) { numberOfNodesInCircle = 6; numberOfNodesInCircle = 6; } // Order nodes by angle

### comment:1 Changed 4 years ago by naoliv

Description: modified (diff)

### comment:2 Changed 4 years ago by bastiK

Resolution: → fixed new → closed

In 12879/josm:

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

### comment:3 Changed 4 years ago by Don-vip

Milestone: → 17.09

### Modify Ticket

Change Properties
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.