Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TODO: finish documentaion
- //TODO: remove
- package Mavo2020.Playground;
- /**
- * Represent a point
- */
- public class Point {
- private double _x;
- private double _y;
- /**
- * Constructor
- * @param x the x axis value
- * @param y the y axis value
- */
- public Point(double x, double y) {
- this._x = x;
- this._y = y;
- }
- /**
- * Copy constructor
- * @param other the other Point object to copy from
- */
- public Point(Point other) {
- this._x = other._x;
- this._y = other._y;
- }
- public double getX() {
- return this._x;
- }
- public double getY() {
- return this._y;
- }
- public void setX(double x) {
- this._x = x;
- }
- public void setY(double y) {
- this._y = y;
- }
- public String toString() {
- return "(" + this._x + "," + this._y + ")";
- }
- public boolean equals(Point other) {
- return this._x == other._x && this._y == other._y;
- }
- public boolean isAbove(Point other) {
- return this._y != other.getY() && this._y > other.getY();
- }
- public boolean isUnder(Point other) {
- return !this.isAbove(other);
- }
- public boolean isLeft(Point other) {
- return this._x != other.getX() && this._x < other.getX();
- }
- public boolean isRight(Point other) {
- return !this.isLeft(other);
- }
- public double distance(Point p) {
- return Math.sqrt(Math.pow(this._y - p.getY(), 2) + Math.pow(this._x - p.getX(), 2));
- }
- public void move(double dx, double dy) {
- this._x = this._x + dx;
- this._y = this._y + dy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement