1 package edu.berkeley.slipway.gui;
3 import com.atmel.fpslic.*;
4 import java.awt.geom.*;
5 import static com.atmel.fpslic.FpslicConstants.*;
9 private double x1, x2, y1, y2;
10 public R(P p1, P p2) { this(p1.x, p1.y, p2.x, p2.y); }
11 public R(double x1, double y1, double x2, double y2) {
18 public double getWidth() { return Math.abs(x2-x1); }
19 public double getHeight() { return Math.abs(y2-y1); }
20 public double minx() { return Math.min(x1, x2); }
21 public double miny() { return Math.min(y1, y2); }
22 public double maxx() { return Math.max(x1, x2); }
23 public double maxy() { return Math.max(y1, y2); }
24 public double cx() { return (x1+x2)/2; }
25 public double cy() { return (y1+y2)/2; }
26 public double width() { return Math.abs(x2-x1); }
27 public double height() { return Math.abs(y2-y1); }
29 public void fill(G g) {
30 g.g.fill(new Rectangle2D.Double(minx(), miny(), width(), height()));
32 public void draw(G g) {
33 g.line(x1, y1, x1, y2);
34 g.line(x1, y2, x2, y2);
35 g.line(x2, y2, x2, y1);
36 g.line(x2, y1, x1, y1);
39 public boolean contains(P p) {
40 return p.x >= minx() && p.x < maxx() && p.y >= miny() && p.y < maxy();
43 public R plus(double minxplus, double minyplus, double maxxplus, double maxyplus) {
44 return new R(minx()+minxplus,
50 public P corner(int dir) {
52 case SW: return new P(minx(), miny());
53 case SE: return new P(maxx(), miny());
54 case NW: return new P(minx(), maxy());
55 case NE: return new P(maxx(), maxy());
56 case NORTH: return new P(cx(), maxy());
57 case SOUTH: return new P(cx(), miny());
58 case WEST: return new P(minx(), cy());
59 case EAST: return new P(maxx(), cy());
64 public boolean within(R r) {
65 return minx() >= r.minx()
68 && maxy() <= r.maxy();