Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / primitive / SurfaceTest.java @ 35472

History | View | Annotate | Download (3.06 KB)

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