return;
}
// now we can start doing things to OSM data
Collection<Command> cmds = new LinkedList<>();
EastNorth center = null;
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();
// calculate the center (xc/yc)
double xc = 0.5 * (x1 + x2);
double yc = 0.5 * (y1 + y2);
center = new EastNorth(xc, yc);
} else {
// triangle: three single nodes needed or a way with three nodes
center = Geometry.getCenter(nodes);
if (center == null) {
notifyNodesNotOnCircle();
return;
}
}
// 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));
// Order nodes by angle
PolarNode[] angles = new PolarNode[nodes.size()];
for(int i = 0; i < nodes.size(); i++) {
angles[i] = new PolarNode(center, nodes.get(i));
}
Arrays.sort(angles, new PolarNodeComparator());
int[] count = distributeNodes(angles,
numberOfNodesInCircle >= nodes.size() ? numberOfNodesInCircle - nodes.size() : 0);
// build a way for the circle
List<Node> wayToAdd = new ArrayList<>();
for(int i = 0; i < nodes.size(); i++) {
wayToAdd.add(angles[i].node);
double delta = angles[(i+1) % nodes.size()].a - angles[i].a;
if(delta < 0)
delta += 2*Math.PI;
for(int j = 0; j < count[i]; j++) {
double alpha = angles[i].a + (j+1)*delta/(count[i]+1);
double x = center.east() + r*Math.cos(alpha);
double y = center.north() + r*Math.sin(alpha);
LatLon ll = Main.getProjection().eastNorth2latlon(new EastNorth(x,y));
if (ll.isOutSideWorld()) {
notifyNodesNotOnCircle();
return;
}
Node n = new Node(ll);