View | Details | Raw Unified | Return to bug 212460 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/draw2d/geometry/PrecisionPoint.java (-24 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 33-47 Link Here
33
 * @param copy Point from which the initial values are taken
33
 * @param copy Point from which the initial values are taken
34
 */
34
 */
35
public PrecisionPoint(Point copy) {
35
public PrecisionPoint(Point copy) {
36
	if (copy instanceof PrecisionPoint) {
36
	preciseX = copy.preciseX();
37
		PrecisionPoint precPt = (PrecisionPoint)copy;
37
	preciseY = copy.preciseY();
38
		preciseX = precPt.preciseX;
38
	updateInts();
39
		preciseY = precPt.preciseY;
40
		updateInts();
41
	} else {
42
		preciseX = x = copy.x;
43
		preciseY = y = copy.y;
44
	}
45
}
39
}
46
40
47
/**
41
/**
Lines 61-69 Link Here
61
 * @param y Y value
55
 * @param y Y value
62
 */
56
 */
63
public PrecisionPoint(double x, double y) {
57
public PrecisionPoint(double x, double y) {
64
	super(x, y);
65
	preciseX = x;
58
	preciseX = x;
66
	preciseY = y;
59
	preciseY = y;
60
	updateInts();
67
}
61
}
68
62
69
/**
63
/**
Lines 80-87 Link Here
80
public void performScale(double factor) {
74
public void performScale(double factor) {
81
	preciseX = preciseX * factor;
75
	preciseX = preciseX * factor;
82
	preciseY = preciseY * factor;
76
	preciseY = preciseY * factor;
83
	x = (int)Math.floor(preciseX + 0.000000001);
77
	updateInts();
84
	y = (int)Math.floor(preciseY + 0.000000001);	
85
}
78
}
86
79
87
/**
80
/**
Lines 90-112 Link Here
90
public void performTranslate(int dx, int dy) {
83
public void performTranslate(int dx, int dy) {
91
	preciseX += dx;
84
	preciseX += dx;
92
	preciseY += dy;
85
	preciseY += dy;
93
	x = (int)Math.floor(preciseX + 0.000000001);
86
	updateInts();
94
	y = (int)Math.floor(preciseY + 0.000000001);
95
}
87
}
96
88
97
/**
89
/**
98
 * @see org.eclipse.draw2d.geometry.Point#setLocation(Point)
90
 * @see org.eclipse.draw2d.geometry.Point#setLocation(Point)
99
 */
91
 */
100
public Point setLocation(Point pt) {
92
public Point setLocation(Point pt) {
101
	if (pt instanceof PrecisionPoint) {
93
	preciseX = pt.preciseX();
102
		preciseX = ((PrecisionPoint)pt).preciseX;
94
	preciseY = pt.preciseY();
103
		preciseY = ((PrecisionPoint)pt).preciseY;
95
	updateInts();
104
	} else {
105
		preciseX = pt.x;
106
		preciseY = pt.y;
107
	}
108
	x = (int)Math.floor(preciseX + 0.000000001);
109
	y = (int)Math.floor(preciseY + 0.000000001);
110
	return this;
96
	return this;
111
}
97
}
112
98
Lines 118-121 Link Here
118
	y = (int)Math.floor(preciseY + 0.000000001);
104
	y = (int)Math.floor(preciseY + 0.000000001);
119
}
105
}
120
106
107
double preciseX() {
108
	return preciseX;
109
}
110
111
double preciseY() {
112
	return preciseY;
113
}
114
121
}
115
}
(-)src/org/eclipse/draw2d/geometry/Rectangle.java (-3 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 882-888 Link Here
882
 * @param p  Point to be unioned with this Rectangle
882
 * @param p  Point to be unioned with this Rectangle
883
 * @since 2.0
883
 * @since 2.0
884
 */
884
 */
885
public final void union(Point p) {
885
public void union(Point p) {
886
	union(p.x, p.y);
886
	union(p.x, p.y);
887
}
887
}
888
888
Lines 894-900 Link Here
894
 * @param rect  Rectangle to be unioned with this Rectangle
894
 * @param rect  Rectangle to be unioned with this Rectangle
895
 * @since 2.0
895
 * @since 2.0
896
 */
896
 */
897
public final Rectangle union(Rectangle rect) {
897
public Rectangle union(Rectangle rect) {
898
	if (rect == null)
898
	if (rect == null)
899
		return this;
899
		return this;
900
	return union(rect.x, rect.y, rect.width, rect.height);
900
	return union(rect.x, rect.y, rect.width, rect.height);
Lines 921-924 Link Here
921
	return this;
921
	return this;
922
}
922
}
923
923
924
double preciseX() {
925
	return x;
926
}
927
928
double preciseY() {
929
	return y;
930
}
931
932
double preciseWidth() {
933
	return width;
934
}
935
936
double preciseHeight() {
937
	return height;
938
}
939
924
}
940
}
(-)src/org/eclipse/draw2d/geometry/PrecisionDimension.java (-4 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
2
 * Copyright (c) 2003, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 47-55 Link Here
47
 * @param d the reference dimension
47
 * @param d the reference dimension
48
 */
48
 */
49
public PrecisionDimension(Dimension d) {
49
public PrecisionDimension(Dimension d) {
50
	super(d);
50
	preciseHeight = d.preciseHeight();
51
	preciseHeight = d.height;
51
	preciseWidth = d.preciseWidth();
52
	preciseWidth = d.width;
52
	updateInts();
53
}
53
}
54
54
55
/**
55
/**
Lines 69-72 Link Here
69
	height = (int)Math.floor(preciseHeight + 0.000000001);	
69
	height = (int)Math.floor(preciseHeight + 0.000000001);	
70
}
70
}
71
71
72
double preciseWidth() {
73
	return preciseWidth;
74
}
75
76
double preciseHeight() {
77
	return preciseHeight;
78
}
79
72
}
80
}
(-)src/org/eclipse/draw2d/geometry/Dimension.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 435-438 Link Here
435
	return this;
435
	return this;
436
}
436
}
437
437
438
double preciseWidth() {
439
	return width;
440
}
441
442
double preciseHeight() {
443
	return height;
444
}
445
438
}
446
}
(-)src/org/eclipse/draw2d/geometry/Point.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 395-398 Link Here
395
	return this;
395
	return this;
396
}
396
}
397
397
398
double preciseX() {
399
	return x;
400
}
401
402
double preciseY() {
403
	return y;
404
}
405
398
}
406
}
(-)src/org/eclipse/draw2d/geometry/PrecisionRectangle.java (-29 / +150 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
2
 * Copyright (c) 2003, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.draw2d.geometry;
11
package org.eclipse.draw2d.geometry;
12
12
13
13
/**
14
/**
14
 * A Rectangle implementation using floating point values which are truncated into the inherited
15
 * A Rectangle implementation using floating point values which are truncated into the inherited
15
 * integer fields. The use of floating point prevents rounding errors from accumulating.
16
 * integer fields. The use of floating point prevents rounding errors from accumulating.
Lines 40-57 Link Here
40
 * @param rect the base rectangle
41
 * @param rect the base rectangle
41
 */
42
 */
42
public PrecisionRectangle(Rectangle rect) {
43
public PrecisionRectangle(Rectangle rect) {
43
	if (rect instanceof PrecisionRectangle) {
44
	preciseX = rect.preciseX();
44
		PrecisionRectangle rectangle = (PrecisionRectangle)rect;
45
	preciseY = rect.preciseY();
45
		preciseX = rectangle.preciseX;
46
	preciseWidth = rect.preciseWidth();
46
		preciseY = rectangle.preciseY;
47
	preciseHeight = rect.preciseHeight();
47
		preciseWidth = rectangle.preciseWidth;
48
		preciseHeight = rectangle.preciseHeight;
49
	} else {
50
		preciseX = rect.x;
51
		preciseY = rect.y;
52
		preciseWidth = rect.width;
53
		preciseHeight = rect.height;
54
	}
55
	updateInts();
48
	updateInts();
56
}
49
}
57
50
Lines 148-161 Link Here
148
 * @see org.eclipse.draw2d.geometry.Rectangle#resize(org.eclipse.draw2d.geometry.Dimension)
141
 * @see org.eclipse.draw2d.geometry.Rectangle#resize(org.eclipse.draw2d.geometry.Dimension)
149
 */
142
 */
150
public Rectangle resize(Dimension sizeDelta) {
143
public Rectangle resize(Dimension sizeDelta) {
151
	if (sizeDelta instanceof PrecisionDimension) {
144
	preciseWidth += sizeDelta.preciseWidth();
152
		PrecisionDimension pd = (PrecisionDimension)sizeDelta;
145
	preciseHeight += sizeDelta.preciseHeight();
153
		preciseWidth += pd.preciseWidth;
154
		preciseHeight += pd.preciseHeight;
155
	} else {
156
		preciseWidth += sizeDelta.width;
157
		preciseHeight += sizeDelta.height;
158
	}
159
	updateInts();
146
	updateInts();
160
	return this;
147
	return this;
161
}
148
}
Lines 200-213 Link Here
200
 * @see org.eclipse.draw2d.geometry.Rectangle#translate(org.eclipse.draw2d.geometry.Point)
187
 * @see org.eclipse.draw2d.geometry.Rectangle#translate(org.eclipse.draw2d.geometry.Point)
201
 */
188
 */
202
public Rectangle translate(Point p) {
189
public Rectangle translate(Point p) {
203
	if (p instanceof PrecisionPoint) {
190
	preciseX += p.preciseX();
204
		PrecisionPoint pp = (PrecisionPoint)p;
191
	preciseY += p.preciseY();
205
		preciseX += pp.preciseX;
206
		preciseY += pp.preciseY;
207
	} else {
208
		preciseX += p.x;
209
		preciseY += p.y;
210
	}
211
	updateInts();
192
	updateInts();
212
	return this;
193
	return this;
213
}
194
}
Lines 218-223 Link Here
218
 * @since 3.0
199
 * @since 3.0
219
 * @param other the rectangle being unioned
200
 * @param other the rectangle being unioned
220
 * @return <code>this</code> for convenience
201
 * @return <code>this</code> for convenience
202
 * @deprecated
203
 * Use {@link #union(Rectangle)} instead
221
 */
204
 */
222
public PrecisionRectangle union(PrecisionRectangle other) {
205
public PrecisionRectangle union(PrecisionRectangle other) {
223
	double newright = Math.max(preciseRight(), other.preciseRight());
206
	double newright = Math.max(preciseRight(), other.preciseRight());
Lines 232-237 Link Here
232
}
215
}
233
216
234
/**
217
/**
218
 * @see org.eclipse.draw2d.geometry.Rectangle#union(org.eclipse.draw2d.geometry.Rectangle)
219
 */
220
public Rectangle union(Rectangle other) {
221
	double newright = Math.max(preciseRight(), other.preciseX() + other.preciseWidth());
222
	double newbottom = Math.max(preciseBottom(), other.preciseY() + other.preciseHeight());
223
	preciseX = Math.min(preciseX, other.preciseX());
224
	preciseY = Math.min(preciseY, other.preciseY());
225
	preciseWidth = newright - preciseX;
226
	preciseHeight = newbottom - preciseY;
227
	updateInts();
228
	
229
	return this;
230
}
231
232
/**
235
 * Updates the integer values based on the current precise values.  The integer values ar
233
 * Updates the integer values based on the current precise values.  The integer values ar
236
 * the floor of the double values.  This is called automatically when calling api which is
234
 * the floor of the double values.  This is called automatically when calling api which is
237
 * overridden in this class.
235
 * overridden in this class.
Lines 244-247 Link Here
244
	height = (int)Math.floor(preciseHeight + preciseY + 0.000000001) - y;
242
	height = (int)Math.floor(preciseHeight + preciseY + 0.000000001) - y;
245
}
243
}
246
244
245
/**
246
 * @see org.eclipse.draw2d.geometry.Rectangle#union(org.eclipse.draw2d.geometry.Point)
247
 */
248
public void union(Point p) {
249
	if (p.preciseX() < preciseX) {
250
		preciseWidth += (preciseX - p.preciseX());
251
		preciseX = p.preciseX();
252
	} else {
253
		double right = preciseX + preciseWidth;
254
		if (p.preciseX() > right) {
255
			preciseWidth = p.preciseX() - preciseX;
256
		}
257
	}
258
	if (p.preciseY() < preciseY) {
259
		preciseHeight += (preciseY - p.preciseY());
260
		preciseY = p.preciseY();
261
	} else {
262
		double bottom = preciseY + preciseHeight;
263
		if (p.preciseY() > bottom) {
264
			preciseHeight = p.preciseY() - preciseY;
265
		}
266
	}
267
	updateInts();
268
}
269
270
/**
271
 * @see org.eclipse.draw2d.geometry.Rectangle#transpose()
272
 */
273
public Rectangle transpose() {
274
	double temp = preciseX;
275
	preciseX = preciseY;
276
	preciseY = temp;
277
	temp = preciseWidth;
278
	preciseWidth = preciseHeight;
279
	preciseHeight = temp;
280
	super.transpose();
281
	return this;
282
}
283
284
/**
285
 * @see org.eclipse.draw2d.geometry.Rectangle#setLocation(org.eclipse.draw2d.geometry.Point)
286
 */
287
public Rectangle setLocation(Point loc) {
288
	preciseX = loc.preciseX();
289
	preciseY = loc.preciseY();
290
	updateInts();
291
	return this;
292
}
293
294
/**
295
 * Returns the precise geometric centre of the rectangle
296
 * 
297
 * @return <code>PrecisionPoint</code> geometric center of the rectangle
298
 * @since 3.4
299
 */
300
public PrecisionPoint getPreciseCenter() {
301
	return new PrecisionPoint(preciseX + preciseWidth / 2.0, preciseY + preciseHeight / 2.0);
302
}
303
304
/**
305
 * Shrinks the sides of this Rectangle by the horizontal and vertical values 
306
 * provided as input, and returns this Rectangle for convenience. The center of 
307
 * this Rectangle is kept constant.
308
 *
309
 * @param h  Horizontal reduction amount
310
 * @param v  Vertical reduction amount
311
 * @return  <code>this</code> for convenience
312
 * @since 3.4
313
 */
314
public Rectangle shrink(double h, double v) {
315
	preciseX += h; 
316
	preciseWidth -= (h + h);
317
	preciseY += v; 
318
	preciseHeight -= (v + v);
319
	updateInts();
320
	return this;
321
}
322
323
/**
324
 * Expands the horizontal and vertical sides of this Rectangle with the values 
325
 * provided as input, and returns this for convenience. The location of its 
326
 * center is kept constant.
327
 * 
328
 * @param h  Horizontal increment
329
 * @param v  Vertical increment
330
 * @return  <code>this</code> for convenience
331
 * @since 3.4
332
 */
333
public Rectangle expand(double h, double v) {
334
	return shrink(-h, -v);
335
}
336
337
/**
338
 * @see org.eclipse.draw2d.geometry.Rectangle#shrink(int, int)
339
 */
340
public Rectangle shrink(int h, int v) {
341
	return shrink((double)h, (double)v);
342
}
343
344
/**
345
 * @see org.eclipse.draw2d.geometry.Rectangle#contains(org.eclipse.draw2d.geometry.Point)
346
 */
347
public boolean contains(Point p) {
348
	return preciseX <= p.preciseX() && p.preciseX() <= preciseX + preciseWidth
349
	&& preciseY <= p.preciseY() && p.preciseY() <= preciseY + preciseHeight;
350
}
351
352
double preciseX() {
353
	return preciseX;
354
}
355
356
double preciseY() {
357
	return preciseY;
358
}
359
360
double preciseWidth() {
361
	return preciseWidth;
362
}
363
364
double preciseHeight() {
365
	return preciseHeight;
366
}
367
247
}
368
}

Return to bug 212460