sdr 0.7

net.cscott.sdr.util
Class Box

java.lang.Object
  extended by net.cscott.sdr.util.Box

public class Box
extends Object

An orthogonal box, with sides parallel to the x and y axes.


Field Summary
 Point ll
           
 Point ur
           
 
Constructor Summary
Box(Point ll, Point ur)
          Basic constructor.
 
Method Summary
 Point center()
          Returns the center of the box.
 boolean equals(Object o)
           
 int hashCode()
           
 Fraction height()
           
 boolean includes(Point p)
          Returns true iff the given point in inside this box.
 boolean overlaps(Box b)
          Returns true iff this box overlaps the given one.
 String toString()
           
 Fraction width()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ll

public final Point ll

ur

public final Point ur
Constructor Detail

Box

public Box(Point ll,
           Point ur)
Basic constructor.

Parameters:
ll - Lower-left corner (minimum x, minimum y)
ur - Upper-right corner (maximum x, maximum y)
Method Detail

height

public Fraction height()

width

public Fraction width()

center

public Point center()
Returns the center of the box.

Tests:
js> function f(i) { return Fraction.valueOf(i); }
js> new Box(new Point(f(-1),f(-1)), new Point(f(1),f(1))).center();
0,0
js> new Box(new Point(f(0),f(0)), new Point(f(3),f(4))).center();
1 1/2,2

overlaps

public boolean overlaps(Box b)
Returns true iff this box overlaps the given one.

Tests:
js> function f(i) { return Fraction.valueOf(i); }
js> b1 = new Box(new Point(f(-1),f(-1)), new Point(f(1),f(1)));
(-1,-1;1,1)
js> b2 = new Box(new Point(f(0),f(0)), new Point(f(3),f(3)));
(0,0;3,3)
js> b3 = new Box(new Point(f(-2),f(-2)), new Point(f(0),f(0)));
(-2,-2;0,0)
js> b4 = new Box(new Point(f(1),f(4)), new Point(f(2),f(4)));
(1,4;2,4)
js> b1.overlaps(b2)
true
js> b1.overlaps(b2) == b2.overlaps(b1)
true
js> b1.overlaps(b3)
true
js> b1.overlaps(b3) == b3.overlaps(b1)
true
js> b2.overlaps(b4)
false
js> b2.overlaps(b4) == b4.overlaps(b2)
true
js> b2.overlaps(b3)
false
js> b2.overlaps(b3) == b3.overlaps(b2)
true
js> function f(i) { return Fraction.valueOf(i); }
js> b1 = new Box(new Point(f(-4),f(0)), new Point(f(0),f(2)));
(-4,0;0,2)
js> b2 = new Box(new Point(f(-4),f(-2)), new Point(f(0),f(0)));
(-4,-2;0,0)
js> b1.overlaps(b2)
false
js> b2.overlaps(b1)
false

includes

public boolean includes(Point p)
Returns true iff the given point in inside this box. The edges count as "inside".

Tests:
js> function f(i) { return Fraction.valueOf(i); }
js> b = new Box(new Point(f(-1),f(-1)), new Point(f(1),f(1)));
(-1,-1;1,1)
js> b.includes(new Point(f(0),f(0)))
true
js> b.includes(b.ll)
true
js> b.includes(b.ur)
true
js> b.includes(new Point(f(-1),f(1)))
true
js> b.includes(new Point(f(1),f(-1)))
true
js> b.includes(new Point(f(-2),f(0)))
false
js> b.includes(new Point(f(0),f(2)))
false

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian