Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java @ 9382:8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
author | mschaefer |
---|---|
date | Tue, 07 Aug 2018 14:06:49 +0200 |
parents | b194fa64506a |
children | 83e6acdf8fc6 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java Tue Aug 07 12:43:53 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java Tue Aug 07 14:06:49 2018 +0200 @@ -10,6 +10,7 @@ package org.dive4elements.river.artifacts.sinfo.flowdepth; import org.dive4elements.river.artifacts.model.Calculation; +import org.dive4elements.river.utils.Formatter; /** * @author Gernot Belger @@ -55,4 +56,13 @@ /* >= 1998 */ return 3; } + + /** + * Calculates a flow depth, rounded to the active scale + */ + public static double calcFlowDepth(final double wst, final double bedHeight) { + if (Double.isNaN(wst) || Double.isInfinite(wst) || Double.isNaN(bedHeight) || Double.isInfinite(bedHeight)) + return Math.max(wst - bedHeight, 0.0); + return Math.max(Formatter.roundFlowDepth(wst).subtract(Formatter.roundFlowDepth(bedHeight)).doubleValue(), 0.0); + } } \ No newline at end of file