Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 63ef889eea2b |
children | d8f2ab5b61c3 |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.jfree; | |
2 | |
3 import de.intevation.flys.artifacts.math.Function; | |
4 | |
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 { | |
17 | |
18 /** Do not instantiate. */ | |
19 private JFreeUtil() { | |
20 } | |
21 | |
22 | |
23 /** | |
24 * True if \param hotspot collides with a Entity in \param entities. | |
25 * @param hotspot Shape to compare against other shapes (bounds only). | |
26 * @param entities entities against which to compare shape. | |
27 * @param exclusiveEntityClass If not null, consider only entities of | |
28 * given class. | |
29 * @return true if a collision (non-zero intersection) exists between | |
30 * shapes. | |
31 */ | |
32 public static boolean collides(Shape hotspot, EntityCollection entities, | |
33 Class exclusiveEntityClass) { | |
34 if (entities == null) return false; | |
35 | |
36 Rectangle2D hotspotBox = hotspot.getBounds2D(); | |
37 | |
38 for (Iterator i = entities.iterator(); i.hasNext(); ) { | |
39 Object next = i.next(); | |
40 ChartEntity entity = (ChartEntity) next; | |
41 if (exclusiveEntityClass == null | |
42 || exclusiveEntityClass.isInstance(entity)) | |
43 { | |
44 if (entity.getArea().intersects(hotspotBox)) { | |
45 // Found collision, early stop. | |
46 return true; | |
47 } | |
48 } | |
49 } | |
50 | |
51 return false; | |
52 } | |
53 | |
54 | |
55 public static StyledXYSeries sampleFunction2D( | |
56 Function func, | |
57 Document theme, | |
58 String seriesKey, | |
59 int samples, | |
60 double start, | |
61 double end | |
62 ) { | |
63 StyledXYSeries series = new StyledXYSeries(seriesKey, theme); | |
64 | |
65 double step = (end - start) / (samples - 1); | |
66 | |
67 for (int i = 0; i < samples; i++) { | |
68 double x = start + (step * i); | |
69 series.add(x, func.value(x)); | |
70 } | |
71 | |
72 return series; | |
73 } | |
74 } | |
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |