aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/cheok-yin-fung/java/Box.java
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-109/cheok-yin-fung/java/Box.java')
-rw-r--r--challenge-109/cheok-yin-fung/java/Box.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-109/cheok-yin-fung/java/Box.java b/challenge-109/cheok-yin-fung/java/Box.java
new file mode 100644
index 0000000000..4f3b0cdcc6
--- /dev/null
+++ b/challenge-109/cheok-yin-fung/java/Box.java
@@ -0,0 +1,34 @@
+// The Weekly Challenge - 109
+// Task 2 Four Squares(Rectangles) Puzzle
+// Supporting codes
+
+class Box
+{
+ private Point tl, br;
+
+ Box(int x1, int y1, int x2, int y2) {
+ tl = new Point(x1, y1);
+ br = new Point(x2, y2);
+ }
+
+ Box(Point p1, Point p2) {
+ this(p1.x(), p1.y(), p2.x(), p2.y());
+ }
+
+ Point topLeft() {
+ return tl;
+ }
+
+ int height() {
+ return br.x()-tl.x();
+ }
+
+ int width() {
+ return br.y()-tl.y();
+ }
+
+ boolean isEnclosed(Point p) {
+ return p.x() > tl.x() && p.x() < br.x() &&
+ p.y() > tl.y() && p.y() < br.y();
+ }
+}