Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 140056 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/draw2d/geometry/Rectangle.java (-2 / +4 lines)
Lines 95-102 Link Here
95
 * @since 2.0
95
 * @since 2.0
96
 */
96
 */
97
public Rectangle(Point p1, Point p2) {
97
public Rectangle(Point p1, Point p2) {
98
	setLocation(p1);
98
	this.x = Math.min(p1.x, p2.x);
99
	union(p2);
99
	this.y = Math.min(p1.y, p2.y);
100
	this.width = Math.abs(p2.x - p1.x) + 1;
101
	this.height = Math.abs(p2.y - p1.y) + 1;
100
}
102
}
101
103
102
/**
104
/**
(-)src/org/eclipse/draw2d/test/Draw2dTestSuite.java (+1 lines)
Lines 45-50 Link Here
45
    addTest(new TestSuite(PrecisionRectangleTest.class));
45
    addTest(new TestSuite(PrecisionRectangleTest.class));
46
    addTest(new TestSuite(ThumbnailTest.class));
46
    addTest(new TestSuite(ThumbnailTest.class));
47
    addTest(new TestSuite(FigureUtilitiesTest.class));
47
    addTest(new TestSuite(FigureUtilitiesTest.class));
48
    addTest(new TestSuite(RectangleTest.class));
48
//    addTest(new TestSuite(ColorConstantTest.class));
49
//    addTest(new TestSuite(ColorConstantTest.class));
49
}
50
}
50
51
(-)src/org/eclipse/draw2d/test/RectangleTest.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
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
10
 *******************************************************************************/
11
12
package org.eclipse.draw2d.test;
13
14
import junit.framework.TestCase;
15
16
import org.eclipse.draw2d.geometry.Point;
17
import org.eclipse.draw2d.geometry.Rectangle;
18
19
public class RectangleTest extends TestCase {
20
	/**
21
	 * @see TestCase#setUp()
22
	 */
23
	protected void setUp() throws Exception {
24
		super.setUp();
25
	}
26
27
	/**
28
	 * @see TestCase#tearDown()
29
	 */
30
	protected void tearDown() throws Exception {
31
		super.tearDown();
32
	}
33
34
	public void test_creationSymmetry() {
35
		Point topLeft = new Point(0, 0);
36
		Point topRight = new Point(10, 0);
37
		Point bottomLeft = new Point(0, 10);
38
		Point bottomRight = new Point(10, 10);
39
		Rectangle rect1 = new Rectangle(topLeft, bottomRight);
40
		Rectangle rect2 = new Rectangle(topRight, bottomLeft);
41
42
		assertTrue(rect1.equals(rect2));
43
	}
44
45
	public void test_creationValues() {
46
47
		final Rectangle testRect = new Rectangle(10, 10, 10, 10);
48
49
		Point topLeft = new Point(10, 10);
50
		Point topRight = new Point(19, 10);
51
		Point bottomLeft = new Point(10, 19);
52
		Point bottomRight = new Point(19, 19);
53
		Rectangle rect1 = new Rectangle(topLeft, bottomRight);
54
		Rectangle rect2 = new Rectangle(topRight, bottomLeft);
55
56
		assertTrue(rect1.equals(testRect));
57
		assertTrue(rect2.equals(testRect));
58
	}
59
	
60
	public void test_sameBehavior() {
61
		
62
		Point p1 = new Point(0,0);
63
		Point p2 = new Point(10, 10);
64
		Rectangle origRect = new Rectangle();
65
		origRect.setLocation(p1);
66
		origRect.union(p2);
67
		
68
		Rectangle newRect = new Rectangle(p1, p2);
69
		
70
		assertTrue(origRect.equals(newRect));
71
	}
72
73
}

Return to bug 140056