Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2674:2be59d5b342c
Added and respect theme prop whether or not to display (not yet calculated) middle height.
flys-artifacts/trunk@4368 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 09 May 2012 20:05:46 +0000 |
parents | 0143b44631cc |
children | 22c8a9b4de31 |
comparison
equal
deleted
inserted
replaced
2673:0143b44631cc | 2674:2be59d5b342c |
---|---|
56 sum += Math.sqrt(xDiff*xDiff + yDiff*yDiff); | 56 sum += Math.sqrt(xDiff*xDiff + yDiff*yDiff); |
57 } | 57 } |
58 return sum; | 58 return sum; |
59 } | 59 } |
60 | 60 |
61 public static List<Line2D> fillWater(List<Point2D> points, double waterLevel) { | 61 |
62 /** List of lines and a double-precision area. */ | |
63 private static class ListWithArea { | |
64 public List<Line2D> lines; | |
65 public double area; | |
66 public ListWithArea(List<Line2D> lines, double area) { | |
67 this.lines = lines; | |
68 this.area = area; | |
69 } | |
70 } | |
71 | |
72 | |
73 public static ListWithArea fillWater(List<Point2D> points, double waterLevel) { | |
62 | 74 |
63 boolean debug = log.isDebugEnabled(); | 75 boolean debug = log.isDebugEnabled(); |
64 | 76 |
65 if (debug) { | 77 if (debug) { |
66 log.debug("fillWater"); | 78 log.debug("fillWater"); |
70 List<Line2D> result = new ArrayList(); | 82 List<Line2D> result = new ArrayList(); |
71 | 83 |
72 int N = points.size(); | 84 int N = points.size(); |
73 | 85 |
74 if (N == 0) { | 86 if (N == 0) { |
75 return result; | 87 return new ListWithArea(result, 0d); |
76 } | 88 } |
77 | 89 |
78 if (N == 1) { | 90 if (N == 1) { |
79 Point2D p = points.get(0); | 91 Point2D p = points.get(0); |
80 // Only generate point if over profile | 92 // Only generate point if over profile |
81 if (waterLevel > p.getY()) { | 93 if (waterLevel > p.getY()) { |
82 result.add(new Line2D.Double( | 94 result.add(new Line2D.Double( |
83 p.getX(), waterLevel, | 95 p.getX(), waterLevel, |
84 p.getX(), waterLevel)); | 96 p.getX(), waterLevel)); |
85 } | 97 } |
86 return result; | 98 return new ListWithArea(result, 0d); |
87 } | 99 } |
88 | 100 |
89 double minX = Double.MAX_VALUE; | 101 double minX = Double.MAX_VALUE; |
90 double minY = Double.MAX_VALUE; | 102 double minY = Double.MAX_VALUE; |
91 double maxX = -Double.MAX_VALUE; | 103 double maxX = -Double.MAX_VALUE; |
101 if (y > maxY) maxY = y; | 113 if (y > maxY) maxY = y; |
102 } | 114 } |
103 | 115 |
104 if (minY > waterLevel) { // profile completely over water level | 116 if (minY > waterLevel) { // profile completely over water level |
105 log.debug("complete over water"); | 117 log.debug("complete over water"); |
106 return result; | 118 return new ListWithArea(result, 0d); |
107 } | 119 } |
108 | 120 |
109 if (waterLevel > maxY) { // water floods profile | 121 if (waterLevel > maxY) { // water floods profile |
110 log.debug("complete under water"); | 122 log.debug("complete under water"); |
111 result.add(new Line2D.Double(minX, waterLevel, maxX, waterLevel)); | 123 result.add(new Line2D.Double(minX, waterLevel, maxX, waterLevel)); |
112 return result; | 124 return new ListWithArea(result, 0d); |
113 } | 125 } |
114 | 126 |
115 // Water is sometimes above, sometimes under profile. | 127 // Water is sometimes above, sometimes under profile. |
116 Mode mode = Mode.UNDEF; | 128 Mode mode = Mode.UNDEF; |
117 | 129 |
290 result.add(new Line2D.Double( | 302 result.add(new Line2D.Double( |
291 startX, waterLevel, | 303 startX, waterLevel, |
292 maxX, waterLevel)); | 304 maxX, waterLevel)); |
293 } | 305 } |
294 | 306 |
295 return result; | 307 return new ListWithArea(result, area); |
296 } | 308 } |
297 | 309 |
298 | 310 |
299 /** | 311 /** |
300 * Class holding points that form lines and the calculated length. | 312 * Class holding points that form lines and the calculated length. |
313 | 325 |
314 public static LineData createWaterLines( | 326 public static LineData createWaterLines( |
315 List<Point2D> points, | 327 List<Point2D> points, |
316 double waterlevel | 328 double waterlevel |
317 ) { | 329 ) { |
318 List<Line2D> lines = fillWater(points, waterlevel); | 330 ListWithArea listAndArea = fillWater(points, waterlevel); |
331 List<Line2D> lines = listAndArea.lines; | |
319 | 332 |
320 TDoubleArrayList lxs = new TDoubleArrayList(); | 333 TDoubleArrayList lxs = new TDoubleArrayList(); |
321 TDoubleArrayList lys = new TDoubleArrayList(); | 334 TDoubleArrayList lys = new TDoubleArrayList(); |
322 double linesLength = 0.0f; | 335 double linesLength = 0.0f; |
323 | 336 |
341 } | 354 } |
342 } | 355 } |
343 | 356 |
344 return new LineData( | 357 return new LineData( |
345 new double [][] { lxs.toNativeArray(), lys.toNativeArray() }, | 358 new double [][] { lxs.toNativeArray(), lys.toNativeArray() }, |
346 linesLength, 0d | 359 linesLength, listAndArea.area |
347 ); | 360 ); |
348 } | 361 } |
349 } | 362 } |
350 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 363 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |