/** * Compares the X-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 x-position of region1 is smaller</li> * <li>0 if the x-positions are equal</li> * <li>1 if the x-position of region2 is smaller</li> * </ul> */ @Override public int compare(Region region1, Region region2) { if (region1 == region2) { return 0; } if (region1.getX() == region2.getX()) { return 0; } return region1.getX() < region2.getX() ? -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 left of the left side with same height<br> the new region extends to the left screen border<br> use * grow() to include the current region * * @return the new region */ public Region left() { int distToLeftScreenBorder = getX() - getScreen().getX(); return left(distToLeftScreenBorder); }
/** * 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 right of the right side with same height. the new region extends to the right screen border<br> * use grow() to include the current region * * @return the new region */ public Region right() { int distToRightScreenBorder = getScreen().getX() + getScreen().getW() - (getX() + getW()); return right(distToRightScreenBorder); }