skunkworks/com/danitheskunk/skunkworks/Recti.java

66 lines
1.1 KiB
Java

package com.danitheskunk.skunkworks;
@SuppressWarnings("SpellCheckingInspection")
public final class Recti {
private final Vec2i pos, size;
//constructors
public Recti(int x, int y, int width, int height) {
this(new Vec2i(x, y), new Vec2i(width, height));
}
public Recti(Vec2i pos, Vec2i size) {
this.pos = pos;
this.size = size;
}
public boolean contains(Vec2i vec) {
var br = getBottomRight();
return vec.getX() >= pos.getX() &&
vec.getY() >= pos.getY() &&
vec.getX() < br.getX() &&
vec.getY() < br.getY();
}
public Vec2i getBottomLeft() {
return new Vec2i(pos.getX(), pos.getY() + size.getY());
}
public Vec2i getBottomRight() {
return Vec2i.add(pos, size);
}
public int getHeight() {
return size.getY();
}
//getters
public Vec2i getPos() {
return pos;
}
public Vec2i getSize() {
return size;
}
public Vec2i getTopLeft() {
return pos;
}
public Vec2i getTopRight() {
return new Vec2i(pos.getX() + size.getX(), pos.getY());
}
public int getWidth() {
return size.getX();
}
public int getX() {
return pos.getX();
}
public int getY() {
return pos.getY();
}
}