comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3023:e19ff9086035

Avoid collisions between line labels. flys-artifacts/trunk@4590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 05 Jun 2012 15:03:11 +0000
parents fb07f936b5ad
children 5642a83420f2
comparison
equal deleted inserted replaced
3022:705d2058b682 3023:e19ff9086035
17 17
18 /** 18 /**
19 * True if \param hotspot collides with a Entity in \param entities. 19 * True if \param hotspot collides with a Entity in \param entities.
20 * @param hotspot Shape to compare against other shapes (bounds only). 20 * @param hotspot Shape to compare against other shapes (bounds only).
21 * @param entities entities against which to compare shape. 21 * @param entities entities against which to compare shape.
22 * @param true if a collision (non-zero intersection) exists between 22 * @param exclusiveEntityClass If not null, consider only entities of
23 * given class.
24 * @return true if a collision (non-zero intersection) exists between
23 * shapes. 25 * shapes.
24 */ 26 */
25 public static boolean collides(Shape hotspot, EntityCollection entities) { 27 public static boolean collides(Shape hotspot, EntityCollection entities,
28 Class exclusiveEntityClass) {
26 if (entities == null) return false; 29 if (entities == null) return false;
27 30
28 Rectangle2D hotspotBox = hotspot.getBounds2D(); 31 Rectangle2D hotspotBox = hotspot.getBounds2D();
29 32
30 for (Iterator i = entities.iterator(); i.hasNext(); ) { 33 for (Iterator i = entities.iterator(); i.hasNext(); ) {
31 Object next = i.next(); 34 Object next = i.next();
32 ChartEntity entity = (ChartEntity) next; 35 ChartEntity entity = (ChartEntity) next;
33 if (entity.getArea().intersects(hotspotBox)) { 36 if (exclusiveEntityClass == null
34 // Found collision, early stop. 37 || exclusiveEntityClass.isInstance(entity))
35 return true; 38 {
39 if (entity.getArea().intersects(hotspotBox)) {
40 // Found collision, early stop.
41 return true;
42 }
36 } 43 }
37 } 44 }
38 45
39 return false; 46 return false;
40 } 47 }

http://dive4elements.wald.intevation.org