1 /*
2  * Copyright (c) 2016 Vivid Solutions.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
8  * and the Eclipse Distribution License is available at
9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12 
13 package org.locationtech.jts.operation.union;
14 
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 
19 import org.locationtech.jts.geom.Coordinate;
20 import org.locationtech.jts.geom.Geometry;
21 import org.locationtech.jts.geom.GeometryFactory;
22 
23 import junit.framework.TestCase;
24 import test.jts.util.IOUtil;
25 
26 /**
27  * Large-scale tests of {@link CascadedPolygonUnion}
28  * using synthetic datasets.
29  *
30  * @author mbdavis
31  *
32  */
33 public class CascadedPolygonUnionTest extends TestCase
34 {
35 	GeometryFactory geomFact = new GeometryFactory();
36 
CascadedPolygonUnionTest(String name)37   public CascadedPolygonUnionTest(String name) {
38     super(name);
39   }
40 
main(String[] args)41   public static void main(String[] args) {
42     junit.textui.TestRunner.run(CascadedPolygonUnionTest.class);
43   }
44 
testBoxes()45   public void testBoxes()
46   throws Exception
47   {
48   	runTest(IOUtil.readWKT(
49   			new String[] {
50   				"POLYGON ((80 260, 200 260, 200 30, 80 30, 80 260))",
51   				"POLYGON ((30 180, 300 180, 300 110, 30 110, 30 180))",
52   				"POLYGON ((30 280, 30 150, 140 150, 140 280, 30 280))"
53   			}),
54   			CascadedPolygonUnionTester.MIN_SIMILARITY_MEAURE);
55   }
56 
testDiscs1()57   public void testDiscs1()
58   throws Exception
59   {
60   	Collection geoms = createDiscs(5, 0.7);
61 
62   	//System.out.println(geomFact.buildGeometry(geoms));
63 
64   	runTest(geoms,
65   			CascadedPolygonUnionTester.MIN_SIMILARITY_MEAURE);
66   }
67 
68 
testDiscs2()69   public void testDiscs2()
70   throws Exception
71   {
72   	Collection geoms = createDiscs(5, 0.55);
73 
74   	//System.out.println(geomFact.buildGeometry(geoms));
75 
76   	runTest(geoms,
77   			CascadedPolygonUnionTester.MIN_SIMILARITY_MEAURE);
78   }
79 
80 
81   // TODO: add some synthetic tests
82 
83   private static CascadedPolygonUnionTester tester = new CascadedPolygonUnionTester();
84 
runTest(Collection geoms, double minimumMeasure)85   private void runTest(Collection geoms, double minimumMeasure)
86   {
87   	assertTrue(tester.test(geoms, minimumMeasure));
88   }
89 
createDiscs(int num, double radius)90   private Collection createDiscs(int num, double radius)
91   {
92   	List geoms = new ArrayList();
93   	for (int i = 0; i < num; i++) {
94     	for (int j = 0; j < num; j++) {
95     		Coordinate pt = new Coordinate(i, j);
96     		Geometry ptGeom = geomFact.createPoint(pt);
97     		Geometry disc = ptGeom.buffer(radius);
98     		geoms.add(disc);
99     	}
100   	}
101   	return geoms;
102   }
103 }
104