Changeset 6007 in josm for trunk/src/org


Ignore:
Timestamp:
2013-06-15T11:12:46+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8794 - NumberFormatException in Geometry.getCentroid()

File:
1 edited

Legend:

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

    r5980 r6007  
    651651            EastNorth n1 = nodes.get((i+1) % nodes.size()).getEastNorth();
    652652
    653             BigDecimal x0 = new BigDecimal(n0.east());
    654             BigDecimal y0 = new BigDecimal(n0.north());
    655             BigDecimal x1 = new BigDecimal(n1.east());
    656             BigDecimal y1 = new BigDecimal(n1.north());
    657 
    658             BigDecimal k = x0.multiply(y1, MathContext.DECIMAL128).subtract(y0.multiply(x1, MathContext.DECIMAL128));
    659 
    660             area = area.add(k, MathContext.DECIMAL128);
    661             east = east.add(k.multiply(x0.add(x1, MathContext.DECIMAL128), MathContext.DECIMAL128));
    662             north = north.add(k.multiply(y0.add(y1, MathContext.DECIMAL128), MathContext.DECIMAL128));
     653            if (n0.isValid() && n1.isValid()) {
     654                BigDecimal x0 = new BigDecimal(n0.east());
     655                BigDecimal y0 = new BigDecimal(n0.north());
     656                BigDecimal x1 = new BigDecimal(n1.east());
     657                BigDecimal y1 = new BigDecimal(n1.north());
     658   
     659                BigDecimal k = x0.multiply(y1, MathContext.DECIMAL128).subtract(y0.multiply(x1, MathContext.DECIMAL128));
     660   
     661                area = area.add(k, MathContext.DECIMAL128);
     662                east = east.add(k.multiply(x0.add(x1, MathContext.DECIMAL128), MathContext.DECIMAL128));
     663                north = north.add(k.multiply(y0.add(y1, MathContext.DECIMAL128), MathContext.DECIMAL128));
     664            }
    663665        }
    664666
Note: See TracChangeset for help on using the changeset viewer.