#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 )
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
161 161 162 162 if (nodes.size() == 2) { 163 163 // 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(); 170 166 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); 175 168 } else { 176 169 // triangle: three single nodes needed or a way with three nodes 177 170 center = Geometry.getCenter(nodes); … … 183 176 184 177 // calculate the radius (r) 185 178 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); 188 180 189 181 // see #10777 190 182 LatLon ll1 = Main.getProjection().eastNorth2latlon(n1); … … 193 185 double radiusInMeters = ll1.greatCircleDistance(ll2); 194 186 195 187 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 } 196 192 if (numberOfNodesInCircle < 6) { 197 numberOfNodesInCircle = 6;193 numberOfNodesInCircle = 6; 198 194 } 199 195 200 196 // Order nodes by angle
Attachments (0)
Change History (3)
comment:1 by , 7 years ago
Description: | modified (diff) |
---|
comment:2 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 7 years ago
Milestone: | → 17.09 |
---|
In 12879/josm: