Android Open Source - YOGOSec Rectanglei






From Project

Back to project page YOGOSec.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project YOGOSec listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package YOGOSec.core.util;
/*from   w  ww . j a v  a  2s  .  co m*/
/**
 * @author Aritz Lopez
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 */
public class Rectanglei implements Rectangle<Integer> {

    private final int x, y;
    private final int width, height;

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

    public Rectanglei(Point2i p1, Point2i p2) {
        this.x = p1.getX();
        this.y = p1.getY();
        this.width = p2.getX() - p1.getX();
        this.height = p2.getY() - p1.getY();
    }

    @Override
    public Rectanglei setSize(Integer width, Integer height) {
        return new Rectanglei(this.x, this.y, width, height);
    }

    @Override
    public Rectanglei setPos(Integer x, Integer y) {
        return new Rectanglei(x, y, this.width, this.height);
    }

    public Rectanglei translate(int dx, int dy) {
        return new Rectanglei(this.x + dx, this.y + dy, this.width, this.height);
    }

    public Rectanglei scale(float sc, float sy) {
        return new Rectanglei(this.x, this.y, (int) (this.width * sc), (int) (this.height * sy));
    }

    @Override
    public boolean contains(Point<? extends Number> point) {
        return this.contains(point, false);
    }

    @Override
    public boolean contains(Point<? extends Number> point, boolean yUp) {
        return this.contains(point.getX().intValue(), point.getY().intValue(), yUp);
    }

    public boolean contains(int x, int y) {
        return this.contains(x, y, false);
    }

    public boolean contains(int x, int y, boolean yUp) {
        return (!yUp && this.x >= x && this.y >= y && this.x + this.width <= x && this.y + this.height <= y) ||
                this.x >= x && this.y >= y && this.x + this.width <= x && this.y - this.height <= y;
    }

    @Override
    public Integer getX() {
        return x;
    }

    @Override
    public Integer getY() {
        return y;
    }

    @Override
    public Integer getWidth() {
        return width;
    }

    @Override
    public Integer getHeight() {
        return height;
    }

    @Override
    public Rectanglei setX(Integer x) {
        return new Rectanglei(x, this.y, this.width, this.height);
    }

    @Override
    public Rectanglei setY(Integer y) {
        return new Rectanglei(this.x, y, this.width, this.height);
    }

    @Override
    public Rectanglei setWidth(Integer width) {
        return new Rectanglei(this.x, this.y, width, this.height);
    }

    @Override
    public Rectanglei setHeight(Integer height) {
        return new Rectanglei(this.x, this.y, this.width, height);
    }


    @Override
    public String toString() {
        return "(" + this.x + ", " + this.width + ") " + this.width + "x" + this.height;
    }
}




Java Source Code List

YOGOSec.android.GameActivity.java
YOGOSec.core.Game.java
YOGOSec.core.gui.Button.java
YOGOSec.core.gui.GUIComponent.java
YOGOSec.core.gui.GUI.java
YOGOSec.core.gui.IActionListener.java
YOGOSec.core.gui.InputListener.java
YOGOSec.core.gui.ProgressBar.java
YOGOSec.core.input.Input.java
YOGOSec.core.render.Render.java
YOGOSec.core.render.YUpPixmap.java
YOGOSec.core.screens.MainMenuScreen.java
YOGOSec.core.screens.MyScreen.java
YOGOSec.core.util.Point2f.java
YOGOSec.core.util.Point2i.java
YOGOSec.core.util.Point.java
YOGOSec.core.util.Rectangle.java
YOGOSec.core.util.Rectanglef.java
YOGOSec.core.util.Rectanglei.java
YOGOSec.java.GameDesktop.java