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(double x1, double y1, double x2, double y2) {
17 public double getWidth() { return Math.abs(x2-x1); }
18 public double getHeight() { return Math.abs(y2-y1); }
19 public double minx() { return Math.min(x1, x2); }
20 public double miny() { return Math.min(y1, y2); }
21 public double maxx() { return Math.max(x1, x2); }
22 public double maxy() { return Math.max(y1, y2); }
23 public double cx() { return (x1+x2)/2; }
24 public double cy() { return (y1+y2)/2; }
25 public double width() { return Math.abs(x2-x1); }
26 public double height() { return Math.abs(y2-y1); }
28 public void fill(G g) {
29 g.g.fill(new Rectangle2D.Double(minx(), miny(), width(), height()));
31 public void draw(G g) {
32 g.line(x1, y1, x1, y2);
33 g.line(x1, y2, x2, y2);
34 g.line(x2, y2, x2, y1);
35 g.line(x2, y1, x1, y1);
38 public boolean contains(P p) {
39 return p.x >= minx() && p.x < maxx() && p.y >= miny() && p.y < maxy();
42 public R plus(double minxplus, double minyplus, double maxxplus, double maxyplus) {
43 return new R(minx()+minxplus,
49 public P corner(int dir) {
51 case SW: return new P(minx(), miny());
52 case SE: return new P(maxx(), miny());
53 case NW: return new P(minx(), maxy());
54 case NE: return new P(maxx(), maxy());
55 case NORTH: return new P(cx(), maxy());
56 case SOUTH: return new P(cx(), miny());
57 case WEST: return new P(minx(), cy());
58 case EAST: return new P(maxx(), cy());