From bf8cc329cfc882ca791b1d10d97db3061f40d88d Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Wed, 21 May 2014 02:19:10 +0200 Subject: [PATCH] Box: - add Box.overlap(Box) and copy constructor - add Box.inside(box) --- vtm/src/org/oscim/core/Box.java | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/core/Box.java b/vtm/src/org/oscim/core/Box.java index b09f6da7..4d94965c 100644 --- a/vtm/src/org/oscim/core/Box.java +++ b/vtm/src/org/oscim/core/Box.java @@ -55,6 +55,13 @@ public class Box { this.maxY = maxY; } + public Box(Box bbox) { + this.minX = bbox.minX; + this.minY = bbox.minY; + this.maxX = bbox.maxX; + this.maxY = bbox.maxY; + } + /** * Check if Box contains point defined by coordinates x and y. * @@ -68,11 +75,33 @@ public class Box { /** * Check if Box contains Point. - * - * @param p the point - * @return true, if point is inside box. */ public boolean contains(Point p) { return (p.x >= minX && p.x <= maxY && p.y >= minY && p.y <= maxY); } + + /** + * Check if this Box is inside box. + */ + public boolean inside(Box box) { + return minX >= box.minX && maxX <= box.maxX && minY >= box.minY && maxY <= box.maxY; + } + + public double getWidth() { + return maxX - minX; + } + + public double getHeight() { + return maxY - minY; + } + + public boolean overlap(Box other) { + return !(minX > other.maxX || maxX < other.minX || minY > other.maxY || maxY < other.minY); + } + + @Override + public String toString() { + return "[" + minX + ',' + minY + ',' + maxX + ',' + maxY + ']'; + } + }