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

Collapse All | Expand All

(-)src/org/eclipse/draw2d/test/Draw2dTestSuite.java (+1 lines)
Lines 49-54 Link Here
49
    addTest(new TestSuite(FigureUtilitiesTest.class));
49
    addTest(new TestSuite(FigureUtilitiesTest.class));
50
    addTest(new TestSuite(RectangleTest.class));
50
    addTest(new TestSuite(RectangleTest.class));
51
//    addTest(new TestSuite(ColorConstantTest.class));
51
//    addTest(new TestSuite(ColorConstantTest.class));
52
    addTest(new TestSuite(RayTest.class));
52
}
53
}
53
54
54
}
55
}
(-)src/org/eclipse/draw2d/test/RayTest.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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
package org.eclipse.draw2d.test;
12
13
import junit.framework.TestCase;
14
15
import org.eclipse.draw2d.geometry.Ray;
16
17
/**
18
 * Ray's tests
19
 * 
20
 * @author aboyko
21
 *
22
 */
23
public class RayTest extends TestCase {
24
25
	/**
26
	 * @see TestCase#setUp()
27
	 */
28
	protected void setUp() throws Exception {
29
		super.setUp();
30
	}
31
32
	/**
33
	 * @see TestCase#tearDown()
34
	 */
35
	protected void tearDown() throws Exception {
36
		super.tearDown();
37
	}
38
39
	public void test_length() {
40
		testLengthValues(3, 4, 5);
41
		testLengthValues(0, Integer.MAX_VALUE, Integer.MAX_VALUE);
42
	}
43
	
44
	private void testLengthValues(int x, int y, double expectedLength) {
45
		Ray ray = new Ray(x, y);
46
		assertEquals(expectedLength, ray.length(), 0);
47
	}
48
}
(-)src/org/eclipse/draw2d/geometry/Ray.java (-2 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 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 96-101 Link Here
96
}
96
}
97
97
98
/**
98
/**
99
 * Calculates the dot product of this Ray with another.
100
 * @param r the Ray used to perform the dot product
101
 * @return The dot product as <code>long</code> to avoid possible integer overflow
102
 * @since 3.4.1
103
 */
104
long dotProductL(Ray r) {
105
	return (long) x * r.x + (long) y * r.y;
106
}
107
108
/**
99
 * @see java.lang.Object#equals(Object)
109
 * @see java.lang.Object#equals(Object)
100
 */
110
 */
101
public boolean equals(Object obj) {
111
public boolean equals(Object obj) {
Lines 160-166 Link Here
160
 * @since 2.0
170
 * @since 2.0
161
 */
171
 */
162
public double length() {
172
public double length() {
163
	return Math.sqrt(dotProduct(this));
173
	return Math.sqrt(dotProductL(this));
164
}
174
}
165
175
166
/**
176
/**

Return to bug 246290