# HG changeset patch # User Ingo Weinzierl # Date 1347625034 0 # Node ID d8f2ab5b61c31681e03960dc571c6867dcb4fec5 # Parent a6f5bb10eff4205875d0cf9b7526935a35ee9ba6 Added JFreeUtil.randomizeLine() to generate randomized lines. flys-artifacts/trunk@5467 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a6f5bb10eff4 -r d8f2ab5b61c3 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Sep 14 08:01:02 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Sep 14 12:17:14 2012 +0000 @@ -1,3 +1,8 @@ +2012-09-14 Ingo Weinzierl + + * src/main/java/de/intevation/flys/jfree/JFreeUtil.java: Added function to + generate a randomized line. + 2012-09-14 Ingo Weinzierl * doc/conf/themes.xml: Defined new mappings for the six bed quality diff -r a6f5bb10eff4 -r d8f2ab5b61c3 flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java --- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java Fri Sep 14 08:01:02 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java Fri Sep 14 12:17:14 2012 +0000 @@ -1,19 +1,20 @@ package de.intevation.flys.jfree; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; +import java.util.Iterator; +import java.util.Random; + +import org.apache.log4j.Logger; +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.EntityCollection; +import org.w3c.dom.Document; + import de.intevation.flys.artifacts.math.Function; -import java.awt.Shape; - -import java.awt.geom.Rectangle2D; - -import java.util.Iterator; - -import org.jfree.chart.entity.ChartEntity; -import org.jfree.chart.entity.EntityCollection; - -import org.w3c.dom.Document; - public class JFreeUtil { + + private static final Logger logger = Logger.getLogger(JFreeUtil.class); /** Do not instantiate. */ private JFreeUtil() { @@ -50,6 +51,50 @@ return false; } + + + /** + * This function samples a randomized line that contains of x and y values + * between startX, endX, startY and endY. The + * number of points in the line is specified by num. + * + * @param num The number of points in the line. + * @param startX The min value of the x values. + * @param endX The max value of the x values. + * @param startY The min value of the y values. + * @param endY The max value of the y values. + * @return an array with [allX-values, allY-values]. + * @throws IllegalArgumentException + */ + public static double[][] randomizeLine( + int num, + double startX, + double endX, + double startY, + double endY + ) throws IllegalArgumentException + { + if (num <= 0) { + throw new IllegalArgumentException("Parameter 'num' has to be > 0"); + } + + Random random = new Random(); + + double[] x = new double[num]; + double[] y = new double[num]; + + for (int i = 0; i < num; i++) { + double xFac = random.nextDouble(); + double yFac = random.nextDouble(); + + x[i] = startX + xFac * (endX - startX); + y[i] = startY + yFac * (endY - startY); + + logger.debug("Created new point: " + x[i] + "|" + y[i]); + } + + return new double[][] { x, y }; + } public static StyledXYSeries sampleFunction2D(