AI2 Component  (Version nb184)
BoundingBox.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime.util;
8 
13 public final class BoundingBox {
14  private double left;
15  private double top;
16  private double right;
17  private double bottom;
18 
27  public BoundingBox(double l, double t, double r, double b) {
28  left = l;
29  top = t;
30  right = r;
31  bottom = b;
32  }
33 
43  public boolean intersectDestructively(BoundingBox bb) {
44  // Determine intersection.
45  double xmin = Math.max(left, bb.left);
46  double xmax = Math.min(right, bb.right);
47  double ymin = Math.max(top, bb.top);
48  double ymax = Math.min(bottom, bb.bottom);
49 
50  // If there is no intersection, return false.
51  if (xmin > xmax || ymin > ymax) {
52  return false;
53  }
54 
55  // Mutate this bounding box to be the intersection before returning true.
56  left = xmin;
57  right = xmax;
58  top = ymin;
59  bottom = ymax;
60  return true;
61 
62  }
63 
69  public double getLeft() {
70  return left;
71  }
72 
78  public double getTop() {
79  return top;
80  }
81 
87  public double getRight() {
88  return right;
89  }
90 
96  public double getBottom() {
97  return bottom;
98  }
99 
100  public String toString() {
101  return "<BoundingBox (left = " + left + ", top = " + top +
102  ", right = " + right + ", bottom = " + bottom + ">";
103  }
104 }
com.google.appinventor.components.runtime.util.BoundingBox.getTop
double getTop()
Definition: BoundingBox.java:78
com.google.appinventor.components.runtime.util.BoundingBox
Definition: BoundingBox.java:13
com.google.appinventor.components.runtime.util.BoundingBox.getBottom
double getBottom()
Definition: BoundingBox.java:96
com.google.appinventor.components.runtime.util.BoundingBox.getLeft
double getLeft()
Definition: BoundingBox.java:69
com.google.appinventor.components.runtime.util.BoundingBox.intersectDestructively
boolean intersectDestructively(BoundingBox bb)
Definition: BoundingBox.java:43
com.google.appinventor.components.runtime.util.BoundingBox.getRight
double getRight()
Definition: BoundingBox.java:87
com.google.appinventor.components.runtime.util.BoundingBox.toString
String toString()
Definition: BoundingBox.java:100
com.google.appinventor.components.runtime.util.BoundingBox.BoundingBox
BoundingBox(double l, double t, double r, double b)
Definition: BoundingBox.java:27