source: josm/trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java@ 9504

Last change on this file since 9504 was 8876, checked in by Don-vip, 9 years ago

cleanup unit tests

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import org.junit.Assert;
5import org.junit.BeforeClass;
6import org.junit.Test;
7import org.openstreetmap.josm.JOSMFixture;
8import org.openstreetmap.josm.data.coor.EastNorth;
9
10/**
11 * Unit tests of {@link Geometry} class.
12 */
13public class GeometryTest {
14
15 /**
16 * Setup test.
17 */
18 @BeforeClass
19 public static void setUp() {
20 JOSMFixture.createUnitTestFixture().init();
21 }
22
23 /**
24 * Test of {@link Geometry#getLineLineIntersection} method.
25 */
26 @Test
27 public void testLineLineIntersection() {
28 EastNorth p1 = new EastNorth(-9477809.106349014, 1.5392960539974203E7);
29 EastNorth p2 = new EastNorth(-9477813.789091509, 1.5392954297092048E7);
30 EastNorth p3 = new EastNorth(-9477804.974058038, 1.539295490030348E7);
31 EastNorth p4 = new EastNorth(-9477814.628697459, 1.5392962142181376E7);
32
33 EastNorth intersectionPoint = Geometry.getLineLineIntersection(p1, p2, p3, p4);
34
35 EastNorth d1 = p3.subtract(intersectionPoint);
36 EastNorth d2 = p1.subtract(p2);
37 Double crossProduct = d1.east()*d2.north() - d1.north()*d2.east();
38 Double scalarProduct = d1.east()*d2.east() + d1.north()*d2.north();
39 Double len1 = d1.length();
40 Double len2 = d2.length();
41
42 Double angle1 = Geometry.getCornerAngle(p1, p2, intersectionPoint);
43 Double angle2 = Geometry.getCornerAngle(p3, p4, intersectionPoint);
44 Assert.assertTrue("intersection point not on line, angle: " + angle1,
45 Math.abs(angle1) < 1e-10);
46 Assert.assertTrue("intersection point not on line, angle: " + angle2,
47 Math.abs(angle1) < 1e-10);
48
49 Assert.assertTrue("cross product != 1 : " + Math.abs(crossProduct/len1/len2),
50 Math.abs(Math.abs(crossProduct/len1/len2) - 1) < 1e-10);
51 Assert.assertTrue("scalar product != 0 : " + scalarProduct/len1/len2,
52 Math.abs(scalarProduct/len1/len2) < 1e-10);
53 }
54}
Note: See TracBrowser for help on using the repository browser.