Java Rectangle getAbsoluteRectangle(Rectangle rect)

Here you can find the source of getAbsoluteRectangle(Rectangle rect)

Description

if rectangle has negative width or height, convert to equivalent rectangle with posititve width or height, else don't do anything

License

Open Source License

Parameter

Parameter Description
rect a parameter

Declaration

public static Rectangle getAbsoluteRectangle(Rectangle rect) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {
    /**//from  w  ww .  j av  a  2 s .  co  m
     * if rectangle has negative width or height, convert to equivalent rectangle
     * with posititve width or height, else don't do anything
     * @param rect
     * @return
     */
    public static Rectangle getAbsoluteRectangle(Rectangle rect) {
        if (rect == null)
            return null;

        Rectangle r = new Rectangle(rect);
        // take care of negative width height
        if (r.width < 0) {
            r.width = -r.width;
            r.x = r.x - r.width;
        }
        if (r.height < 0) {
            r.height = -r.height;
            r.y = r.y - r.height;
        }
        // take care of width height that are 0
        if (r.width == 0)
            r.width = 1;
        if (r.height == 0)
            r.height = 1;
        return r;
    }
}

Related

  1. expand(Rectangle rectangle, int expansion)
  2. firstSmallerThanSecond(java.awt.Rectangle first, java.awt.Rectangle second)
  3. flip(Dimension view, Rectangle rect, int direction)
  4. formatRect(Rectangle rc)
  5. formatRectangle(Rectangle rect)
  6. getFrameOrientations(Rectangle parent)
  7. getMaximalRectangle(Rectangle r1, Rectangle r2)
  8. getRect(byte[] data, int i)
  9. getRectangleProperty(Map p, Object key, Rectangle defaultValue)