# HG changeset patch # User Sascha L. Teichmann # Date 1270726304 0 # Node ID bb7afd7833212bc8e73e1a3cf42abb820313e135 # Parent 9058c08eac3a973821c44bf7388be18a681bf9e4 Removed trailing whitespace. Added more javadoc. gnv-artifacts/trunk@887 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu Apr 08 11:31:44 2010 +0000 @@ -1,3 +1,19 @@ +2010-04-08 Sascha L. Teichmann + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java, + src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Removed trailing whitespace. + + * src/main/java/de/intevation/gnv/math/ConstantXYDepth.java, + src/main/java/de/intevation/gnv/math/LinearMetrics.java, + src/main/java/de/intevation/gnv/math/QueriedXYDepth.java, + src/main/java/de/intevation/gnv/math/L1Comparator.java, + src/main/java/de/intevation/gnv/math/Metrics.java, + src/main/java/de/intevation/gnv/math/LinearToMap.java, + src/main/java/de/intevation/gnv/math/LinearFunction.java, + src/main/java/de/intevation/gnv/math/Interpolator.java: + Added more javadoc. + 2010-04-08 Ingo Weinzierl * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java, diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/ConstantXYDepth.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/ConstantXYDepth.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/ConstantXYDepth.java Thu Apr 08 11:31:44 2010 +0000 @@ -3,16 +3,28 @@ import com.vividsolutions.jts.geom.Coordinate; /** + * Instances of the implementation return a constant value. + * * @author Sascha L. Teichmann */ public class ConstantXYDepth implements XYDepth { + /** + * The constant depth. + */ protected double depth; + /** + * Default constructor. The constant depth = 0. + */ public ConstantXYDepth() { } + /** + * Construtor to create a ConstantXYDepth with a given depth. + * @param depth The constant depth. + */ public ConstantXYDepth(double depth) { this.depth = depth; } @@ -21,4 +33,4 @@ return depth; } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolator.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolator.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolator.java Thu Apr 08 11:31:44 2010 +0000 @@ -3,10 +3,19 @@ import com.vividsolutions.jts.geom.Coordinate; /** + * Implementations of this interface interpolate coordinates + * a line at a given point determined by a factor t (0 <= t <= 1).
+ * If t = 0 the start point of the line is used.
+ * If t = 1 the start point of the line is used. * @author Sascha L. Teichmann */ public interface Interpolator { + /** + * Interpolates a point along a line with a given factor between 0 and 1. + * @param t The factor. + * @param v The result of the interpolation is stored in this coordinate. + */ void interpolate(double t, Coordinate v); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java Thu Apr 08 11:31:44 2010 +0000 @@ -5,6 +5,11 @@ import java.util.Comparator; /** + * Compares two coordinates a and b by their L1(Matnhattan) distance + * relative to a reference point r. + * da = L1(a, r)
+ * db = L1(b, r)
+ * -1 if da < db, +1 if da > db, 0 else. * @author Sascha L. Teichmann */ public class L1Comparator @@ -12,17 +17,35 @@ { private Coordinate ref; + /** + * Default constructor. + */ public L1Comparator() { } + /** + * Constructor to create a L1Comparator with a given reference point. + * @param ref The reference point. + */ public L1Comparator(Coordinate ref) { this.ref = ref; } + /** + * Explicitly sets the reference point. + * @param ref The reference point. + */ public void setReference(Coordinate ref) { this.ref = ref; } + /** + * Compares to coordinate by their L1 distance to the reference point. + * @param a The first coordinate. + * @param b The second coordinate. + * @return -1 if L1(a, ref) < L1(b, ref), + * +1 if L1(a, ref) > L1(b, ref), 0 else. + */ public int compare(Object a, Object b) { Coordinate pa = (Coordinate)a; Coordinate pb = (Coordinate)b; @@ -33,9 +56,15 @@ return 0; } + /** + * Computes the L1 distance between two points a and b:
+ * L1(a, b) = abs(a.x - b.x) + abs(a.y - b.y) + * @param a The first point. + * @param b The second point. + * @return The L1 distance. + */ public static double L1(Coordinate a, Coordinate b) { return Math.abs(a.x - b.x) + Math.abs(a.y - b.y); } - } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java Thu Apr 08 11:31:44 2010 +0000 @@ -7,22 +7,49 @@ import org.apache.commons.math.optimization.fitting.ParametricRealFunction; /** + * Models a linear function to be usable in the fitting frame of + * the Apache Commons Mathematics Library. + * * @author Sascha L. Teichmann */ public class LinearFunction implements ParametricRealFunction { + /** + * Instance to prevent needless creations of instances. + */ public static final LinearFunction INSTANCE = new LinearFunction(); + /** + * Specialized class to be useful in function evaluating + * in the Apache Commons Mathematics Library. + */ public static class Univariate implements UnivariateRealFunction { + /** + * The linear scaling factor. + */ protected double m; + /** + * The linear offset. + */ protected double b; + /** + * Default constructor. + */ public Univariate() { } + /** + * Constructor to create a Univariate with the linear parameters + * of the line between (x1, y1) and (x2, y2). + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. + */ public Univariate(double x1, double y1, double x2, double y2) { if (y1 == y2) { m = 0d; @@ -39,6 +66,9 @@ } } // class Univariate + /** + * Default constructor. + */ public LinearFunction() { } diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java Thu Apr 08 11:31:44 2010 +0000 @@ -3,14 +3,22 @@ import com.vividsolutions.jts.geom.Coordinate; /** + * Implements {@link de.intevation.gnv.math.Metrics} + * for linear interpolations and distance measurements. * @author Sascha L. Teichmann */ public final class LinearMetrics implements Metrics { + /** + * Instance to prevent needless creations of instances. + */ public static final Metrics INSTANCE = new LinearMetrics(); + /** + * Implements the corresponding linear interpolator. + */ public static final class LinearInterpolator implements Interpolator { @@ -19,6 +27,12 @@ private double my; private double by; + /** + * Constructor to create a linear interpolator between two + * given points. + * @param p1 The first point. + * @param p2 The second point. + */ public LinearInterpolator(Coordinate p1, Coordinate p2) { /* @@ -56,4 +70,4 @@ return new LinearInterpolator(p1, p2); } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearToMap.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearToMap.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearToMap.java Thu Apr 08 11:31:44 2010 +0000 @@ -7,10 +7,18 @@ import java.util.NoSuchElementException; /** + * Given a list of line segments instances of this class are able + * to span a metric system between a start and an end point + * represented as scalar values to 2D coordinate on the + * course of the segments. + * * @author Sascha L. Teichmann */ public class LinearToMap { + /** + * Represents a segment of the line string. + */ public static final class Range { private Range next; @@ -23,9 +31,23 @@ private Interpolator interpolator; + /** + * Default constructor. + */ public Range() { } + /** + * Constructor to create a segment that maps + * a coordinate pair to two scalar values. + * Interpolations inside this segment are done with + * a given interpolator. + * @param from Start point of the segment. + * @param to End point of the segment. + * @param interpolator The interpolator. + * @param p1 The scalar value mapped to the start point. + * @param p2 The scalar value mappend to the end point. + */ public Range( double from, double to, @@ -44,29 +66,70 @@ : 1.0d/(to - from); } + /** + * Interpolated a coordinate on the segment given a scalar value + * between the start and end point of the range. + * @param x The scalar value. + * @param v The interpolated value is stored here. + */ public void eval(double x, Coordinate v) { interpolator.interpolate((x - from)*b, v); } + /** + * Checks if a given value is inside this segment. + * @param x The value to test + * @return true if inside, else false. + */ public boolean inside(double x) { return x >= from && x <= to; } + /** + * Returns the start point of this segment. + * @return The start point. + */ public Coordinate startPoint() { return p1; } + /** + * Return the end point of this segment. + * @return The end point. + */ public Coordinate endPoint() { return p2; } } // class Range + /** + * The head of the internal range list. + */ protected Range head; + + /** + * The last accessed segment. Used to accelerate + * the access of the right segment. + */ protected Range last; + /** + * Default constructor. + */ public LinearToMap() { } + /** + * Constructor to create a LinearToMap that maps + * given scalar values to coordinates of a given + * list of line segments. + * @param path The list of line segments. + * @param from The start value mapped to the start point + * of the first line segment. + * @param to The end value mapped to the end point of + * the last line segment. + * @param metrics The metric used to span the 2D space. + */ public LinearToMap( List path, double from, @@ -108,6 +171,11 @@ } } + /** + * Returns a segment on which a given value is found. + * @param diagramX The value. + * @return The segment or null if no matching segment was found. + */ protected Range locateRange(double diagramX) { if (last != null && last.inside(diagramX)) { @@ -125,6 +193,13 @@ return null; } + /** + * Interpolates a coordinate at a given scalar position. + * @param diagramX The scalar position. + * @param v The interpolated coordinate is stored here. + * @return true if the scalar position is inside the + * spanned range of the line string, else false. + */ public boolean locate(double diagramX, Coordinate v) { Range range = locateRange(diagramX); if (range == null) { @@ -134,6 +209,13 @@ return true; } + /** + * Returns the length of a given line string using + * a given metric. + * @param path The line string. + * @param metrics The used metric. + * @return The length of the line string. + */ public static double length( List path, Metrics metrics @@ -147,6 +229,10 @@ return sum; } + /** + * Return the number of segments in this map. + * @return the number of segments. + */ public int numRanges() { int count = 0; Range current = head; @@ -157,6 +243,10 @@ return count; } + /** + * Returns an iterator over all segments of this map. + * @return The iterator. + */ public Iterator ranges() { return new Iterator() { diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/Metrics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/Metrics.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/Metrics.java Thu Apr 08 11:31:44 2010 +0000 @@ -3,12 +3,28 @@ import com.vividsolutions.jts.geom.Coordinate; /** + * Implementations provides the ability to calculate the distance between + * two points ans support for interpolating points between two points. + * * @author Sascha L. Teichmann */ public interface Metrics { + /** + * Calculates the distance between two given points. + * @param p1 The first point. + * @param p2 The second point. + * @return The distance. + */ double distance(Coordinate p1, Coordinate p2); + /** + * Return an interpolator which allows interpolations between + * two given points. + * @param p1 The first point. + * @param p2 The second point. + * @return The interpolator. + */ Interpolator getInterpolator(Coordinate p1, Coordinate p2); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Thu Apr 08 11:31:44 2010 +0000 @@ -21,14 +21,15 @@ import org.apache.log4j.Logger; /** + * This implementation uses the geo backend to query a depth via + * a raster layer stored in the database. + * * @author Tim Englich * @author Sascha L. Teichmann */ -public class QueriedXYDepth implements XYDepth { - - /** - * the logger, used to log exceptions and additonaly information - */ +public class QueriedXYDepth +implements XYDepth +{ private static Logger log = Logger.getLogger(QueriedXYDepth.class); private static final String queryID = "rasterQuery"; @@ -41,19 +42,24 @@ private int interpolation; + /** + * Default construtor. Interpolation method is bilinear. + */ public QueriedXYDepth() { this(RasterObject.BILINEAR); } + /** + * Constructor to create a QueriedXYDepth with a given interpolation + * method. + * @param interpolation The interpolation method. + */ public QueriedXYDepth(int interpolation) { this.interpolation = interpolation; rasterData = new ArrayList>(); queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); } - /** - * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate) - */ public double depth(Coordinate coordinate) { double resultValue = Double.NaN; diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Thu Apr 08 11:31:44 2010 +0000 @@ -386,7 +386,7 @@ /** * Find the parameter name which is used during mapfile creation in * MapfileGenerator. - * + * * @param callContext The CallContext object. * @return the parameter name of the current parameterization. */ diff -r 9058c08eac3a -r bb7afd783321 gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Thu Apr 08 10:10:04 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Thu Apr 08 11:31:44 2010 +0000 @@ -203,7 +203,7 @@ "QF" }; - + /** * Profile for exporting data to odv */ @@ -620,7 +620,7 @@ /** * Create an odv file representing the data corresponding to the current * parameterization. - * + * * @param outputStream The output stream used to export the odv file. * @param result The data used for odv file creation. * @param uuid The UUID of the current artifact.