/** * Compares the Y-Position of two {@link Region} objects. * @param region1 The first {@link Region} object * @param region2 The second {@link Region} object * @return * <ul> * <li>-1 if the y-position of region1 is smaller</li> * <li>0 if the y-positions are equal</li> * <li>1 if the y-position of region2 is smaller</li> * </ul> */ @Override public int compare(Region region1, Region region2) { if (region1 == region2) { return 0; } if (region1.getY() == region2.getY()) { return 0; } return region1.getY() < region2.getY() ? -1 : 1; }
/** * Compares the distance of two {@link Region} objects. * @param region1 The first {@link Region} object * @param region2 The second {@link Region} object * @return * <ul> * <li>-1 if the distance to region2 is smaller than to region1</li> * <li>0 if the distances are equal</li> * <li>1 if the distance to region1 is smaller than to region2</li> * </ul> */ @Override public int compare(Region region1, Region region2) { if (region1 == region2) { return 0; } double distance1 = Math.sqrt(Math.pow(y - region1.getY(),2) + Math.pow(x - region1.getX(),2)); double distance2 = Math.sqrt(Math.pow(y - region2.getY(),2) + Math.pow(x - region2.getX(),2)); if (distance1 == distance2) { return 0; } return distance1 < distance2 ? -1 : 1; }
/** * create a region above the top side with same width<br> the new region extends to the top screen border<br> use * grow() to include the current region * * @return the new region */ public Region above() { int distToAboveScreenBorder = getY() - getScreen().getY(); return above(distToAboveScreenBorder); }
/** * resets this region to the given region <br> this might move the region even to another screen * <p> * <br>Because of the wanted side effect for the containing screen, this should only be used with screen objects. * <br>For Region objects use setRect() instead. * * @param reg Region */ public void setROI(Region reg) { setROI(reg.getX(), reg.getY(), reg.getW(), reg.getH()); }
/** * @return the center pixel location of the region */ public Location getCenter() { return checkAndSetRemote(new Location(getX() + getW() / 2, getY() + getH() / 2)); }
/** * create a region below the bottom side with same width<br> the new region extends to the bottom screen border<br> * use grow() to include the current region * * @return the new region */ public Region below() { int distToBelowScreenBorder = getScreen().getY() + getScreen().getH() - (getY() + getH()); return below(distToBelowScreenBorder); }