All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threerings.getdown.util.Rectangle Maven / Gradle / Ivy

There is a newer version: 1.8.7
Show newest version
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2016 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE

package com.threerings.getdown.util;

/**
 * An immutable rectangle.
 */
public class Rectangle
{
    public final int x;
    public final int y;
    public final int width;
    public final int height;

    public Rectangle (int x, int y, int width, int height)
    {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    public Rectangle union (Rectangle other) {
        int x1 = Math.min(x, other.x);
        int x2 = Math.max(x + width, other.x + other.width);
        int y1 = Math.min(y, other.y);
        int y2 = Math.max(y + height, other.y + other.height);
        return new Rectangle(x1, y1, x2 - x1, y2 - y1);
    }

    /** {@inheritDoc} */
    public String toString ()
    {
        return getClass().getName() + "[x=" + x + ", y=" + y +
            ", width=" + width + ", height=" + height + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy