1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.util.geometry;
16
17
18
19
20
21
22 public class Rectangle2D implements Shape2D {
23 private double left_;
24 private double top_;
25 private double right_;
26 private double bottom_;
27
28
29
30
31
32
33
34
35 public Rectangle2D(final double x1, final double y1, final double x2, final double y2) {
36 if (x1 < x2) {
37 left_ = x1;
38 right_ = x2;
39 }
40 else {
41 left_ = x2;
42 right_ = x1;
43 }
44
45 if (y1 > y2) {
46 top_ = y1;
47 bottom_ = y2;
48 }
49 else {
50 top_ = y2;
51 bottom_ = y1;
52 }
53 }
54
55
56
57
58 public double getLeft() {
59 return left_;
60 }
61
62
63
64
65 public double getBottom() {
66 return bottom_;
67 }
68
69
70
71
72 @Override
73 public boolean contains(final double x, final double y) {
74 return x >= left_
75 && x <= right_
76 && y <= top_
77 && y >= bottom_;
78 }
79
80
81
82
83
84
85
86
87 public void extend(final double x, final double y) {
88 if (x > right_) {
89 right_ = x;
90 }
91 else {
92 if (x < left_) {
93 left_ = x;
94 }
95 }
96
97 if (y > top_) {
98 top_ = y;
99 }
100 else {
101 if (y < bottom_) {
102 bottom_ = y;
103 }
104 }
105 }
106
107
108
109
110 @Override
111 public boolean isEmpty() {
112 return Math.abs(top_ - bottom_) < EPSILON || Math.abs(left_ - right_) < EPSILON;
113 }
114
115 @Override
116 public String toString() {
117 return "Rectangle2D [left_=" + left_ + ", top_=" + top_ + ", right_=" + right_ + ", bottom_=" + bottom_ + "]";
118 }
119 }