Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesWFacet.java @ 7494:4de4b19b6be6
Fixed half broken interpolation code for lines to 'Dauerlinie'.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 01 Nov 2013 13:25:54 +0100 |
parents | 3e9961dcbf9a |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
7493:8cdc86327149 | 7494:4de4b19b6be6 |
---|---|
18 import org.dive4elements.artifacts.DataProvider; | 18 import org.dive4elements.artifacts.DataProvider; |
19 | 19 |
20 import org.dive4elements.artifactdatabase.state.DefaultFacet; | 20 import org.dive4elements.artifactdatabase.state.DefaultFacet; |
21 | 21 |
22 import org.dive4elements.river.artifacts.MainValuesArtifact; | 22 import org.dive4elements.river.artifacts.MainValuesArtifact; |
23 import org.dive4elements.river.artifacts.math.Linear; | |
24 import org.dive4elements.river.jfree.RiverAnnotation; | 23 import org.dive4elements.river.jfree.RiverAnnotation; |
25 import org.dive4elements.river.jfree.StickyAxisAnnotation; | 24 import org.dive4elements.river.jfree.StickyAxisAnnotation; |
26 import org.dive4elements.river.exports.fixings.FixChartGenerator; | 25 import org.dive4elements.river.exports.fixings.FixChartGenerator; |
27 | 26 |
28 | 27 |
52 * Set the hit-point in W where a line drawn from the axis would hit the | 51 * Set the hit-point in W where a line drawn from the axis would hit the |
53 * curve in WQDay (if hit). | 52 * curve in WQDay (if hit). |
54 * Employ linear interpolation. | 53 * Employ linear interpolation. |
55 */ | 54 */ |
56 protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) { | 55 protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) { |
56 float w = annotation.getPos(); | |
57 | 57 |
58 if (wqday.size() == 0) { | 58 Double day = wqday.interpolateDayByW(w); |
59 return; | 59 |
60 if (day != null) { | |
61 annotation.setHitPoint(day.floatValue()); | |
60 } | 62 } |
61 | 63 else if (logger.isDebugEnabled()) { |
62 int idx = 0; | 64 logger.debug("StickyAnnotation does not hit wqday curve: " + w); |
63 float w = annotation.getPos(); | |
64 boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1); | |
65 if (wIncreases) { | |
66 while (idx < wqday.size() && wqday.getW(idx) < w) { | |
67 idx++; | |
68 } | |
69 } | |
70 else { | |
71 idx = wqday.size() -1; | |
72 while (idx > 0 && wqday.getW(idx) > w) { | |
73 idx--; | |
74 } | |
75 } | |
76 | |
77 double day = 0d; | |
78 int mod = (wIncreases) ? -1 : +1; | |
79 if (idx != 0 && idx < wqday.size()-1-mod) { | |
80 day = Linear.linear(w, wqday.getW(idx +mod), wqday.getW(idx), | |
81 wqday.getDay(idx+mod), wqday.getDay(idx)); | |
82 annotation.setHitPoint((float)day); | |
83 } | |
84 else { | |
85 logger.debug("StickyAnnotation does not hit wqday curve"); | |
86 } | 65 } |
87 } | 66 } |
88 | 67 |
89 | 68 |
90 /** | 69 /** |