comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2652:9d2a06c3a134

Added DataType for lines that also stores width, use it. Added HasLabel interface for some series. flys-artifacts/trunk@4318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 27 Apr 2012 09:58:21 +0000
parents a6fa128e4654
children 0143b44631cc
comparison
equal deleted inserted replaced
2651:9e9eb9d97548 2652:9d2a06c3a134
11 11
12 import org.apache.log4j.Logger; 12 import org.apache.log4j.Logger;
13 13
14 import gnu.trove.TDoubleArrayList; 14 import gnu.trove.TDoubleArrayList;
15 15
16 /**
17 * Utility to create lines (intersect water with cross-section etc).
18 */
16 public class Lines 19 public class Lines
17 { 20 {
18 private static Logger log = Logger.getLogger(Lines.class); 21 private static Logger log = Logger.getLogger(Lines.class);
19 22
20 public static final double EPSILON = 1e-4; 23 public static final double EPSILON = 1e-4;
22 public static enum Mode { UNDEF, WET, DRY }; 25 public static enum Mode { UNDEF, WET, DRY };
23 26
24 protected Lines() { 27 protected Lines() {
25 } 28 }
26 29
30 /**
31 * Calculate the 'length' of the given lines.
32 */
27 public static double length(List<Line2D> lines) { 33 public static double length(List<Line2D> lines) {
28 double sum = 0d; 34 double sum = 0d;
29 for (Line2D line: lines) { 35 for (Line2D line: lines) {
30 double xDiff = line.getX1() - line.getX2(); 36 double xDiff = line.getX1() - line.getX2();
31 double yDiff = line.getY1() - line.getY2(); 37 double yDiff = line.getY1() - line.getY2();
259 } 265 }
260 266
261 return result; 267 return result;
262 } 268 }
263 269
264 public static double [][] createWaterLines( 270
271 /**
272 * Class holding points that form lines and the calculated length.
273 */
274 public static class LineData {
275 public double [][] points;
276 public double width;
277 public LineData(double[][] points, double width) {
278 this.points = points;
279 this.width = width;
280 }
281 }
282
283
284 public static LineData createWaterLines(
265 List<Point2D> points, 285 List<Point2D> points,
266 double waterlevel 286 double waterlevel
267 ) { 287 ) {
268 List<Line2D> lines = fillWater(points, waterlevel); 288 List<Line2D> lines = fillWater(points, waterlevel);
269 289
270 TDoubleArrayList lxs = new TDoubleArrayList(); 290 TDoubleArrayList lxs = new TDoubleArrayList();
271 TDoubleArrayList lys = new TDoubleArrayList(); 291 TDoubleArrayList lys = new TDoubleArrayList();
292 double linesLength = 0.0f;
272 293
273 for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) { 294 for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) {
274 Line2D l = iter.next(); 295 Line2D line = iter.next();
275 Point2D p1 = l.getP1(); 296 Point2D p1 = line.getP1();
276 Point2D p2 = l.getP2(); 297 Point2D p2 = line.getP2();
277 lxs.add(p1.getX()); 298 lxs.add(p1.getX());
278 lys.add(p1.getY()); 299 lys.add(p1.getY());
279 lxs.add(p2.getX()); 300 lxs.add(p2.getX());
280 lys.add(p2.getY()); 301 lys.add(p2.getY());
302
303 // Length calculation.
304 double xDiff = line.getX1() - line.getX2();
305 double yDiff = line.getY1() - line.getY2();
306 linesLength += Math.sqrt(xDiff*xDiff + yDiff*yDiff);
307
281 if (iter.hasNext()) { 308 if (iter.hasNext()) {
282 lxs.add(Double.NaN); 309 lxs.add(Double.NaN);
283 lys.add(Double.NaN); 310 lys.add(Double.NaN);
284 } 311 }
285 } 312 }
286 313
287 return new double [][] { lxs.toNativeArray(), lys.toNativeArray() }; 314 return new LineData(
315 new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
316 linesLength
317 );
288 } 318 }
289 } 319 }
290 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 320 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org