Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 8955:798d9dcbccdd
BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
author | mschaefer |
---|---|
date | Mon, 19 Mar 2018 16:32:42 +0100 |
parents | 5d5d482da3e9 |
children | 45f1ad66560e |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Mon Mar 19 14:13:37 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Mon Mar 19 16:32:42 2018 +0100 @@ -37,6 +37,12 @@ private final NavigableMap<Double, BedHeightValue> values; + private double meanBedHeight; + + private double minBedHeight; + + private double maxBedHeight; + /** * Create bed height finders from a collection of bed heights. */ @@ -139,23 +145,53 @@ } public double getMeanBedHeight(final double km) { + getBedHeights(km); + return this.meanBedHeight; + } - if (this.values.containsKey(km)) - return this.values.get(km).getHeight(); + public double getMinBedHeight(final double km) { + getBedHeights(km); + return this.minBedHeight; + } + + public double getMaxBedHeight(final double km) { + getBedHeights(km); + return this.maxBedHeight; + } + + private boolean getBedHeights(final double km) { + if (this.values.containsKey(km)) { + this.meanBedHeight = (this.values.get(km).getHeight() != null) ? this.values.get(km).getHeight().doubleValue() : Double.NaN; + this.minBedHeight = (this.values.get(km).getMinHeight() != null) ? this.values.get(km).getMinHeight().doubleValue() : Double.NaN; + this.maxBedHeight = (this.values.get(km).getMaxHeight() != null) ? this.values.get(km).getMaxHeight().doubleValue() : Double.NaN; + return true; + } final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km); final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km); - if (floorEntry == null || ceilingEntry == null) - return Double.NaN; + if (floorEntry == null || ceilingEntry == null) { + this.meanBedHeight = Double.NaN; + this.minBedHeight = Double.NaN; + this.maxBedHeight = Double.NaN; + return false; + } - final double floorKm = floorEntry.getKey(); - final double floorHeight = floorEntry.getValue().getHeight(); - final double ceilKm = ceilingEntry.getKey(); - final double ceilHeight = ceilingEntry.getValue().getHeight(); + final double floorKm = floorEntry.getKey().doubleValue(); + final double ceilKm = ceilingEntry.getKey().doubleValue(); // FIXME: check if we always want that... - return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilHeight); + this.meanBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getHeight(), ceilingEntry.getValue().getHeight()); + this.minBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getMinHeight(), ceilingEntry.getValue().getMinHeight()); + this.maxBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getMaxHeight(), ceilingEntry.getValue().getMaxHeight()); + return true; + } + + private double interpolate(final double km, final double floorKm, final double ceilKm, final Double floorHeight, final Double ceilHeight) { + if ((floorHeight != null) && (ceilHeight != null)) + return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilHeight); + else + return Double.NaN; } } \ No newline at end of file