Revision 38288

View differences:

tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/CircleTest.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 CircleTest 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 testCreateCircle2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
54
		Circle circle = (Circle)manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
55
		GeneralPathX generalPathX = new GeneralPathX();
56
		Exception e = null;
57
		try{
58
			circle.setGeneralPath(generalPathX);
59
		}catch (UnsupportedOperationException e1){
60
			e = e1;
61
		}
62
		Assert.assertTrue(e instanceof UnsupportedOperationException);
63
		
64
		Point center = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
		center.setCoordinateAt(0, 0);
66
		center.setCoordinateAt(1, 0);
67
		
68
		Point radious = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
69
		radious.setCoordinateAt(0, 1);
70
		radious.setCoordinateAt(1, 1);
71
				
72
		circle.setPoints(center, radious);
73
		
74
		assertEquals(0.0, circle.getCenter().getX(), 0);
75
		assertEquals(0.0, circle.getCenter().getY(), 0);
76
		assertEquals(Math.sqrt(2), circle.getRadious(), 0);
77
		
78
	}	
79
}
80

  
81

  
82

  
0 83

  
tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/CurveTest.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
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

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

  
52
	protected void doSetUp() throws Exception {
53
		manager = GeometryLocator.getGeometryManager();		
54
	}
55
	
56
	public void testCreateCurve2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
57
		Curve curve = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
58
		GeneralPathX generalPathX = new GeneralPathX();
59
		generalPathX.moveTo(0, 0);
60
		generalPathX.lineTo(1, 1);
61
		generalPathX.lineTo(2, 1);		
62
		curve.setGeneralPath(generalPathX);	
63
		
64
		Assert.assertEquals(0.0, curve.getCoordinateAt(0,0),0);
65
		Assert.assertEquals(0.0, curve.getCoordinateAt(0,1),0);
66
		Assert.assertEquals(1.0, curve.getCoordinateAt(1,0),0);
67
		Assert.assertEquals(1.0, curve.getCoordinateAt(1,1),0);
68
		Assert.assertEquals(2.0, curve.getCoordinateAt(2,0),0);
69
		Assert.assertEquals(1.0, curve.getCoordinateAt(2,1),0);
70
		
71
		AffineTransform at = new AffineTransform();
72
	    at.translate(1, 1);
73
		curve.transform(at);
74
		
75
		Assert.assertEquals(1.0, curve.getCoordinateAt(0,0),0);
76
		Assert.assertEquals(1.0, curve.getCoordinateAt(0,1),0);
77
		Assert.assertEquals(2.0, curve.getCoordinateAt(1,0),0);
78
		Assert.assertEquals(2.0, curve.getCoordinateAt(1,1),0);
79
		Assert.assertEquals(3.0, curve.getCoordinateAt(2,0),0);
80
		Assert.assertEquals(2.0, curve.getCoordinateAt(2,1),0);
81
				
82
		PathIterator iterator = curve.getPathIterator(at);
83
		double[] coords = new double[3];
84
		int i=0;
85
		while (!iterator.isDone()){
86
			i++;			
87
			iterator.currentSegment(coords);		
88
			iterator.next();
89
		}
90
		Assert.assertEquals(3, i);		
91
	}
92
	
93
	public void testCreateCurve2DZ() throws InstantiationException, IllegalAccessException, CreateGeometryException{
94
		Curve curve = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM3D);
95
		GeneralPathX generalPathX = new GeneralPathX();
96
		generalPathX.moveTo(0, 0);
97
		generalPathX.lineTo(1, 1);
98
		generalPathX.lineTo(2, 1);
99
		curve.setGeneralPath(generalPathX);	
100
		
101
		Assert.assertEquals(0.0, curve.getCoordinateAt(0,0),0);
102
		Assert.assertEquals(0.0, curve.getCoordinateAt(0,1),0);
103
		Assert.assertEquals(1.0, curve.getCoordinateAt(1,0),0);
104
		Assert.assertEquals(1.0, curve.getCoordinateAt(1,1),0);
105
		Assert.assertEquals(2.0, curve.getCoordinateAt(2,0),0);
106
		Assert.assertEquals(1.0, curve.getCoordinateAt(2,1),0);
107
		
108
		AffineTransform at = new AffineTransform();
109
	    at.translate(1, 1);
110
		curve.transform(at);
111
		
112
		Assert.assertEquals(1.0, curve.getCoordinateAt(0,0),0);
113
		Assert.assertEquals(1.0, curve.getCoordinateAt(0,1),0);
114
		Assert.assertEquals(2.0, curve.getCoordinateAt(1,0),0);
115
		Assert.assertEquals(2.0, curve.getCoordinateAt(1,1),0);
116
		Assert.assertEquals(3.0, curve.getCoordinateAt(2,0),0);
117
		Assert.assertEquals(2.0, curve.getCoordinateAt(2,1),0);
118
				
119
		PathIterator iterator = curve.getPathIterator(at);
120
		double[] coords = new double[2];
121
		int i=0;
122
		while (!iterator.isDone()){
123
			i++;
124
			iterator.currentSegment(coords);
125
			iterator.next();
126
		}
127
		Assert.assertEquals(3, i);		
128

  
129
	}
130
}
131

  
132

  
0 133

  
tags/v2_0_0_Build_2047/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 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 ArcTest 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 testCreateArc2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
54
		Arc arc = (Arc)manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
55
		GeneralPathX generalPathX = new GeneralPathX();
56
		Exception e = null;
57
		try{
58
			arc.setGeneralPath(generalPathX);
59
		}catch (UnsupportedOperationException e1){
60
			e = e1;
61
		}
62
		Assert.assertTrue(e instanceof UnsupportedOperationException);
63
		
64
		Point center = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
		center.setCoordinateAt(0, 0);
66
		center.setCoordinateAt(1, 0);
67
		
68
		Point initPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
69
		initPoint.setCoordinateAt(0, 1);
70
		initPoint.setCoordinateAt(1, 1);
71
		
72
		Point endPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
73
		endPoint.setCoordinateAt(0, 0);
74
		endPoint.setCoordinateAt(1, 1);
75
		
76
		arc.setPoints(center, initPoint, endPoint);
77
		
78
		assertEquals(0.5, arc.getCenterPoint().getX(), 0);
79
		assertEquals(0.5, arc.getCenterPoint().getX(), 0);
80
		assertEquals(1.0, arc.getInitPoint().getX(), 0);
81
		assertEquals(1.0, arc.getInitPoint().getX(), 0);
82
		assertEquals(0, arc.getEndPoint().getX(), 0);
83
		assertEquals(0, arc.getEndPoint().getX(), 0);
84
	}	
85
}
86

  
87

  
88

  
0 89

  
tags/v2_0_0_Build_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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);
139

  
140
		double lengthx = 0, lengthy = 0;
141
		double midx = 0, midy = 0;
142
		try {
143
			lengthx = maxx - minx;
144
			midx = ( lengthx/ 2) + minx;
145
		} catch (Exception e) {
146
			// Nonthing to do
147
		}
148
		try {
149
			lengthy = maxy - miny;
150
			midy = (lengthy / 2) + miny;
151
		} catch (Exception e) {
152
			// Nonthing to do
153
		}
154

  
155
		Assert.assertTrue(info + ": center x : expected " + midx + "but has "
156
				+ env.getCenter(0),
157
				env.getCenter(0) - midx < 0.000000001);
158
		Assert.assertTrue(info + ": center y : expected " + midy + "but has "
159
				+ env.getCenter(1), env.getCenter(1) - midy < 0.000000001);
160

  
161
		Assert.assertTrue(info + ": length x : expected " + lengthx
162
				+ "but has " + env.getLength(0),
163
				env.getLength(0) - lengthx < 0.000000001);
164
		Assert.assertTrue(info + ": length y : expected " + lengthy
165
				+ "but has " + env.getLength(1),
166
				env.getLength(1) - lengthy < 0.000000001);
167
	}	
168
	
169
	public void testPersistenceEnvelope2D() throws CreateGeometryException, CreateEnvelopeException, InstantiationException, IllegalAccessException, PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions, LocatorException{
170
		Envelope envelope1 = createEnvelope2D(0, 1, 2, 3);
171
		
172
		PersistentState persistentState = ToolsLocator.getPersistenceManager().getState(envelope1);
173
		Envelope envelope2 = (Envelope) ToolsLocator.getPersistenceManager().create(persistentState);
174
		
175
		Assert.assertEquals(envelope1.getLowerCorner().getX(), envelope2.getLowerCorner().getX(), 0);
176
		Assert.assertEquals(envelope1.getLowerCorner().getY(), envelope2.getLowerCorner().getY(), 0);
177
		Assert.assertEquals(envelope1.getUpperCorner().getX(), envelope2.getUpperCorner().getX(), 0);
178
		Assert.assertEquals(envelope1.getUpperCorner().getY(), envelope2.getUpperCorner().getY(), 0);
179
	}
180
}	
181

  
182

  
0 183

  
tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/DummyPoint2D.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
* 2008 {{Company}}   {{Task}}
26
*/
27
 
28
package org.gvsig.fmap.geom;
29

  
30
import org.gvsig.fmap.geom.primitive.Point;
31
import org.gvsig.fmap.geom.primitive.impl.Point2D;
32
import org.gvsig.fmap.geom.type.GeometryType;
33

  
34

  
35
public class DummyPoint2D extends Point2D implements Point {
36

  
37
	/**
38
	 * @param geometryType
39
	 */
40
	public DummyPoint2D(GeometryType geometryType) {
41
		super(geometryType);
42
		// TODO Auto-generated constructor stub
43
	}
44

  
45
	private static final long serialVersionUID = 4449552637882072964L;
46

  
47
	
48

  
49
}
tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/tojts/toJTSTest.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.operation.tojts;
29

  
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.aggregate.MultiCurve;
38
import org.gvsig.fmap.geom.aggregate.MultiPoint;
39
import org.gvsig.fmap.geom.aggregate.MultiSurface;
40
import org.gvsig.fmap.geom.exception.CreateGeometryException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationException;
42
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
43
import org.gvsig.fmap.geom.primitive.Curve;
44
import org.gvsig.fmap.geom.primitive.GeneralPathX;
45
import org.gvsig.fmap.geom.primitive.Point;
46
import org.gvsig.fmap.geom.primitive.Surface;
47
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
48

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

  
56
    protected void doSetUp() throws Exception {
57
		manager = GeometryLocator.getGeometryManager();
58
		manager.registerGeometryOperation(ToJTS.NAME, new Point2DToJTS(), TYPES.POINT, SUBTYPES.GEOM2D);
59
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.CURVE, SUBTYPES.GEOM2D);
60
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.ARC, SUBTYPES.GEOM2D);
61

  
62
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.SURFACE, SUBTYPES.GEOM2D);
63
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.CIRCLE, SUBTYPES.GEOM2D);
64
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.ELLIPSE, SUBTYPES.GEOM2D);
65
		
66
		manager.registerGeometryOperation(ToJTS.NAME, new MultiPointToJTS(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
67

  
68
		manager.registerGeometryOperation(ToJTS.NAME, new MultiCurveToJTS(), TYPES.MULTICURVE, SUBTYPES.GEOM2D);
69

  
70
		manager.registerGeometryOperation(ToJTS.NAME, new MultiSurfaceToJTS(), TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
71
	}
72

  
73
	public void testPoint() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
74
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
75
		point.setCoordinateAt(0, 1.0);
76
		point.setCoordinateAt(1, 2.0);
77

  
78
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
79

  
80
		Object obj = point.invokeOperation(ToJTS.CODE, ctx);
81
		assertNotNull(obj);
82
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Point);
83
		assertEquals(1.0, ((com.vividsolutions.jts.geom.Point)obj).getX(), 0.0);
84
		assertEquals(2.0, ((com.vividsolutions.jts.geom.Point)obj).getY(), 0.0);
85
	}
86
	
87
	public void testMultiPoint() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
88
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
89
		point1.setCoordinateAt(0, 1.0);
90
		point1.setCoordinateAt(1, 2.0);
91
		point1.setCoordinateAt(2, 3.0);
92
		
93
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
94
		point2.setCoordinateAt(0, 4.0);
95
		point2.setCoordinateAt(1, 5.0);
96
		point2.setCoordinateAt(2, 6.0);
97
		
98
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
99
		multiPoint.addPoint(point1);
100
		multiPoint.addPoint(point2);
101
		
102
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
103

  
104
		Object obj = multiPoint.invokeOperation(ToJTS.CODE, ctx);
105
		assertNotNull(obj);
106
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPoint);
107
		com.vividsolutions.jts.geom.MultiPoint gtMultiPoint = (com.vividsolutions.jts.geom.MultiPoint)obj;
108
		assertEquals(2, (int)gtMultiPoint.getNumGeometries());
109
	}
110

  
111
	public void testLineString() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
112
		Curve lineString = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
113
		GeneralPathX generalPathX = new GeneralPathX();
114
		generalPathX.moveTo(0, 0);
115
		generalPathX.lineTo(1, 1);
116
		generalPathX.lineTo(2, 1);		
117
		lineString.setGeneralPath(generalPathX);	
118

  
119
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
120

  
121
		Object obj = lineString.invokeOperation(ToJTS.CODE, ctx);
122
		assertNotNull(obj);
123
		assertTrue(obj instanceof com.vividsolutions.jts.geom.LineString);
124
		com.vividsolutions.jts.geom.LineString gtLineString = (com.vividsolutions.jts.geom.LineString)obj;
125
		assertEquals(0, gtLineString.getCoordinates()[0].x, 0.0);
126
		assertEquals(0, gtLineString.getCoordinates()[0].y, 0.0);
127
		assertEquals(0, gtLineString.getCoordinates()[1].x, 1.0);
128
		assertEquals(0, gtLineString.getCoordinates()[1].y, 1.0);
129
		assertEquals(0, gtLineString.getCoordinates()[2].x, 2.0);
130
		assertEquals(0, gtLineString.getCoordinates()[2].y, 2.0);
131
	}
132

  
133
	public void testPolygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
134
		Surface polygon = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
135
		GeneralPathX generalPathX = new GeneralPathX();
136
		generalPathX.moveTo(0, 0);
137
		generalPathX.lineTo(1, 1);
138
		generalPathX.lineTo(2, 1);
139
		polygon.setGeneralPath(generalPathX);	
140

  
141
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
142

  
143
		Object obj = polygon.invokeOperation(ToJTS.CODE, ctx);
144
		assertNotNull(obj);
145
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Polygon);
146
		com.vividsolutions.jts.geom.Polygon gtPolygon = (com.vividsolutions.jts.geom.Polygon)obj;
147
		assertEquals(0, gtPolygon.getCoordinates()[0].x, 0.0);
148
		assertEquals(0, gtPolygon.getCoordinates()[0].y, 0.0);
149
		assertEquals(0, gtPolygon.getCoordinates()[1].x, 1.0);
150
		assertEquals(0, gtPolygon.getCoordinates()[1].y, 1.0);
151
		assertEquals(0, gtPolygon.getCoordinates()[2].x, 2.0);
152
		assertEquals(0, gtPolygon.getCoordinates()[2].y, 2.0);
153
	}
154

  
155
	public void testMultiLineString() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
156
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
157
		GeneralPathX generalPathX1 = new GeneralPathX();
158
		generalPathX1.moveTo(0, 0);
159
		generalPathX1.lineTo(1, 1);
160
		generalPathX1.lineTo(2, 1);		
161
		curve1.setGeneralPath(generalPathX1);	
162

  
163
		Curve curve2 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
164
		GeneralPathX generalPathX2 = new GeneralPathX();
165
		generalPathX2.moveTo(0, 0);
166
		generalPathX2.lineTo(1, 1);
167
		generalPathX2.lineTo(2, 1);		
168
		curve2.setGeneralPath(generalPathX2);	
169

  
170
		MultiCurve multiCurve = (MultiCurve)manager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
171
		multiCurve.addCurve(curve1);
172
		multiCurve.addCurve(curve2);
173

  
174
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
175

  
176
		Object obj = multiCurve.invokeOperation(ToJTS.CODE, ctx);
177
		assertNotNull(obj);
178
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiLineString);
179
		com.vividsolutions.jts.geom.MultiLineString gtMultiLineString = (com.vividsolutions.jts.geom.MultiLineString)obj;
180
		assertEquals(2, (int)gtMultiLineString.getNumGeometries());
181
	}
182
	
183
	public void testMultiPlygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
184
		Surface surface1 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
185
		GeneralPathX generalPathX1 = new GeneralPathX();
186
		generalPathX1.moveTo(0, 0);
187
		generalPathX1.lineTo(1, 1);
188
		generalPathX1.lineTo(2, 1);		
189
		surface1.setGeneralPath(generalPathX1);	
190
		
191
		Surface surface2 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);		
192
		GeneralPathX generalPathX2 = new GeneralPathX();
193
		generalPathX2.moveTo(0, 0);
194
		generalPathX2.lineTo(1, 1);
195
		generalPathX2.lineTo(2, 1);		
196
		surface2.setGeneralPath(generalPathX2);	
197
		
198
		MultiSurface multiPolygon = (MultiSurface)manager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
199
		multiPolygon.addSurface(surface1);
200
		multiPolygon.addSurface(surface2);
201

  
202
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
203

  
204
		Object obj = multiPolygon.invokeOperation(ToJTS.CODE, ctx);
205
		assertNotNull(obj);
206
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPolygon);
207
		com.vividsolutions.jts.geom.MultiPolygon gtMultiPolygon = (com.vividsolutions.jts.geom.MultiPolygon)obj;
208
		assertEquals(2, (int)gtMultiPolygon.getNumGeometries());
209
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
210
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
211
	}
212

  
213
}
214

  
0 215

  
tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/println/PrintMultiPoint.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.operation.println;
29

  
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.aggregate.MultiPoint;
35
import org.gvsig.fmap.geom.operation.GeometryOperation;
36
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
37
import org.gvsig.fmap.geom.operation.GeometryOperationException;
38
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
39
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
40
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
41
import org.gvsig.tools.locator.LocatorException;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class PrintMultiPoint extends GeometryOperation {
47

  
48
	public PrintMultiPoint() {
49
		super();
50
		// TODO Auto-generated constructor stub
51
	}
52

  
53
	/* (non-Javadoc)
54
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
55
	 */
56
	public int getOperationIndex() {
57
		try {
58
			return GeometryLocator.getGeometryManager()
59
			.registerGeometryOperation("println", new PrintPoint(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
60
		} catch (LocatorException e) {
61
			// TODO Auto-generated catch block
62
			e.printStackTrace();
63
		} catch (GeometryTypeNotSupportedException e) {
64
			// TODO Auto-generated catch block
65
			e.printStackTrace();
66
		} catch (GeometryTypeNotValidException e) {
67
			// TODO Auto-generated catch block
68
			e.printStackTrace();
69
		}
70
		return -1;
71
	}
72

  
73
	/* (non-Javadoc)
74
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
75
	 */
76
	public Object invoke(Geometry geom, GeometryOperationContext ctx)
77
			throws GeometryOperationException {
78
		MultiPoint multiPoint = (MultiPoint)geom;
79
		System.out.println("MultiPoint");
80
		for (int i=0 ; i<multiPoint.getPrimitivesNumber() ; i++){
81
			try {
82
				System.out.print(" - ");
83
				multiPoint.getPointAt(i).invokeOperation(getOperationIndex(), ctx);
84
			} catch (GeometryOperationNotSupportedException e) {
85
				// TODO Auto-generated catch block
86
				e.printStackTrace();
87
			}
88
		}
89
		return "println-multipoint";
90
	}	
91
	
92
	
93
}
94

  
95

  
96

  
0 97

  
tags/v2_0_0_Build_2047/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/println/PrintPoint.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.operation.println;
29

  
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.operation.GeometryOperation;
35
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
39
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
40
import org.gvsig.tools.locator.LocatorException;
41

  
42
/**
43
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
44
 */
45
public class PrintPoint extends GeometryOperation {
46
	
47
	
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff