Changeset 14587 in josm for trunk/src/org
- Timestamp:
- 2018-12-22T16:17:33+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ShapeClipper.java
r14586 r14587 127 127 for (int i = 2; i < num;) { 128 128 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) { 130 130 path.lineTo(x, y); 131 131 lastX = x; … … 190 190 input = outputList; 191 191 outputList = new double[countVals + 16]; 192 double s Lon = 0, sLat= 0;193 double p Lon = 0, pLat= 0; // intersection192 double sx = 0, sy = 0; 193 double px = 0, py = 0; // intersection 194 194 int posIn = countVals - 2; 195 195 int posOut = 0; … … 197 197 if (posIn >= countVals) 198 198 posIn = 0; 199 double e Lon= input[posIn++];200 double e Lat= input[posIn++];199 double ex = input[posIn++]; 200 double ey = input[posIn++]; 201 201 switch (side) { 202 202 case LEFT: 203 eIsIn = (e Lon>= leftX);203 eIsIn = (ex >= leftX); 204 204 break; 205 205 case TOP: 206 eIsIn = (e Lat< upperY);206 eIsIn = (ey < upperY); 207 207 break; 208 208 case RIGHT: 209 eIsIn = (e Lon< rightX);209 eIsIn = (ex < rightX); 210 210 break; 211 211 default: 212 eIsIn = (e Lat>= lowerY);212 eIsIn = (ey >= lowerY); 213 213 } 214 214 if (i > 0) { … … 216 216 // compute intersection 217 217 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); 220 221 else 221 222 slope = 1; … … 223 224 switch (side) { 224 225 case LEFT: 225 p Lon= leftX;226 p Lat = slope * (leftX - sLon) + sLat;226 px = leftX; 227 py = slope * (leftX - sx) + sy; 227 228 break; 228 229 case RIGHT: 229 p Lon= rightX;230 p Lat = slope * (rightX - sLon) + sLat;230 px = rightX; 231 py = slope * (rightX - sx) + sy; 231 232 break; 232 233 233 234 case TOP: 234 if ( eLon != sLon)235 p Lon = sLon + (upperY - sLat) / slope;235 if (isNotZero) 236 px = sx + (upperY - sy) / slope; 236 237 else 237 p Lon = sLon;238 p Lat= upperY;238 px = sx; 239 py = upperY; 239 240 break; 240 241 default: // BOTTOM 241 if ( eLon != sLon)242 p Lon = sLon + (lowerY - sLat) / slope;242 if (isNotZero) 243 px = sx + (lowerY - sy) / slope; 243 244 else 244 p Lon = sLon;245 p Lat= lowerY;245 px = sx; 246 py = lowerY; 246 247 break; 247 248 … … 265 266 if (eIsIn) { 266 267 if (!sIsIn) { 267 outputList[posOut++] = p Lon;268 outputList[posOut++] = p Lat;269 } 270 outputList[posOut++] = e Lon;271 outputList[posOut++] = e Lat;268 outputList[posOut++] = px; 269 outputList[posOut++] = py; 270 } 271 outputList[posOut++] = ex; 272 outputList[posOut++] = ey; 272 273 } else { 273 274 if (sIsIn) { 274 outputList[posOut++] = p Lon;275 outputList[posOut++] = p Lat;275 outputList[posOut++] = px; 276 outputList[posOut++] = py; 276 277 } 277 278 } 278 279 } 279 280 // S = E 280 s Lon = eLon;281 s Lat = eLat;281 sx = ex; 282 sy = ey; 282 283 sIsIn = eIsIn; 283 284 }
Note:
See TracChangeset
for help on using the changeset viewer.