Ticket #7421: bug7421.patch

File bug7421.patch, 1.3 KB (added by Balaitous, 12 years ago)
  • src/org/openstreetmap/josm/actions/CreateCircleAction.java

     
    99import java.util.ArrayList;
    1010import java.util.Arrays;
    1111import java.util.Collection;
     12import java.util.Collections;
    1213import java.util.Comparator;
    1314import java.util.LinkedList;
    1415import java.util.List;
     
    230231            }
    231232        }
    232233        wayToAdd.add(wayToAdd.get(0)); // close the circle
     234       
     235        // Set circle direction same as selected nodes (see: #7421)
     236        if(nodes.size() == 3) {
     237            double[] x = new double[2];
     238            double[] y = new double[2];
     239            for(int i = 0; i < 2; i++) {
     240                x[i] = nodes.get(i+1).getEastNorth().east() - nodes.get(i).getEastNorth().east();
     241                y[i] = nodes.get(i+1).getEastNorth().north() - nodes.get(i).getEastNorth().north();
     242            }
     243            double pvect = x[0] * y[1] - x[1] * y[0];
     244            if(pvect < 0)
     245                Collections.reverse(wayToAdd);
     246        }
     247       
    233248        if (existingWay == null) {
    234249            Way newWay = new Way();
    235250            newWay.setNodes(wayToAdd);