Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3765:d8f2ab5b61c3
Added JFreeUtil.randomizeLine() to generate randomized lines.
flys-artifacts/trunk@5467 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 14 Sep 2012 12:17:14 +0000 |
parents | 63ef889eea2b |
children | 5a8f8fd5310c |
comparison
equal
deleted
inserted
replaced
3764:a6f5bb10eff4 | 3765:d8f2ab5b61c3 |
---|---|
1 package de.intevation.flys.jfree; | 1 package de.intevation.flys.jfree; |
2 | |
3 import java.awt.Shape; | |
4 import java.awt.geom.Rectangle2D; | |
5 import java.util.Iterator; | |
6 import java.util.Random; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 import org.jfree.chart.entity.ChartEntity; | |
10 import org.jfree.chart.entity.EntityCollection; | |
11 import org.w3c.dom.Document; | |
2 | 12 |
3 import de.intevation.flys.artifacts.math.Function; | 13 import de.intevation.flys.artifacts.math.Function; |
4 | 14 |
5 import java.awt.Shape; | |
6 | |
7 import java.awt.geom.Rectangle2D; | |
8 | |
9 import java.util.Iterator; | |
10 | |
11 import org.jfree.chart.entity.ChartEntity; | |
12 import org.jfree.chart.entity.EntityCollection; | |
13 | |
14 import org.w3c.dom.Document; | |
15 | |
16 public class JFreeUtil { | 15 public class JFreeUtil { |
16 | |
17 private static final Logger logger = Logger.getLogger(JFreeUtil.class); | |
17 | 18 |
18 /** Do not instantiate. */ | 19 /** Do not instantiate. */ |
19 private JFreeUtil() { | 20 private JFreeUtil() { |
20 } | 21 } |
21 | 22 |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 return false; | 52 return false; |
52 } | 53 } |
54 | |
55 | |
56 /** | |
57 * This function samples a randomized line that contains of x and y values | |
58 * between <i>startX</i>, <i>endX</i>, <i>startY</i> and <i>endY</i>. The | |
59 * number of points in the line is specified by <i>num</i>. | |
60 * | |
61 * @param num The number of points in the line. | |
62 * @param startX The min value of the x values. | |
63 * @param endX The max value of the x values. | |
64 * @param startY The min value of the y values. | |
65 * @param endY The max value of the y values. | |
66 * @return an array with [allX-values, allY-values]. | |
67 * @throws IllegalArgumentException | |
68 */ | |
69 public static double[][] randomizeLine( | |
70 int num, | |
71 double startX, | |
72 double endX, | |
73 double startY, | |
74 double endY | |
75 ) throws IllegalArgumentException | |
76 { | |
77 if (num <= 0) { | |
78 throw new IllegalArgumentException("Parameter 'num' has to be > 0"); | |
79 } | |
80 | |
81 Random random = new Random(); | |
82 | |
83 double[] x = new double[num]; | |
84 double[] y = new double[num]; | |
85 | |
86 for (int i = 0; i < num; i++) { | |
87 double xFac = random.nextDouble(); | |
88 double yFac = random.nextDouble(); | |
89 | |
90 x[i] = startX + xFac * (endX - startX); | |
91 y[i] = startY + yFac * (endY - startY); | |
92 | |
93 logger.debug("Created new point: " + x[i] + "|" + y[i]); | |
94 } | |
95 | |
96 return new double[][] { x, y }; | |
97 } | |
53 | 98 |
54 | 99 |
55 public static StyledXYSeries sampleFunction2D( | 100 public static StyledXYSeries sampleFunction2D( |
56 Function func, | 101 Function func, |
57 Document theme, | 102 Document theme, |