Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearToMap.java @ 1129:ccfa07b88476
merged geo-backend
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:01 +0200 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
805
diff
changeset
|
8 |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.math; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
11 import com.vividsolutions.jts.geom.Coordinate; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
13 import java.util.Iterator; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.util.List; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.util.NoSuchElementException; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 /** |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
18 * Given a list of line segments instances of this class are able |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
19 * to span a metric system between a start and an end point |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
20 * represented as scalar values to 2D coordinate on the |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
21 * course of the segments. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
22 * |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
23 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 */ |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 public class LinearToMap |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 { |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
27 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
28 * Represents a segment of the line string. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
29 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public static final class Range { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 private Range next; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 private double from; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 private double to; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 private double b; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
37 private Coordinate p1; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
38 private Coordinate p2; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 private Interpolator interpolator; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
42 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
43 * Default constructor. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
44 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public Range() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
48 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
49 * Constructor to create a segment that maps |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
50 * a coordinate pair to two scalar values. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
51 * Interpolations inside this segment are done with |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
52 * a given interpolator. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
53 * @param from Start point of the segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
54 * @param to End point of the segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
55 * @param interpolator The interpolator. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
56 * @param p1 The scalar value mapped to the start point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
57 * @param p2 The scalar value mappend to the end point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
58 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 public Range( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
361
diff
changeset
|
60 double from, |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 double to, |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 Interpolator interpolator, |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
63 Coordinate p1, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
64 Coordinate p2 |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 ) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 this.from = from; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 this.to = to; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 this.interpolator = interpolator; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 this.p1 = p1; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 this.p2 = p2; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 b = from == to |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 ? 0d |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 : 1.0d/(to - from); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
77 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
78 * Interpolated a coordinate on the segment given a scalar value |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
79 * between the start and end point of the range. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
80 * @param x The scalar value. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
81 * @param v The interpolated value is stored here. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
82 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
83 public void eval(double x, Coordinate v) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 interpolator.interpolate((x - from)*b, v); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
87 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
88 * Checks if a given value is inside this segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
89 * @param x The value to test |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
90 * @return true if inside, else false. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
91 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 public boolean inside(double x) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 return x >= from && x <= to; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
96 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
97 * Returns the start point of this segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
98 * @return The start point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
99 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
100 public Coordinate startPoint() { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return p1; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
104 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
105 * Return the end point of this segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
106 * @return The end point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
107 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
108 public Coordinate endPoint() { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 return p2; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } // class Range |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
113 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
114 * The head of the internal range list. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
115 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 protected Range head; |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
117 |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
118 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
119 * The last accessed segment. Used to accelerate |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
120 * the access of the right segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
121 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 protected Range last; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
124 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
125 * Default constructor. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
126 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 public LinearToMap() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
130 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
131 * Constructor to create a LinearToMap that maps |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
132 * given scalar values to coordinates of a given |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
133 * list of line segments. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
134 * @param path The list of line segments. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
135 * @param from The start value mapped to the start point |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
136 * of the first line segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
137 * @param to The end value mapped to the end point of |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
138 * the last line segment. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
139 * @param metrics The metric used to span the 2D space. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
140 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 public LinearToMap( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
361
diff
changeset
|
142 List<? extends Coordinate> path, |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
361
diff
changeset
|
143 double from, |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
144 double to, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
145 Metrics metrics |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 ) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 double diagramLength = Math.abs(to - from); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 double worldLength = length(path, metrics); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 double rangeStart = from; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 Range last = null; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 for (int i = 1, N = path.size(); i < N; ++i) { |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
156 Coordinate p1 = path.get(i-1); |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
157 Coordinate p2 = path.get(i); |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 double segmentLength = metrics.distance(p1, p2); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 double relativeLength = segmentLength / worldLength; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 double rangeLength = diagramLength * relativeLength; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 double rangeEnd = rangeStart + rangeLength; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 Range range = new Range( |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 rangeStart, rangeEnd, |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 metrics.getInterpolator(p1, p2), |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 p1, p2); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 if (last == null) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 last = head = range; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 else { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 last.next = range; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 last = range; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 rangeStart = rangeEnd; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
182 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
183 * Returns a segment on which a given value is found. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
184 * @param diagramX The value. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
185 * @return The segment or null if no matching segment was found. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
186 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 protected Range locateRange(double diagramX) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 if (last != null && last.inside(diagramX)) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 return last; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 Range current = head; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 while (current != null) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 if (current.inside(diagramX)) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 return last = current; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 current = current.next; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 return null; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
204 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
205 * Interpolates a coordinate at a given scalar position. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
206 * @param diagramX The scalar position. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
207 * @param v The interpolated coordinate is stored here. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
208 * @return true if the scalar position is inside the |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
209 * spanned range of the line string, else false. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
210 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
211 public boolean locate(double diagramX, Coordinate v) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 Range range = locateRange(diagramX); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 if (range == null) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 return false; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 range.eval(diagramX, v); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 return true; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
220 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
221 * Returns the length of a given line string using |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
222 * a given metric. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
223 * @param path The line string. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
224 * @param metrics The used metric. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
225 * @return The length of the line string. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
226 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
227 public static double length( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
361
diff
changeset
|
228 List<? extends Coordinate> path, |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
229 Metrics metrics |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
230 ) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 double sum = 0d; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 for (int i = path.size()-1; i >= 1; --i) { |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
233 Coordinate p1 = path.get(i); |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
234 Coordinate p2 = path.get(i-1); |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 sum += metrics.distance(p1, p2); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 return sum; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
240 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
241 * Return the number of segments in this map. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
242 * @return the number of segments. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
243 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 public int numRanges() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 int count = 0; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 Range current = head; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 while (current != null) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 ++count; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 current = current.next; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 return count; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
254 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
255 * Returns an iterator over all segments of this map. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
256 * @return The iterator. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
257 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 public Iterator ranges() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 return new Iterator() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 Range current = head; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 public boolean hasNext() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 return current != null; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 public Object next() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 if (!hasNext()) { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 throw new NoSuchElementException(); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 Range x = current; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 current = current.next; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 return x; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 public void remove() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 throw new UnsupportedOperationException(); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 }; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 } |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
282 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |