Changeset 14587 in josm for trunk


Ignore:
Timestamp:
2018-12-22T16:17:33+01:00 (5 years ago)
Author:
GerdP
Message:
  • fix more findbugs warnings
  • change varible names from lon,lat to x,y
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ShapeClipper.java

    r14586 r14587  
    127127        for (int i = 2; i < num;) {
    128128            double x = points[i++], y = points[i++];
    129             if (x != lastX || y != lastY) {
     129            if (Double.compare(x, lastX) != 0 || Double.compare(y, lastY) != 0) {
    130130                path.lineTo(x, y);
    131131                lastX = x;
     
    190190            input = outputList;
    191191            outputList = new double[countVals + 16];
    192             double sLon = 0, sLat = 0;
    193             double pLon = 0, pLat = 0; // intersection
     192            double sx = 0, sy = 0;
     193            double px = 0, py = 0; // intersection
    194194            int posIn = countVals - 2;
    195195            int posOut = 0;
     
    197197                if (posIn >= countVals)
    198198                    posIn = 0;
    199                 double eLon = input[posIn++];
    200                 double eLat = input[posIn++];
     199                double ex = input[posIn++];
     200                double ey = input[posIn++];
    201201                switch (side) {
    202202                case LEFT:
    203                     eIsIn = (eLon >= leftX);
     203                    eIsIn = (ex >= leftX);
    204204                    break;
    205205                case TOP:
    206                     eIsIn = (eLat < upperY);
     206                    eIsIn = (ey < upperY);
    207207                    break;
    208208                case RIGHT:
    209                     eIsIn = (eLon < rightX);
     209                    eIsIn = (ex < rightX);
    210210                    break;
    211211                default:
    212                     eIsIn = (eLat >= lowerY);
     212                    eIsIn = (ey >= lowerY);
    213213                }
    214214                if (i > 0) {
     
    216216                        // compute intersection
    217217                        double slope;
    218                         if (eLon != sLon)
    219                             slope = (eLat - sLat) / (eLon - sLon);
     218                        boolean isNotZero = Math.abs(ex - sx) > 1e-12;
     219                        if (isNotZero)
     220                            slope = (ey - sy) / (ex - sx);
    220221                        else
    221222                            slope = 1;
     
    223224                        switch (side) {
    224225                        case LEFT:
    225                             pLon = leftX;
    226                             pLat = slope * (leftX - sLon) + sLat;
     226                            px = leftX;
     227                            py = slope * (leftX - sx) + sy;
    227228                            break;
    228229                        case RIGHT:
    229                             pLon = rightX;
    230                             pLat = slope * (rightX - sLon) + sLat;
     230                            px = rightX;
     231                            py = slope * (rightX - sx) + sy;
    231232                            break;
    232233
    233234                        case TOP:
    234                             if (eLon != sLon)
    235                                 pLon = sLon + (upperY - sLat) / slope;
     235                            if (isNotZero)
     236                                px = sx + (upperY - sy) / slope;
    236237                            else
    237                                 pLon = sLon;
    238                             pLat = upperY;
     238                                px = sx;
     239                            py = upperY;
    239240                            break;
    240241                        default: // BOTTOM
    241                             if (eLon != sLon)
    242                                 pLon = sLon + (lowerY - sLat) / slope;
     242                            if (isNotZero)
     243                                px = sx + (lowerY - sy) / slope;
    243244                            else
    244                                 pLon = sLon;
    245                             pLat = lowerY;
     245                                px = sx;
     246                            py = lowerY;
    246247                            break;
    247248
     
    265266                    if (eIsIn) {
    266267                        if (!sIsIn) {
    267                             outputList[posOut++] = pLon;
    268                             outputList[posOut++] = pLat;
    269                         }
    270                         outputList[posOut++] = eLon;
    271                         outputList[posOut++] = eLat;
     268                            outputList[posOut++] = px;
     269                            outputList[posOut++] = py;
     270                        }
     271                        outputList[posOut++] = ex;
     272                        outputList[posOut++] = ey;
    272273                    } else {
    273274                        if (sIsIn) {
    274                             outputList[posOut++] = pLon;
    275                             outputList[posOut++] = pLat;
     275                            outputList[posOut++] = px;
     276                            outputList[posOut++] = py;
    276277                        }
    277278                    }
    278279                }
    279280                // S = E
    280                 sLon = eLon;
    281                 sLat = eLat;
     281                sx = ex;
     282                sy = ey;
    282283                sIsIn = eIsIn;
    283284            }
Note: See TracChangeset for help on using the changeset viewer.