comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/LinearInterpolated.java @ 6153:12af732c9d0f

LinearInterpolated#apply(): Added simple test if the two datasets intersect at all.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 02 Jun 2013 18:13:29 +0200
parents 0587819960c3
children 1dff8e71c4d6
comparison
equal deleted inserted replaced
6152:0587819960c3 6153:12af732c9d0f
174 double to 174 double to
175 ) { 175 ) {
176 return apply(MAX, other, from, to); 176 return apply(MAX, other, from, to);
177 } 177 }
178 178
179 public boolean intersect(LinearInterpolated other) {
180 if (xs.isEmpty() || other.xs.isEmpty()) {
181 return false;
182 }
183
184 double tMax = xs.max();
185 double oMin = other.xs.min();
186 if (tMax < oMin) {
187 return false;
188 }
189
190 double tMin = xs.min();
191 double oMax = other.xs.max();
192 return !(tMin > oMax);
193 }
194
179 public LinearInterpolated apply( 195 public LinearInterpolated apply(
180 Operator operator, 196 Operator operator,
181 LinearInterpolated other, 197 LinearInterpolated other,
182 double from, 198 double from,
183 double to 199 double to
184 ) { 200 ) {
201 LinearInterpolated result = new LinearInterpolated();
202 if (!intersect(other)) {
203 return result;
204 }
205
185 Set<Double> points = new TreeSet<Double>(CMP); 206 Set<Double> points = new TreeSet<Double>(CMP);
186 points.add(from); 207 points.add(from);
187 points.add(to); 208 points.add(to);
188 209
189 this .pointsInRange(from, to, points); 210 this .pointsInRange(from, to, points);
190 other.pointsInRange(from, to, points); 211 other.pointsInRange(from, to, points);
191 212
192 LinearInterpolated result = new LinearInterpolated();
193 213
194 for (double x: points) { 214 for (double x: points) {
195 if (!inGap(x) && !other.inGap(x)) { 215 if (!inGap(x) && !other.inGap(x)) {
196 double y1 = this .value(x); 216 double y1 = this .value(x);
197 double y2 = other.value(x); 217 double y2 = other.value(x);

http://dive4elements.wald.intevation.org