Skip to content

Commit

Permalink
#11: added method for overlapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
romankh3 committed Mar 15, 2019
1 parent a4554e1 commit 440db37
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/main/java/ua/comparison/image/model/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ua.comparison.image.model;

/**
* Object contained data of the (x,y) point.
*/
public class Point {

/**
* X coordinate for point.
*/
private int x;

/**
* Y coordinate for point.
*/
private int y;

public Point(int x, int y) {
this.x = x;
this.y = y;
}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Point point = (Point) o;

if (x != point.x) {
return false;
}
return y == point.y;
}

@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}
14 changes: 14 additions & 0 deletions src/main/java/ua/comparison/image/model/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ public class Rectangle {
private int maxX = Integer.MIN_VALUE;
private int maxY = Integer.MIN_VALUE;

//todo Move all code to use {@link Point}.
private Point bottomLeft = new Point(maxX, maxY);
private Point topRight = new Point(minX, minY);

public boolean isOverlapping(Rectangle other) {
if (this.topRight.getY() < other.bottomLeft.getY() || this.bottomLeft.getY() > other.topRight.getY()) {
return false;
}
if (this.topRight.getX() < other.bottomLeft.getX() || this.bottomLeft.getX() > other.topRight.getX()) {
return false;
}
return true;
}

/**
* Module of the vector from the start of the matrix to point of the
* beginning {@link Rectangle} object.
Expand Down

0 comments on commit 440db37

Please sign in to comment.