Skip to content

Instantly share code, notes, and snippets.

@themisir
Last active September 12, 2018 19:11
Show Gist options
  • Save themisir/734677b4ac80f9f030776fa1fd316ea0 to your computer and use it in GitHub Desktop.
Save themisir/734677b4ac80f9f030776fa1fd316ea0 to your computer and use it in GitHub Desktop.
class Rectangle {
public float x;
public float y;
public float width;
public float height;
public float left() {
return this.x;
}
public float top() {
return this.y;
}
public float right() {
return this.x + this.width;
}
public float bottom() {
return this.y + this.height;
}
public boolean contains(float x, float y) {
return x >= left() && x <= right() && y >= top() && y <= bottom();
}
public void set(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rectangle(float x, float y, float width, float height) {
this.set(x, y, width, height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment