Revision 39459

View differences:

tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/GeometryManagerTest.java
1
package org.gvsig.fmap.geom;
2

  
3
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
4
import org.gvsig.fmap.geom.Geometry.TYPES;
5
import org.gvsig.fmap.geom.exception.CreateGeometryException;
6
import org.gvsig.fmap.geom.operation.GeometryOperation;
7
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
8
import org.gvsig.fmap.geom.operation.GeometryOperationException;
9
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
10
import org.gvsig.fmap.geom.operation.ensureOrientation.EnsureOrientation;
11
import org.gvsig.fmap.geom.operation.flip.Flip;
12
import org.gvsig.fmap.geom.operation.isCCW.IsCCW;
13
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
14
import org.gvsig.fmap.geom.operation.towkb.ToWKB;
15
import org.gvsig.fmap.geom.primitive.Arc;
16
import org.gvsig.fmap.geom.primitive.Point;
17
import org.gvsig.fmap.geom.primitive.impl.Arc2D;
18
import org.gvsig.fmap.geom.type.GeometryType;
19
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
20
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
21
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class GeometryManagerTest extends AbstractLibraryAutoInitTestCase {
26

  
27
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
28

  
29
	private GeometryManager manager;
30

  
31
	protected void doSetUp() throws Exception {
32
		manager = GeometryLocator.getGeometryManager();		
33
	}
34

  
35
	public void testRegister() throws Exception {
36
		logger.debug("--------- testRegister() START ----------");
37

  
38
		Point p2d = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
39
		assertNotNull(p2d);
40
		p2d.setCoordinateAt(0, 0);
41
		p2d.setCoordinateAt(1, 0);
42

  
43
		java.awt.geom.Point2D pt1 = new java.awt.geom.Point2D.Float(0,1);
44
		java.awt.geom.Point2D pt2 = new java.awt.geom.Point2D.Float(1,1);
45
		java.awt.geom.Point2D pt3 = new java.awt.geom.Point2D.Float(1,0);
46
		Arc2D c2d = (Arc2D) manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
47
		assertNotNull(c2d);
48
		
49
		GeometryType geomType1 = manager.getGeometryType(TYPES.POINT, SUBTYPES.GEOM2D);
50
		GeometryType geomType2 = manager.getGeometryType(TYPES.ARC, SUBTYPES.GEOM2D);
51

  
52
		assertEquals(p2d.getGeometryType(), geomType1);
53
		assertEquals(c2d.getGeometryType(), geomType2);
54

  
55
//		int op1 = manager.registerGeometryOperation("toJTS", new ToJTS(), geomType1);
56
//		logger.debug("op1=" + op1);
57
//
58
//		int op2 = -1;
59
//		try {
60
//			op2 = manager.registerGeometryOperation("toJTS", new ToJTS(), geomType1);
61
//			logger.debug("op2=" + op2);
62
//		} catch (Exception e) {
63
//			logger.error("Error registrando operaci?n: ", e);
64
//		}
65

  
66
		int op3 = manager.registerGeometryOperation("toWKB", new ToWKB(),geomType1);
67
		int op4 = manager.registerGeometryOperation("toWKB", new ToWKB(),geomType2);
68

  
69
		logger.debug("op3=" + op3);
70

  
71
//		assertTrue("FALLO: op1 != op2", op1 == op2);
72
//		assertTrue("FALLO: op1 == op3", op1 != op3);
73
//		assertFalse("FALLO: op4 == op", op4 == op1);
74

  
75
		//Point p = (Point) factory.createPoint2D(1, 2);
76
		Point p = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
77

  
78
		// TODO: implement again with the needed context for each operation
79

  
80
		// GeometryOperationContext ctx = new GeometryOperationContext();
81
		// ctx.setAttribute("dummy", "DummyValue");
82
		// p.invokeOperation(ToWKB.CODE, ctx);
83
		// p.invokeOperation(ToJTS.CODE, ctx);
84
		// p.invokeOperation(Flip.CODE, ctx);
85

  
86
		Geometry sol = manager.create(TYPES.SOLID, SUBTYPES.GEOM3D);
87
		assertNotNull(sol);
88
		//logger.debug(sol);
89

  
90
		logger.debug("--------- testRegister() END ----------");
91
	}
92

  
93
	public void testGeneralPathXOperations() throws InstantiationException, IllegalAccessException, CreateGeometryException{
94
		logger.debug("--------- Test GeneralPathX Operation START ----------");
95

  
96
		//Registering the operation Flip() to all the geometries...
97
		manager.registerGeometryOperation("flip", new Flip());
98

  
99
		//Registering the operation ensureOrientation() to all the geometries...
100
		manager.registerGeometryOperation("ensureOrientation", new EnsureOrientation());
101

  
102
		//Registering the operation isCCW() to all the geometries...
103
		manager.registerGeometryOperation("isCCW", new IsCCW());
104

  
105
		//Building the Points for a curve...
106
//		java.awt.geom.Point2D p1 = new java.awt.geom.Point2D.Double(1,2);
107
//		java.awt.geom.Point2D p2 = new java.awt.geom.Point2D.Double(2,1);
108
//		java.awt.geom.Point2D p3 = new java.awt.geom.Point2D.Double(3,3);
109

  
110
		Point p1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
111
		p1.setCoordinateAt(0, 1);
112
		p1.setCoordinateAt(1, 2);
113

  
114
		Point p2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
115
		p2.setCoordinateAt(0, 2);
116
		p2.setCoordinateAt(1, 1);
117

  
118
		Point p3 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
119
		p3.setCoordinateAt(0, 3);
120
		p3.setCoordinateAt(1, 3);
121

  
122
		//Build a curve to get the operation invoked with the registered operation.
123
		//Geometry curve = (Curve) factory.createArc(p1, p2, p3);
124
		Arc arc = (Arc) manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
125
        arc.setPoints(p1, p2, p3);
126

  
127
		try {
128
			arc.invokeOperation(Flip.CODE, null);
129
		} catch (GeometryOperationNotSupportedException e) {
130
			logger.error("Operation doesn't be registered for this geometry. \n", e);
131
		} catch (GeometryOperationException e) {
132
			logger.error("An error produced while the Operation was running. \n", e);
133
		}
134
		GeometryOperationContext ctx = new GeometryOperationContext();
135
		ctx.setAttribute("bCCW",new Boolean(true));
136
		Boolean aux1 = null;
137
		try {
138
			aux1 = (Boolean) arc.invokeOperation(EnsureOrientation.CODE, ctx);
139
		} catch (GeometryOperationNotSupportedException e) {
140
			logger.error("Operation doesn't be registered for this geometry. \n", e);
141
		} catch (GeometryOperationException e) {
142
			// TODO Auto-generated catch block
143
			logger.error("An error produced while the Operation was running. \n", e);
144
		}
145
		//True si es exterior, le ha dado la vuelta.
146
		assertTrue(aux1.booleanValue());
147

  
148
		Boolean aux2 = null;
149
		try {
150
			aux2 = (Boolean) arc.invokeOperation(IsCCW.CODE, null);
151
		} catch (GeometryOperationNotSupportedException e) {
152
			logger.error("Operation doesn't be registered for this geometry. \n", e);
153
		} catch (GeometryOperationException e) {
154
			// TODO Auto-generated catch block
155
			logger.error("An error produced while the Operation was running. \n", e);
156
		}
157
		//True si es CCW.
158
		assertTrue(aux2.booleanValue());
159

  
160
		logger.debug("--------- Test GeneralPathX Operation END ----------");
161
	}
162

  
163
	// TODO: implement again with the needed context for each operation
164
	// public void testInvoke() throws InstantiationException,
165
	// IllegalAccessException, CreateGeometryException {
166
	// int size = 100000;
167
	//
168
	// // Fill the operation context with required params
169
	// GeometryOperationContext ctx = new GeometryOperationContext();
170
	// GeometryOperationContext var = new GeometryOperationContext();
171
	// var.setAttribute("bCCW",new Boolean(true));
172
	//
173
	// logger.debug("ToJTS.-");
174
	// indirectInvoke(ToJTS.CODE, ctx, size);
175
	// directInvoke(ToJTS.CODE, ctx, size);
176
	// logger.debug("ToWKB.-");
177
	// indirectInvoke(ToWKB.CODE, null, size);
178
	// directInvoke(ToWKB.CODE, null, size);
179
	// logger.debug("Flip.-");
180
	// indirectInvoke(Flip.CODE, ctx, size);
181
	// directInvoke(Flip.CODE, ctx, size);
182
	// logger.debug("EnsureOrientation.-");
183
	// //indirectInvoke(EnsureOrientation.CODE, var, size);
184
	// directInvoke(EnsureOrientation.CODE, var, size);
185
	// logger.debug("isCCW.-");
186
	// //indirectInvoke(IsCCW.CODE, ctx, size);
187
	// directInvoke(IsCCW.CODE, ctx, size);
188
	//
189
	// }
190

  
191
	private Geometry[] createGeometryArray(int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
192
		Geometry[] geom = new Geometry[size];
193
		for (int i = 0; i < size; i++) {
194
			//geom[i] = factory.createPoint2D(Math.log(1 - i), Math.log(i + 1));
195
			geom[i] = manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
196
		}
197
		return geom;
198
	}
199

  
200
	private long directInvoke(int opCode, GeometryOperationContext ctx, int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
201
		Geometry[] geoms = createGeometryArray(size);
202

  
203
		long t0 = System.currentTimeMillis();
204

  
205
		GeometryOperation geomOp = null;
206
		try {
207
			geomOp = manager.getGeometryOperation(ToJTS.CODE, TYPES.POINT, SUBTYPES.GEOM2D);
208
		} catch (GeometryTypeNotSupportedException gtnse) {
209
			logger.error("Error:", gtnse);
210
		} catch (GeometryOperationNotSupportedException gonse) {
211
			logger.error("Error:", gonse);
212
		} catch (GeometryTypeNotValidException e) {
213
			logger.error("Error:", e);
214
		}
215

  
216
		// Here is the main loop where you call the operation
217
		try {
218
			for (int i = 0; i < geoms.length; i++) {
219
				Object result = geomOp.invoke(geoms[i], ctx);
220
				// if(i%100 == 99) logger.debug(result);
221
			}
222

  
223
		} catch (GeometryOperationException goe) {
224
			logger.error("Error:", goe);
225
		}
226
		long t1 = System.currentTimeMillis();
227
		long t = t1 - t0;
228
		logger.debug("Milliseconds (direct): " + t);
229
		return t;
230
	}
231

  
232
	private long indirectInvoke(int opCode, GeometryOperationContext ctx,
233
			int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
234
		Geometry[] geoms = createGeometryArray(size);
235

  
236
		long t0 = System.currentTimeMillis();
237

  
238
		// Here is the main loop where you call the operation
239
		try {
240
			for (int i = 0; i < geoms.length; i++) {
241
				Object result = (geoms[i]).invokeOperation(opCode,
242
						ctx);
243
				// if(i%100 == 99) logger.debug(result);
244
			}
245
		} catch (GeometryOperationNotSupportedException gonse) {
246
			logger.error("Error:", gonse);
247
		} catch (GeometryOperationException goe) {
248
			logger.error("Error:", goe);
249
		}
250
		long t1 = System.currentTimeMillis();
251
		long t = t1 - t0;
252
		logger.debug("Milliseconds (indirect): " + t);
253
		return t;
254
	}
255

  
256
//	public void testRegisterBasicGeometryType() {
257
//		GeometryType gt = GeometryLocator.getGeometryManager()
258
//		.registerGeometryType(DummyPoint2D.class, "DummyPoint2D", TYPES.ELLIPSE,  SUBTYPES.GEOM2DZ);
259
//
260
//		logger.debug(String.valueOf(gt.getType()));
261
//
262
//		GeometryLocator.getGeometryManager().unregisterGeometryType(DummyPoint2D.class);
263
//
264
//		gt = GeometryLocator.getGeometryManager()
265
//		.registerGeometryType(DummyPoint2D.class, "DummyPoint2D", TYPES.POINT, SUBTYPES.GEOM2D);
266
//
267
//		logger.debug(String.valueOf(gt.getType()));
268
//		GeometryLocator.getGeometryManager().unregisterGeometryType(
269
//				DummyPoint2D.class);
270
//		
271
//	}
272
}
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/aggregate/MultiCurveTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.aggregate;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.primitive.Curve;
38
import org.gvsig.fmap.geom.primitive.GeneralPathX;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class MultiCurveTest extends AbstractLibraryAutoInitTestCase {
47
	private GeometryManager manager;
48
	
49
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
50

  
51
	protected void doSetUp() throws Exception {
52
		manager = GeometryLocator.getGeometryManager();		
53
	}
54
	
55
	public void testCreateMultiCurve2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
56
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
57
		GeneralPathX generalPathX1 = new GeneralPathX();
58
		generalPathX1.moveTo(0, 0);
59
		generalPathX1.lineTo(1, 1);
60
		generalPathX1.lineTo(2, 1);		
61
		curve1.setGeneralPath(generalPathX1);	
62
		
63
		Curve curve2 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
64
		GeneralPathX generalPathX2 = new GeneralPathX();
65
		generalPathX2.moveTo(0, 0);
66
		generalPathX2.lineTo(1, 1);
67
		generalPathX2.lineTo(2, 1);		
68
		curve2.setGeneralPath(generalPathX2);	
69
		
70
		MultiCurve multiCurve = (MultiCurve)manager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
71
		multiCurve.addCurve(curve1);
72
		multiCurve.addCurve(curve2);
73
				
74
		Assert.assertEquals(2, multiCurve.getPrimitivesNumber());
75
		Assert.assertEquals(0.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(0, 0), 0);
76
		Assert.assertEquals(0.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(0, 1), 0);
77
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(1, 0), 1);
78
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(1, 1), 1);
79
		Assert.assertEquals(2.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(2, 0), 2);
80
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(0)).getCoordinateAt(2, 1), 1);
81
		
82
		Assert.assertEquals(2, multiCurve.getPrimitivesNumber());
83
		Assert.assertEquals(0.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(0, 0), 0);
84
		Assert.assertEquals(0.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(0, 1), 0);
85
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(1, 0), 1);
86
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(1, 1), 1);
87
		Assert.assertEquals(2.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(2, 0), 2);
88
		Assert.assertEquals(1.0, ((Curve)multiCurve.getPrimitiveAt(1)).getCoordinateAt(2, 1), 1);
89
	}	
90
}
91

  
0 92

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/aggregate/MultiPrimitiveTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.aggregate;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.primitive.Curve;
38
import org.gvsig.fmap.geom.primitive.GeneralPathX;
39
import org.gvsig.fmap.geom.primitive.Point;
40
import org.gvsig.fmap.geom.primitive.Surface;
41
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45
/**
46
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
47
 */
48
public class MultiPrimitiveTest extends AbstractLibraryAutoInitTestCase {
49
	private GeometryManager manager;
50
	
51
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
52

  
53
	protected void doSetUp() throws Exception {
54
		manager = GeometryLocator.getGeometryManager();		
55
	}
56
	
57
	public void testCreateMultiGeometry() throws InstantiationException, IllegalAccessException, CreateGeometryException{
58
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
59
		GeneralPathX generalPathX1 = new GeneralPathX();
60
		generalPathX1.moveTo(0, 0);
61
		generalPathX1.lineTo(1, 1);
62
		generalPathX1.lineTo(2, 1);		
63
		curve1.setGeneralPath(generalPathX1);	
64
		
65
		Curve curve2 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
66
		GeneralPathX generalPathX2 = new GeneralPathX();
67
		generalPathX2.moveTo(0, 0);
68
		generalPathX2.lineTo(1, 1);
69
		generalPathX2.lineTo(2, 1);		
70
		curve2.setGeneralPath(generalPathX2);	
71
		
72
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
73
		point.setCoordinateAt(0, 1.0);
74
		point.setCoordinateAt(1, 2.0);
75
		
76
		Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
77
		GeneralPathX generalPathX = new GeneralPathX();
78
		generalPathX.moveTo(0, 0);
79
		generalPathX.lineTo(1, 1);
80
		generalPathX.lineTo(2, 1);
81
		surface.setGeneralPath(generalPathX);	
82
		
83
		MultiPrimitive multiPrimitive = (MultiPrimitive)manager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D);
84
		multiPrimitive.addPrimitive(curve1);
85
		multiPrimitive.addPrimitive(point);
86
		multiPrimitive.addPrimitive(surface);
87
		multiPrimitive.addPrimitive(curve2);
88
						
89
		Assert.assertEquals(4, multiPrimitive.getPrimitivesNumber());
90
		Assert.assertEquals(0.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(0, 0), 0);
91
		Assert.assertEquals(0.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(0, 1), 0);
92
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(1, 0), 1);
93
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(1, 1), 1);
94
		Assert.assertEquals(2.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(2, 0), 2);
95
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(0)).getCoordinateAt(2, 1), 1);
96
		
97
		Assert.assertEquals(1.0, ((Point)multiPrimitive.getPrimitiveAt(1)).getX(), 0);
98
		Assert.assertEquals(2.0, ((Point)multiPrimitive.getPrimitiveAt(1)).getY(), 0);
99
		
100
		Assert.assertEquals(0.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(0, 0), 0);
101
		Assert.assertEquals(0.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(0, 1), 0);
102
		Assert.assertEquals(1.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(1, 0), 1);
103
		Assert.assertEquals(1.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(1, 1), 1);
104
		Assert.assertEquals(2.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(2, 0), 2);
105
		Assert.assertEquals(1.0, ((Surface)multiPrimitive.getPrimitiveAt(2)).getCoordinateAt(2, 1), 1);
106

  
107
		Assert.assertEquals(0.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(0, 0), 0);
108
		Assert.assertEquals(0.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(0, 1), 0);
109
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(1, 0), 1);
110
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(1, 1), 1);
111
		Assert.assertEquals(2.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(2, 0), 2);
112
		Assert.assertEquals(1.0, ((Curve)multiPrimitive.getPrimitiveAt(3)).getCoordinateAt(2, 1), 1);
113
	}	
114
}
115

  
0 116

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/aggregate/MultiSurfaceTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.aggregate;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.primitive.GeneralPathX;
38
import org.gvsig.fmap.geom.primitive.Surface;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class MultiSurfaceTest extends AbstractLibraryAutoInitTestCase {
47
	private GeometryManager manager;
48
	
49
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
50

  
51
	protected void doSetUp() throws Exception {
52
		manager = GeometryLocator.getGeometryManager();		
53
	}
54
	
55
	public void testCreateMultiSurface2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
56
		Surface surface1 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
57
		GeneralPathX generalPathX1 = new GeneralPathX();
58
		generalPathX1.moveTo(0, 0);
59
		generalPathX1.lineTo(1, 1);
60
		generalPathX1.lineTo(2, 1);		
61
		surface1.setGeneralPath(generalPathX1);	
62
		
63
		Surface surface2 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);		
64
		GeneralPathX generalPathX2 = new GeneralPathX();
65
		generalPathX2.moveTo(0, 0);
66
		generalPathX2.lineTo(1, 1);
67
		generalPathX2.lineTo(2, 1);		
68
		surface2.setGeneralPath(generalPathX2);	
69
		
70
		MultiSurface multiSurface = (MultiSurface)manager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
71
		multiSurface.addSurface(surface1);
72
		multiSurface.addSurface(surface2);
73
				
74
		Assert.assertEquals(2, multiSurface.getPrimitivesNumber());
75
		Assert.assertEquals(0.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(0, 0), 0);
76
		Assert.assertEquals(0.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(0, 1), 0);
77
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(1, 0), 1);
78
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(1, 1), 1);
79
		Assert.assertEquals(2.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(2, 0), 2);
80
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(0)).getCoordinateAt(2, 1), 1);
81
		
82
		Assert.assertEquals(0.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(0, 0), 0);
83
		Assert.assertEquals(0.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(0, 1), 0);
84
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(1, 0), 1);
85
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(1, 1), 1);
86
		Assert.assertEquals(2.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(2, 0), 2);
87
		Assert.assertEquals(1.0, ((Surface)multiSurface.getPrimitiveAt(1)).getCoordinateAt(2, 1), 1);
88
	}	
89
}
90

  
0 91

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/aggregate/MultiPointTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.aggregate;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

  
42
/**
43
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
44
 */
45
public class MultiPointTest extends AbstractLibraryAutoInitTestCase {
46
	private GeometryManager manager;
47
	
48
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
49

  
50
	protected void doSetUp() throws Exception {
51
		manager = GeometryLocator.getGeometryManager();		
52
	}
53
	
54
	public void testCreateMultiPoint2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
55
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
56
		point1.setCoordinateAt(0, 1.0);
57
		point1.setCoordinateAt(1, 2.0);
58
		point1.setCoordinateAt(2, 3.0);
59
		
60
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
61
		point2.setCoordinateAt(0, 4.0);
62
		point2.setCoordinateAt(1, 5.0);
63
		point2.setCoordinateAt(2, 6.0);
64
		
65
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
66
		multiPoint.addPoint(point1);
67
		multiPoint.addPoint(point2);
68
		
69
		Assert.assertEquals(2, multiPoint.getPrimitivesNumber());
70
		Assert.assertEquals(1.0, ((Point)multiPoint.getPrimitiveAt(0)).getX(), 0);
71
		Assert.assertEquals(2.0, ((Point)multiPoint.getPrimitiveAt(0)).getY(), 0);
72
		Assert.assertEquals(3.0, ((Point)multiPoint.getPrimitiveAt(0)).getCoordinateAt(2), 0);
73
		Assert.assertEquals(4.0, ((Point)multiPoint.getPrimitiveAt(1)).getX(), 0);
74
		Assert.assertEquals(5.0, ((Point)multiPoint.getPrimitiveAt(1)).getY(), 0);
75
		Assert.assertEquals(6.0, ((Point)multiPoint.getPrimitiveAt(1)).getCoordinateAt(2), 0);
76
		
77
	}
78
	
79
}
80

  
0 81

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/ArcTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import java.awt.geom.Rectangle2D;
31

  
32
import junit.framework.Assert;
33

  
34
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
37
import org.gvsig.fmap.geom.Geometry.TYPES;
38
import org.gvsig.fmap.geom.exception.CreateGeometryException;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class ArcTest extends AbstractLibraryAutoInitTestCase {
47
	private GeometryManager manager;
48
	
49
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
50

  
51
	protected void doSetUp() throws Exception {
52
		manager = GeometryLocator.getGeometryManager();		
53
	}
54
	
55
	public void testCreateArc2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
56
		Arc arc = (Arc)manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
57
		GeneralPathX generalPathX = new GeneralPathX();
58
		Exception e = null;
59
		try{
60
			arc.setGeneralPath(generalPathX);
61
		}catch (UnsupportedOperationException e1){
62
			e = e1;
63
		}
64
		Assert.assertTrue(e instanceof UnsupportedOperationException);
65

  
66

  
67
		Point initPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
68
		initPoint.setCoordinateAt(0, 1);
69
		initPoint.setCoordinateAt(1, 1);
70

  
71
		Point middle = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
72
		middle.setCoordinateAt(0, 0);
73
		middle.setCoordinateAt(1, 0);
74
		
75
		
76
		Point endPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
77
		endPoint.setCoordinateAt(0, 0);
78
		endPoint.setCoordinateAt(1, 1);
79
		
80
		arc.setPoints(initPoint, middle, endPoint);
81
		
82
		assertEquals(0.5, arc.getCenterPoint().getX(), 0);
83
		assertEquals(0.5, arc.getCenterPoint().getY(), 0);
84
		assertEquals(1.0, arc.getInitPoint().getX(), 0);
85
		assertEquals(1.0, arc.getInitPoint().getY(), 0);
86
		assertEquals(0, arc.getEndPoint().getX(), 0);
87
		assertEquals(1, arc.getEndPoint().getY(), 0);
88
		
89
		// =================================
90
		
91
		double deg_rad = Math.PI / 180.0;
92
		Point cp = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
93
        cp.setX(10);
94
        cp.setY(2);
95
		
96
		arc.setPointsStartExt(cp, 5, 45*deg_rad, 135*deg_rad);
97
        assertEquals(10, arc.getEndPoint().getX(), 0.000001);
98
        assertEquals(-3, arc.getEndPoint().getY(), 0.000001);
99
        
100
        Rectangle2D rect = new Rectangle2D.Double(0, 0, 9, 9);
101
        
102
        arc.setPointsStartEnd(cp, 5, 45*deg_rad, -90*deg_rad);
103
        assertFalse(arc.intersects(rect));
104
        
105
        arc.setPointsStartEnd(cp, 5, 45*deg_rad, 5d*Math.PI/2d);
106
        assertTrue(arc.intersects(rect));
107

  
108
	}	
109
	
110

  
111

  
112
}
113

  
114

  
115

  
0 116

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/SurfaceTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import java.awt.geom.AffineTransform;
31
import java.awt.geom.PathIterator;
32

  
33
import junit.framework.Assert;
34

  
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.fmap.geom.Geometry.TYPES;
39
import org.gvsig.fmap.geom.exception.CreateGeometryException;
40
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
41

  
42
/**
43
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
44
 */
45
public class SurfaceTest extends AbstractLibraryAutoInitTestCase {
46
	private GeometryManager manager;
47
	
48
	protected void doSetUp() throws Exception {
49
		manager = GeometryLocator.getGeometryManager();		
50
	}
51
	
52
	public void testCreateSurface2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
53
		Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
54
		GeneralPathX generalPathX = new GeneralPathX();
55
		generalPathX.moveTo(0, 0);
56
		generalPathX.lineTo(1, 1);
57
		generalPathX.lineTo(2, 1);
58
		surface.setGeneralPath(generalPathX);	
59
		
60
		Assert.assertEquals(0.0, surface.getCoordinateAt(0,0),0);
61
		Assert.assertEquals(0.0, surface.getCoordinateAt(0,1),0);
62
		Assert.assertEquals(1.0, surface.getCoordinateAt(1,0),0);
63
		Assert.assertEquals(1.0, surface.getCoordinateAt(1,1),0);
64
		Assert.assertEquals(2.0, surface.getCoordinateAt(2,0),0);
65
		Assert.assertEquals(1.0, surface.getCoordinateAt(2,1),0);
66
		
67
		AffineTransform at = new AffineTransform();
68
	    at.translate(1, 1);
69
	    surface.transform(at);
70
		
71
		Assert.assertEquals(1.0, surface.getCoordinateAt(0,0),0);
72
		Assert.assertEquals(1.0, surface.getCoordinateAt(0,1),0);
73
		Assert.assertEquals(2.0, surface.getCoordinateAt(1,0),0);
74
		Assert.assertEquals(2.0, surface.getCoordinateAt(1,1),0);
75
		Assert.assertEquals(3.0, surface.getCoordinateAt(2,0),0);
76
		Assert.assertEquals(2.0, surface.getCoordinateAt(2,1),0);
77
				
78
		PathIterator iterator = surface.getPathIterator(at);
79
		double[] coords = new double[2];
80
		int i=0;
81
		while (!iterator.isDone()){
82
			i++;
83
			iterator.currentSegment(coords);		
84
			iterator.next();
85
		}
86
		Assert.assertEquals(3, i);		
87

  
88
	}
89
}
90

  
91

  
92

  
0 93

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/PointTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import java.awt.geom.AffineTransform;
31
import java.awt.geom.PathIterator;
32

  
33
import junit.framework.Assert;
34

  
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.fmap.geom.Geometry.TYPES;
39
import org.gvsig.fmap.geom.exception.CreateGeometryException;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
42
import org.gvsig.tools.locator.LocatorException;
43
import org.gvsig.tools.persistence.PersistentState;
44
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered;
45
import org.gvsig.tools.persistence.exception.PersistenceException;
46
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException;
47
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51
/**
52
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
53
 */
54
public class PointTest extends AbstractLibraryAutoInitTestCase {
55
	private GeometryManager manager;
56
	
57
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
58

  
59

  
60
	protected void doSetUp() throws Exception {
61
		manager = GeometryLocator.getGeometryManager();
62
		
63
	}
64
	
65
	public void testCreatePoint2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
66
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
67
		point.setCoordinateAt(0, 1.0);
68
		point.setCoordinateAt(1, 2.0);
69
		
70
		AffineTransform at = new AffineTransform();
71
	    at.translate(1, 1);
72
		point.transform(at);
73
		
74
		Assert.assertEquals(2.0, point.getCoordinateAt(0),0);
75
		Assert.assertEquals(3.0, point.getCoordinateAt(1),0);
76
		
77
		PathIterator iterator = point.getPathIterator(at);
78
		double[] coords = new double[2];
79
		int i=0;
80
		while (!iterator.isDone()){
81
			i++;
82
			iterator.next();
83
			iterator.currentSegment(coords);			
84
		}
85
		Assert.assertEquals(1, i);
86
		Assert.assertEquals(3.0, coords[0], 0);
87
		Assert.assertEquals(4.0, coords[1] ,0);
88
	}
89
	
90
	public void testPersistencePoint2D() throws CreateGeometryException, PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions, LocatorException{
91
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
92
		point1.setCoordinateAt(0, 1.0);
93
		point1.setCoordinateAt(1, 2.0);
94
		
95
		PersistentState persistentState = ToolsLocator.getPersistenceManager().getState(point1);
96
		Point point2 = (Point) ToolsLocator.getPersistenceManager().create(persistentState);
97
		
98
		Assert.assertEquals(point1.getX(), point2.getX(), 0);
99
		Assert.assertEquals(point1.getX(), point2.getX(), 0);
100
	}
101
	
102
	public void testCreatePoint2DZ() throws InstantiationException, IllegalAccessException, CreateGeometryException{
103
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
104
		point.setCoordinateAt(0, 1.0);
105
		point.setCoordinateAt(1, 2.0);
106
		point.setCoordinateAt(2, 3.0);
107
		
108
		AffineTransform at = new AffineTransform();
109
	    at.translate(1, 1);
110
		point.transform(at);
111
		
112
		Assert.assertEquals(2.0, point.getCoordinateAt(0),0);
113
		Assert.assertEquals(3.0, point.getCoordinateAt(1),0);
114
		Assert.assertEquals(3.0, point.getCoordinateAt(2),0);
115
		
116
		PathIterator iterator = point.getPathIterator(at);
117
		double[] coords = new double[2];
118
		int i=0;
119
		while (!iterator.isDone()){
120
			i++;
121
			iterator.next();
122
			iterator.currentSegment(coords);			
123
		}
124
		Assert.assertEquals(1, i);
125
		Assert.assertEquals(3.0, coords[0], 0);
126
		Assert.assertEquals(4.0, coords[1] ,0);
127
	}
128
	
129
	public void testPersistencePoint2DZ() throws CreateGeometryException, PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions, LocatorException{
130
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
131
		point1.setCoordinateAt(0, 1.0);
132
		point1.setCoordinateAt(1, 2.0);
133
		point1.setCoordinateAt(2, 3.0);
134
		
135
		PersistentState persistentState = ToolsLocator.getPersistenceManager().getState(point1);
136
		Point point2 = (Point) ToolsLocator.getPersistenceManager().create(persistentState);
137
		
138
		Assert.assertEquals(point1.getX(), point2.getX(), 0);
139
		Assert.assertEquals(point1.getX(), point2.getX(), 0);
140
		Assert.assertEquals(point1.getCoordinateAt(2), point2.getCoordinateAt(2), 0);
141
	}
142

  
143
}
144

  
0 145

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/SplineTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
38

  
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class SplineTest extends AbstractLibraryAutoInitTestCase {
43
	private GeometryManager manager;
44
	
45
	protected void doSetUp() throws Exception {
46
		manager = GeometryLocator.getGeometryManager();		
47
	}
48
	
49
	public void testCreateSpline2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
50
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
51
		point1.setCoordinateAt(0, 1.0);
52
		point1.setCoordinateAt(1, 2.0);
53
		
54
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
55
		point2.setCoordinateAt(0, 4.0);
56
		point2.setCoordinateAt(1, 5.0);
57
	
58
		Spline spline = (Spline)manager.create(TYPES.SPLINE, SUBTYPES.GEOM2D);
59
		spline.addVertex(point1);
60
		spline.addVertex(point2);
61
		
62
		Assert.assertEquals(1.0, spline.getCoordinateAt(0, 0), 0);
63
		Assert.assertEquals(2.0, spline.getCoordinateAt(0, 1), 0);
64
		
65
	}
66
}
67

  
0 68

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/EllipticArcTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

  
41
/**
42
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
43
 */
44
public class EllipticArcTest extends AbstractLibraryAutoInitTestCase {
45
	private GeometryManager manager;
46
	
47
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
48

  
49
	protected void doSetUp() throws Exception {
50
		manager = GeometryLocator.getGeometryManager();		
51
	}
52
	
53
	public void testEllipticArc2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
54
		EllipticArc ellipticArc = (EllipticArc)manager.create(TYPES.ELLIPTICARC, SUBTYPES.GEOM2D);
55
		GeneralPathX generalPathX = new GeneralPathX();
56
		Exception e = null;
57
		try{
58
			ellipticArc.setGeneralPath(generalPathX);
59
		}catch (UnsupportedOperationException e1){
60
			e = e1;
61
		}
62
		Assert.assertTrue(e instanceof UnsupportedOperationException);
63
		
64
		Point axis1Start = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
		axis1Start.setCoordinateAt(0, 0);
66
		axis1Start.setCoordinateAt(1, 0);
67
		
68
		Point axix1End = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
69
		axix1End.setCoordinateAt(0, 1);
70
		axix1End.setCoordinateAt(1, 1);
71
		
72
		double axis2Dist = 1;
73
		double angSt = 1;
74
		double angExt = 1;
75
		
76
		ellipticArc.setPoints(axis1Start, axix1End, axis2Dist, angSt, angExt);
77
		
78
		assertEquals(0, ellipticArc.getAxis1Start().getX(), 0);
79
		assertEquals(0, ellipticArc.getAxis1Start().getY(), 0);
80
		assertEquals(1, ellipticArc.getAxis1End().getX(), 0);
81
		assertEquals(1, ellipticArc.getAxis1End().getY(), 0);
82
		assertEquals(1, ellipticArc.getAxis2Dist(), axis2Dist);
83
		assertEquals(1, ellipticArc.getAngSt(), angSt);
84
		assertEquals(1, ellipticArc.getAngExt(), angExt);
85
	}	
86
}
87

  
88

  
89

  
90

  
91

  
0 92

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/EllipseTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

  
41
/**
42
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
43
 */
44
public class EllipseTest extends AbstractLibraryAutoInitTestCase {
45
	private GeometryManager manager;
46
	
47
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
48

  
49
	protected void doSetUp() throws Exception {
50
		manager = GeometryLocator.getGeometryManager();		
51
	}
52
	
53
	public void testEllipse2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
54
		Ellipse ellipse = (Ellipse)manager.create(TYPES.ELLIPSE, SUBTYPES.GEOM2D);
55
		GeneralPathX generalPathX = new GeneralPathX();
56
		Exception e = null;
57
		try{
58
			ellipse.setGeneralPath(generalPathX);
59
		}catch (UnsupportedOperationException e1){
60
			e = e1;
61
		}
62
		Assert.assertTrue(e instanceof UnsupportedOperationException);
63
		
64
		Point initPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
		initPoint.setCoordinateAt(0, 0);
66
		initPoint.setCoordinateAt(1, 0);
67
		
68
		Point endPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
69
		endPoint.setCoordinateAt(0, 1);
70
		endPoint.setCoordinateAt(1, 1);
71
		
72
		double axisLength = 1;
73
		
74
		ellipse.setPoints(initPoint, endPoint, axisLength);
75
		
76
		assertEquals(0, ellipse.getAxis1Start().getX(), 0);
77
		assertEquals(0, ellipse.getAxis1Start().getY(), 0);
78
		assertEquals(1, ellipse.getAxis1End().getX(), 0);
79
		assertEquals(1, ellipse.getAxis1End().getY(), 0);
80
		assertEquals(1, ellipse.getAxis2Dist(), axisLength);
81
	;
82
	}	
83
}
84

  
85

  
86

  
0 87

  
tags/v2_0_0_Build_2061/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/EnvelopeTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27

  
28
package org.gvsig.fmap.geom.primitive;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
37
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
import org.gvsig.tools.locator.LocatorException;
41
import org.gvsig.tools.persistence.PersistentState;
42
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException;
45
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

  
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
51
 */
52
public class EnvelopeTest extends AbstractLibraryAutoInitTestCase {
53
	private GeometryManager manager;
54

  
55
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
56

  
57
	protected void doSetUp() throws Exception {
58
		manager = GeometryLocator.getGeometryManager();		
59
	}
60

  
61
	public void testEnvelope2D() throws InstantiationException,
62
			IllegalAccessException, CreateEnvelopeException, CreateGeometryException {
63

  
64
		// Create
65
		Envelope env = createEnvelope2D(0, 1, 2, 3);
66
		checkEnvelope2D(env, 0, 1, 2, 3, "Create");
67

  
68
		Envelope env2 = createEnvelope2D(1, 2, 3, 4);
69
		checkEnvelope2D(env2, 1, 2, 3, 4, "Create 2");
70

  
71
		// Add
72
		env.add(env2);
73
		checkEnvelope2D(env, 0, 1, 3, 4, "Add");
74

  
75
		// Contains
76
		assertTrue("Contains", env.contains(env2));
77
		env2 = createEnvelope2D(1, 1, 2, 2);
78
		assertTrue("Contains 2", env.contains(env2));
79
		env2 = createEnvelope2D(1, 1, 6, 6);
80
		assertFalse("Contains 3", env.contains(env2));
81
		env2 = createEnvelope2D(-1, -1, -6, -6);
82
		assertFalse("Contains 4", env.contains(env2));
83

  
84
		// Intersets
85
		env2 = createEnvelope2D(1, 1, 2, 2);
86
		assertTrue("Intersets", env.intersects(env2));
87
		env2 = createEnvelope2D(-1, -1, 2, 2);
88
		assertTrue("Intersets 2", env.intersects(env2));
89
		env2 = createEnvelope2D(1, 1, 6, 6);
90
		assertTrue("Intersets 3", env.intersects(env2));
91
		env2 = createEnvelope2D(-5, -5, 6, 6);
92
		assertTrue("Intersets 3", env.intersects(env2));
93
		env2 = createEnvelope2D(-1, -1, -6, -6);
94
		assertFalse("Intersets 4", env.intersects(env2));
95
		env2 = createEnvelope2D(5, 5, 9, 9);
96
		assertFalse("Intersets 4", env.intersects(env2));
97
	}
98

  
99
	private Envelope createEnvelope2D(double minx, double miny, double maxx,
100
			double maxy) throws InstantiationException, IllegalAccessException, CreateEnvelopeException, CreateGeometryException {
101
		Envelope envelope = manager.createEnvelope(SUBTYPES.GEOM2D);
102
		Point min = (Point) manager.create(TYPES.POINT,SUBTYPES.GEOM2D);
103
		Point max = (Point) manager.create(TYPES.POINT,SUBTYPES.GEOM2D);
104
		min.setX(minx);
105
		min.setY(miny);
106

  
107
		max.setX(maxx);
108
		max.setY(maxy);
109
		envelope.setLowerCorner(min);
110
		envelope.setUpperCorner(max);
111

  
112
		return envelope;
113
	}
114

  
115
	private void checkEnvelope2D(Envelope env, double minx, double miny,
116
			double maxx, double maxy, String info) {
117

  
118
		Assert.assertTrue(info + ": minx : expected " + minx + " but has "
119
				+ env.getMinimum(0), env.getMinimum(0) - minx < 0.000000001);
120
		Assert.assertTrue(info + ": miny : expected " + miny + " but has "
121
				+ env.getMinimum(1), env.getMinimum(1) - miny < 0.000000001);
122
		Assert.assertTrue(info + ": maxx : expected " + maxx + " but has "
123
				+ env.getMaximum(0), env.getMaximum(0) - maxx < 0.000000001);
124
		Assert.assertTrue(info + ": maxy : expected " + maxy + " but has "
125
				+ env.getMaximum(1), env.getMaximum(1) - maxy < 0.000000001);
126

  
127
		Assert.assertTrue(info + ": lower conrner x : expected " + minx
128
				+ "but has " + env.getLowerCorner().getX(),
129
				env.getLowerCorner().getX() - minx < 0.000000001);
130
		Assert.assertTrue(info + ": lower conrner y : expected " + miny
131
				+ "but has " + env.getLowerCorner().getY(),
132
				env.getLowerCorner().getY() - miny < 0.000000001);
133
		Assert.assertTrue(info + ": upper conrner x : expected " + maxx
134
				+ "but has " + env.getUpperCorner().getX(),
135
				env.getUpperCorner().getX() - maxx < 0.000000001);
136
		Assert.assertTrue(info + ": upper conrner y : expected " + maxy
137
				+ "but has " + env.getUpperCorner().getY(),
138
				env.getUpperCorner().getY() - maxy < 0.000000001);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff