/** * Gets the bounds of the image associated with the given key. * * @param key the image key * @return image bounds as a new Rectangle or {@code null} if the key * could not be found */ public Rectangle getBounds(K key) { Element e = elements.get(key); return e == null ? null : e.getBounds(); }
/** * Gets the enclosing bounds of all images in this set. This is * the union of the individual image bounds. If the set is empty * an empty {@code Rectangle} will be returned. * * @return enclosing bounds for this image set */ public Rectangle getUnionBounds() { Rectangle r = new Rectangle(); for (Element e : elements.values()) { r = r.union(e.getBounds()); } return r; }
/** * Gets the common bounds of images in this set This is the intersection * of the individual iamge bounds. An empty {@code Rectangle} will be * returned if ths set is empty, or if there is no area over which all * images overlap. * * @return common bounds for this image set */ public Rectangle getIntersectionBounds() { Rectangle r = null; for (Element e : elements.values()) { r = (r == null ? e.getBounds() : r.intersection(e.getBounds())); if (r.isEmpty()) { break; } } return r; }
/** * Gets a new iterator based on the bounds of the image with the * specified key value. * * @param referenceImageKey the key of the image to use as the reference * for the iterator * * @return the new iterator * * @throws IllegalArgumentException if this image set is empty or if no * image corresponds to the key value */ public Iterator<K> getIterator(K referenceImageKey) { if (elements.isEmpty()) { throw new IllegalArgumentException("This image set is empty"); } Rectangle bounds = getBounds(referenceImageKey); return getIterator(bounds); }