Tests whether a passed rectangle has valid coordinates, i.e. - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

Tests whether a passed rectangle has valid coordinates, i.e.

Demo Code


//package com.java2s;
import java.awt.geom.*;

public class Main {
    /**/*w w w.  j a v  a2  s  .co  m*/
     * Tests whether a passed rectangle has valid coordinates, i.e. x, y, width
     * and height are not NaN and not infinite.
     * @param rect The rectangle to test. Can be null.
     * @return True if the passed rectangle is valid, false otherwise.
     */
    public static boolean isRectangleValid(Rectangle2D rect) {

        if (rect == null) {
            return false;
        }

        final double x = rect.getX();
        final double y = rect.getY();
        final double w = rect.getWidth();
        final double h = rect.getHeight();
        return !Double.isInfinite(x) && !Double.isNaN(x)
                && !Double.isInfinite(y) && !Double.isNaN(y)
                && !Double.isInfinite(w) && !Double.isNaN(w)
                && !Double.isInfinite(h) && !Double.isNaN(h);

    }
}

Related Tutorials