Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
8954:183f42641ab6 | 8955:798d9dcbccdd |
---|---|
34 public final class BedHeightsFinder { | 34 public final class BedHeightsFinder { |
35 | 35 |
36 private final BedHeightInfo info; | 36 private final BedHeightInfo info; |
37 | 37 |
38 private final NavigableMap<Double, BedHeightValue> values; | 38 private final NavigableMap<Double, BedHeightValue> values; |
39 | |
40 private double meanBedHeight; | |
41 | |
42 private double minBedHeight; | |
43 | |
44 private double maxBedHeight; | |
39 | 45 |
40 /** | 46 /** |
41 * Create bed height finders from a collection of bed heights. | 47 * Create bed height finders from a collection of bed heights. |
42 */ | 48 */ |
43 public static Collection<BedHeightsFinder> createTkhBedHeights(final DoubleRange range, final Collection<BedHeight> bedHeights) { | 49 public static Collection<BedHeightsFinder> createTkhBedHeights(final DoubleRange range, final Collection<BedHeight> bedHeights) { |
137 public Collection<Double> getStations() { | 143 public Collection<Double> getStations() { |
138 return this.values.keySet(); | 144 return this.values.keySet(); |
139 } | 145 } |
140 | 146 |
141 public double getMeanBedHeight(final double km) { | 147 public double getMeanBedHeight(final double km) { |
148 getBedHeights(km); | |
149 return this.meanBedHeight; | |
150 } | |
142 | 151 |
143 if (this.values.containsKey(km)) | 152 public double getMinBedHeight(final double km) { |
144 return this.values.get(km).getHeight(); | 153 getBedHeights(km); |
154 return this.minBedHeight; | |
155 } | |
156 | |
157 public double getMaxBedHeight(final double km) { | |
158 getBedHeights(km); | |
159 return this.maxBedHeight; | |
160 } | |
161 | |
162 private boolean getBedHeights(final double km) { | |
163 if (this.values.containsKey(km)) { | |
164 this.meanBedHeight = (this.values.get(km).getHeight() != null) ? this.values.get(km).getHeight().doubleValue() : Double.NaN; | |
165 this.minBedHeight = (this.values.get(km).getMinHeight() != null) ? this.values.get(km).getMinHeight().doubleValue() : Double.NaN; | |
166 this.maxBedHeight = (this.values.get(km).getMaxHeight() != null) ? this.values.get(km).getMaxHeight().doubleValue() : Double.NaN; | |
167 return true; | |
168 } | |
145 | 169 |
146 final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km); | 170 final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km); |
147 final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km); | 171 final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km); |
148 | 172 |
149 if (floorEntry == null || ceilingEntry == null) | 173 if (floorEntry == null || ceilingEntry == null) { |
150 return Double.NaN; | 174 this.meanBedHeight = Double.NaN; |
175 this.minBedHeight = Double.NaN; | |
176 this.maxBedHeight = Double.NaN; | |
177 return false; | |
178 } | |
151 | 179 |
152 final double floorKm = floorEntry.getKey(); | 180 final double floorKm = floorEntry.getKey().doubleValue(); |
153 final double floorHeight = floorEntry.getValue().getHeight(); | 181 final double ceilKm = ceilingEntry.getKey().doubleValue(); |
154 final double ceilKm = ceilingEntry.getKey(); | |
155 final double ceilHeight = ceilingEntry.getValue().getHeight(); | |
156 | 182 |
157 // FIXME: check if we always want that... | 183 // FIXME: check if we always want that... |
158 | 184 |
159 return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilHeight); | 185 this.meanBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getHeight(), ceilingEntry.getValue().getHeight()); |
186 this.minBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getMinHeight(), ceilingEntry.getValue().getMinHeight()); | |
187 this.maxBedHeight = interpolate(km, floorKm, ceilKm, floorEntry.getValue().getMaxHeight(), ceilingEntry.getValue().getMaxHeight()); | |
188 return true; | |
189 } | |
190 | |
191 private double interpolate(final double km, final double floorKm, final double ceilKm, final Double floorHeight, final Double ceilHeight) { | |
192 if ((floorHeight != null) && (ceilHeight != null)) | |
193 return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilHeight); | |
194 else | |
195 return Double.NaN; | |
160 } | 196 } |
161 } | 197 } |