Mercurial > projects > dwt-linux
annotate dwt/graphics/Rectangle.d @ 364:2bcb17ebe0be default tip
fix: thx torhu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 20:57:46 +0100 |
parents | c0d810de7093 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
4 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
4 | 12 *******************************************************************************/ |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
13 module dwt.graphics.Rectangle; |
4 | 14 |
238 | 15 import dwt.dwthelper.utils; |
16 | |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
17 public import dwt.graphics.Point; |
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
18 public import dwt.internal.SerializableCompatibility; |
4 | 19 |
71 | 20 import dwt.DWT; |
21 import dwt.DWTError; | |
4 | 22 import tango.text.convert.Format; |
23 | |
24 /** | |
25 * Instances of this class represent rectangular areas in an | |
26 * (x, y) coordinate system. The top left corner of the rectangle | |
27 * is specified by its x and y values, and the extent of the | |
28 * rectangle is specified by its width and height. | |
29 * <p> | |
30 * The coordinate space for rectangles and points is considered | |
31 * to have increasing values downward and to the right from its | |
32 * origin making this the normal, computer graphics oriented notion | |
33 * of (x, y) coordinates rather than the strict mathematical one. | |
34 * </p> | |
35 * <p> | |
36 * The hashCode() method in this class uses the values of the public | |
37 * fields to compute the hash value. When storing instances of the | |
38 * class in hashed collections, do not modify these fields after the | |
39 * object has been inserted. | |
40 * </p> | |
41 * <p> | |
42 * Application code does <em>not</em> need to explicitly release the | |
43 * resources managed by each instance when those instances are no longer | |
44 * required, and thus no <code>dispose()</code> method is provided. | |
45 * </p> | |
46 * | |
47 * @see Point | |
259 | 48 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
4 | 49 */ |
50 | |
51 public final class Rectangle : SerializableCompatibility { | |
52 | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
53 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
54 * the x coordinate of the rectangle |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
55 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
56 public int x; |
4 | 57 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
58 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
59 * the y coordinate of the rectangle |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
60 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
61 public int y; |
4 | 62 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
63 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
64 * the width of the rectangle |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
65 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
66 public int width; |
4 | 67 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
68 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
69 * the height of the rectangle |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
70 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
71 public int height; |
4 | 72 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
73 //static final long serialVersionUID = 3256439218279428914L; |
4 | 74 |
75 /** | |
76 * Construct a new instance of this class given the | |
77 * x, y, width and height values. | |
78 * | |
79 * @param x the x coordinate of the origin of the rectangle | |
80 * @param y the y coordinate of the origin of the rectangle | |
81 * @param width the width of the rectangle | |
82 * @param height the height of the rectangle | |
83 */ | |
84 public this (int x, int y, int width, int height) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
85 this.x = x; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
86 this.y = y; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
87 this.width = width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
88 this.height = height; |
4 | 89 } |
90 | |
91 /** | |
92 * Destructively replaces the x, y, width and height values | |
93 * in the receiver with ones which represent the union of the | |
94 * rectangles specified by the receiver and the given rectangle. | |
95 * <p> | |
96 * The union of two rectangles is the smallest single rectangle | |
97 * that completely covers both of the areas covered by the two | |
98 * given rectangles. | |
99 * </p> | |
100 * | |
101 * @param rect the rectangle to merge with the receiver | |
102 * | |
103 * @exception IllegalArgumentException <ul> | |
104 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
105 * </ul> | |
106 */ | |
107 public void add (Rectangle rect) { | |
71 | 108 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
109 int left = x < rect.x ? x : rect.x; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
110 int top = y < rect.y ? y : rect.y; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
111 int lhs = x + width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
112 int rhs = rect.x + rect.width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
113 int right = lhs > rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
114 lhs = y + height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
115 rhs = rect.y + rect.height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
116 int bottom = lhs > rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
117 x = left; y = top; width = right - left; height = bottom - top; |
4 | 118 } |
119 | |
120 /** | |
121 * Returns <code>true</code> if the point specified by the | |
122 * arguments is inside the area specified by the receiver, | |
123 * and <code>false</code> otherwise. | |
124 * | |
125 * @param x the x coordinate of the point to test for containment | |
126 * @param y the y coordinate of the point to test for containment | |
127 * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise | |
128 */ | |
129 public bool contains (int x, int y) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
130 return (x >= this.x) && (y >= this.y) && ((x - this.x) < width) && ((y - this.y) < height); |
4 | 131 } |
132 | |
133 /** | |
134 * Returns <code>true</code> if the given point is inside the | |
135 * area specified by the receiver, and <code>false</code> | |
136 * otherwise. | |
137 * | |
138 * @param pt the point to test for containment | |
139 * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise | |
140 * | |
141 * @exception IllegalArgumentException <ul> | |
142 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
143 * </ul> | |
144 */ | |
145 public bool contains (Point pt) { | |
148
ee9953d47114
some ==/is replacements, thanks torhu for bug report
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
146 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
147 return contains(pt.x, pt.y); |
4 | 148 } |
149 | |
150 /** | |
151 * Compares the argument to the receiver, and returns true | |
152 * if they represent the <em>same</em> object using a class | |
153 * specific comparison. | |
154 * | |
155 * @param object the object to compare with this object | |
156 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
157 * | |
158 * @see #hashCode() | |
159 */ | |
160 public override int opEquals (Object object) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
161 if (object is this) return true; |
4 | 162 if( auto r = cast(Rectangle) object ){ |
148
ee9953d47114
some ==/is replacements, thanks torhu for bug report
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
163 return (r.x is this.x) && (r.y is this.y) && (r.width is this.width) && (r.height is this.height); |
4 | 164 } |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
165 return false; |
4 | 166 } |
167 | |
168 /** | |
169 * Returns an integer hash code for the receiver. Any two | |
170 * objects that return <code>true</code> when passed to | |
171 * <code>equals</code> must return the same value for this | |
172 * method. | |
173 * | |
174 * @return the receiver's hash | |
175 * | |
176 * @see #equals(Object) | |
177 */ | |
178 public override hash_t toHash () { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
179 return x ^ y ^ width ^ height; |
4 | 180 } |
181 | |
182 /** | |
183 * Destructively replaces the x, y, width and height values | |
184 * in the receiver with ones which represent the intersection of the | |
185 * rectangles specified by the receiver and the given rectangle. | |
186 * | |
187 * @param rect the rectangle to intersect with the receiver | |
188 * | |
189 * @exception IllegalArgumentException <ul> | |
190 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
191 * </ul> | |
192 * | |
193 * since 3.0 | |
194 */ | |
195 public void intersect (Rectangle rect) { | |
71 | 196 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
197 if (this is rect) return; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
198 int left = x > rect.x ? x : rect.x; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
199 int top = y > rect.y ? y : rect.y; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
200 int lhs = x + width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
201 int rhs = rect.x + rect.width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
202 int right = lhs < rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
203 lhs = y + height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
204 rhs = rect.y + rect.height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
205 int bottom = lhs < rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
206 x = right < left ? 0 : left; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
207 y = bottom < top ? 0 : top; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
208 width = right < left ? 0 : right - left; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
209 height = bottom < top ? 0 : bottom - top; |
4 | 210 } |
211 | |
212 /** | |
213 * Returns a new rectangle which represents the intersection | |
214 * of the receiver and the given rectangle. | |
215 * <p> | |
216 * The intersection of two rectangles is the rectangle that | |
217 * covers the area which is contained within both rectangles. | |
218 * </p> | |
219 * | |
220 * @param rect the rectangle to intersect with the receiver | |
221 * @return the intersection of the receiver and the argument | |
222 * | |
223 * @exception IllegalArgumentException <ul> | |
224 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
225 * </ul> | |
226 */ | |
227 public Rectangle intersection (Rectangle rect) { | |
71 | 228 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
229 if (this is rect) return new Rectangle (x, y, width, height); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
230 int left = x > rect.x ? x : rect.x; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
231 int top = y > rect.y ? y : rect.y; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
232 int lhs = x + width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
233 int rhs = rect.x + rect.width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
234 int right = lhs < rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
235 lhs = y + height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
236 rhs = rect.y + rect.height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
237 int bottom = lhs < rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
238 return new Rectangle ( |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
239 right < left ? 0 : left, |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
240 bottom < top ? 0 : top, |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
241 right < left ? 0 : right - left, |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
242 bottom < top ? 0 : bottom - top); |
4 | 243 } |
244 | |
245 /** | |
246 * Returns <code>true</code> if the rectangle described by the | |
247 * arguments intersects with the receiver and <code>false</code> | |
248 * otherwise. | |
249 * <p> | |
250 * Two rectangles intersect if the area of the rectangle | |
251 * representing their intersection is not empty. | |
252 * </p> | |
253 * | |
254 * @param x the x coordinate of the origin of the rectangle | |
255 * @param y the y coordinate of the origin of the rectangle | |
256 * @param width the width of the rectangle | |
257 * @param height the height of the rectangle | |
258 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
259 * | |
260 * @exception IllegalArgumentException <ul> | |
261 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
262 * </ul> | |
263 * | |
264 * @see #intersection(Rectangle) | |
265 * @see #isEmpty() | |
266 * | |
267 * @since 3.0 | |
268 */ | |
269 public bool intersects (int x, int y, int width, int height) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
270 return (x < this.x + this.width) && (y < this.y + this.height) && |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
271 (x + width > this.x) && (y + height > this.y); |
4 | 272 } |
273 | |
274 /** | |
275 * Returns <code>true</code> if the given rectangle intersects | |
276 * with the receiver and <code>false</code> otherwise. | |
277 * <p> | |
278 * Two rectangles intersect if the area of the rectangle | |
279 * representing their intersection is not empty. | |
280 * </p> | |
281 * | |
282 * @param rect the rectangle to test for intersection | |
283 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
284 * | |
285 * @exception IllegalArgumentException <ul> | |
286 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
287 * </ul> | |
288 * | |
289 * @see #intersection(Rectangle) | |
290 * @see #isEmpty() | |
291 */ | |
292 public bool intersects (Rectangle rect) { | |
148
ee9953d47114
some ==/is replacements, thanks torhu for bug report
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
293 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
ee9953d47114
some ==/is replacements, thanks torhu for bug report
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
294 return rect is this || intersects (rect.x, rect.y, rect.width, rect.height); |
4 | 295 } |
296 | |
297 /** | |
298 * Returns <code>true</code> if the receiver does not cover any | |
299 * area in the (x, y) coordinate plane, and <code>false</code> if | |
300 * the receiver does cover some area in the plane. | |
301 * <p> | |
302 * A rectangle is considered to <em>cover area</em> in the | |
303 * (x, y) coordinate plane if both its width and height are | |
304 * non-zero. | |
305 * </p> | |
306 * | |
307 * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise | |
308 */ | |
309 public bool isEmpty () { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
310 return (width <= 0) || (height <= 0); |
4 | 311 } |
312 | |
313 /** | |
314 * Returns a string containing a concise, human-readable | |
315 * description of the receiver. | |
316 * | |
317 * @return a string representation of the rectangle | |
318 */ | |
238 | 319 public override String toString () { |
177 | 320 return Format( "Rectangle {{{}, {}, {}, {}}", x, y, width, height ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
4 | 321 } |
322 | |
323 /** | |
324 * Returns a new rectangle which represents the union of | |
325 * the receiver and the given rectangle. | |
326 * <p> | |
327 * The union of two rectangles is the smallest single rectangle | |
328 * that completely covers both of the areas covered by the two | |
329 * given rectangles. | |
330 * </p> | |
331 * | |
332 * @param rect the rectangle to perform union with | |
333 * @return the union of the receiver and the argument | |
334 * | |
335 * @exception IllegalArgumentException <ul> | |
336 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
337 * </ul> | |
338 * | |
339 * @see #add(Rectangle) | |
340 */ | |
341 public Rectangle makeUnion (Rectangle rect) { | |
71 | 342 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
343 int left = x < rect.x ? x : rect.x; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
344 int top = y < rect.y ? y : rect.y; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
345 int lhs = x + width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
346 int rhs = rect.x + rect.width; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
347 int right = lhs > rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
348 lhs = y + height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
349 rhs = rect.y + rect.height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
350 int bottom = lhs > rhs ? lhs : rhs; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
351 return new Rectangle (left, top, right - left, bottom - top); |
4 | 352 } |
353 | |
354 } |