Ignore:
Timestamp:
2017-02-23T01:03:15+01:00 (3 years ago)
Author:
Don-vip
Message:

error-prone: fix FallThrough errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r11495 r11601  
    10051005
    10061006    /**
    1007      * Adjusts the position of a node to lie on a segment (or a segment
    1008      * intersection).
     1007     * Adjusts the position of a node to lie on a segment (or a segment intersection).
    10091008     *
    10101009     * If one or more than two segments are passed, the node is adjusted
    10111010     * to lie on the first segment that is passed.
    10121011     *
    1013      * If two segments are passed, the node is adjusted to be at their
    1014      * intersection.
     1012     * If two segments are passed, the node is adjusted to be at their intersection.
    10151013     *
    10161014     * No action is taken if no segments are passed.
     
    10201018     */
    10211019    private static void adjustNode(Collection<Pair<Node, Node>> segs, Node n) {
    1022 
    10231020        switch (segs.size()) {
    10241021        case 0:
    10251022            return;
    10261023        case 2:
    1027             // This computes the intersection between the two segments and adjusts the node position.
    1028             Iterator<Pair<Node, Node>> i = segs.iterator();
    1029             Pair<Node, Node> seg = i.next();
    1030             EastNorth pA = seg.a.getEastNorth();
    1031             EastNorth pB = seg.b.getEastNorth();
    1032             seg = i.next();
    1033             EastNorth pC = seg.a.getEastNorth();
    1034             EastNorth pD = seg.b.getEastNorth();
    1035 
    1036             double u = det(pB.east() - pA.east(), pB.north() - pA.north(), pC.east() - pD.east(), pC.north() - pD.north());
    1037 
    1038             // Check for parallel segments and do nothing if they are
    1039             // In practice this will probably only happen when a way has been duplicated
    1040 
    1041             if (u == 0)
    1042                 return;
    1043 
    1044             // q is a number between 0 and 1
    1045             // It is the point in the segment where the intersection occurs
    1046             // if the segment is scaled to lenght 1
    1047 
    1048             double q = det(pB.north() - pC.north(), pB.east() - pC.east(), pD.north() - pC.north(), pD.east() - pC.east()) / u;
    1049             EastNorth intersection = new EastNorth(
    1050                     pB.east() + q * (pA.east() - pB.east()),
    1051                     pB.north() + q * (pA.north() - pB.north()));
    1052 
    1053 
    1054             // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
    1055             // fall through to default action.
    1056             // (for semi-parallel lines, intersection might be miles away!)
    1057             if (Main.map.mapView.getPoint2D(n).distance(Main.map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) {
    1058                 n.setEastNorth(intersection);
    1059                 return;
    1060             }
     1024            adjustNodeTwoSegments(segs, n);
     1025            break;
    10611026        default:
    1062             EastNorth p = n.getEastNorth();
    1063             seg = segs.iterator().next();
    1064             pA = seg.a.getEastNorth();
    1065             pB = seg.b.getEastNorth();
    1066             double a = p.distanceSq(pB);
    1067             double b = p.distanceSq(pA);
    1068             double c = pA.distanceSq(pB);
    1069             q = (a - b + c) / (2*c);
    1070             n.setEastNorth(new EastNorth(pB.east() + q * (pA.east() - pB.east()), pB.north() + q * (pA.north() - pB.north())));
    1071         }
     1027            adjustNodeDefault(segs, n);
     1028        }
     1029    }
     1030
     1031    private static void adjustNodeTwoSegments(Collection<Pair<Node, Node>> segs, Node n) {
     1032        // This computes the intersection between the two segments and adjusts the node position.
     1033        Iterator<Pair<Node, Node>> i = segs.iterator();
     1034        Pair<Node, Node> seg = i.next();
     1035        EastNorth pA = seg.a.getEastNorth();
     1036        EastNorth pB = seg.b.getEastNorth();
     1037        seg = i.next();
     1038        EastNorth pC = seg.a.getEastNorth();
     1039        EastNorth pD = seg.b.getEastNorth();
     1040
     1041        double u = det(pB.east() - pA.east(), pB.north() - pA.north(), pC.east() - pD.east(), pC.north() - pD.north());
     1042
     1043        // Check for parallel segments and do nothing if they are
     1044        // In practice this will probably only happen when a way has been duplicated
     1045
     1046        if (u == 0)
     1047            return;
     1048
     1049        // q is a number between 0 and 1
     1050        // It is the point in the segment where the intersection occurs
     1051        // if the segment is scaled to length 1
     1052
     1053        double q = det(pB.north() - pC.north(), pB.east() - pC.east(), pD.north() - pC.north(), pD.east() - pC.east()) / u;
     1054        EastNorth intersection = new EastNorth(
     1055                pB.east() + q * (pA.east() - pB.east()),
     1056                pB.north() + q * (pA.north() - pB.north()));
     1057
     1058
     1059        // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
     1060        // fall through to default action.
     1061        // (for semi-parallel lines, intersection might be miles away!)
     1062        if (Main.map.mapView.getPoint2D(n).distance(Main.map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) {
     1063            n.setEastNorth(intersection);
     1064            return;
     1065        }
     1066
     1067        adjustNodeDefault(segs, n);
     1068    }
     1069
     1070    private static void adjustNodeDefault(Collection<Pair<Node, Node>> segs, Node n) {
     1071        EastNorth p = n.getEastNorth();
     1072        Pair<Node, Node> seg = segs.iterator().next();
     1073        EastNorth pA = seg.a.getEastNorth();
     1074        EastNorth pB = seg.b.getEastNorth();
     1075        double a = p.distanceSq(pB);
     1076        double b = p.distanceSq(pA);
     1077        double c = pA.distanceSq(pB);
     1078        double q = (a - b + c) / (2*c);
     1079        n.setEastNorth(new EastNorth(pB.east() + q * (pA.east() - pB.east()), pB.north() + q * (pA.north() - pB.north())));
    10721080    }
    10731081
Note: See TracChangeset for help on using the changeset viewer.