Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / primitive / SurfaceTest.java @ 27042

History | View | Annotate | Download (3.3 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
import junit.framework.TestCase;
35

    
36
import org.gvsig.fmap.geom.GeometryLocator;
37
import org.gvsig.fmap.geom.GeometryManager;
38
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
39
import org.gvsig.fmap.geom.Geometry.TYPES;
40
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
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 SurfaceTest extends TestCase {
48
        private GeometryManager manager;
49
        
50
        final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
51

    
52
        static {
53
                //logger.addAppender(new ConsoleAppender(new SimpleLayout()));
54
        }
55

    
56
        public void setUp() throws Exception {
57
                super.setUp();
58

    
59
                DefaultGeometryLibrary lib = new DefaultGeometryLibrary();                
60
                lib.initialize();
61
                lib.postInitialize();
62
                
63
                manager = GeometryLocator.getGeometryManager();
64
        }
65
        
66
        public void testCreateSurface2D() throws InstantiationException, IllegalAccessException{
67
                Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
68
                GeneralPathX generalPathX = new GeneralPathX();
69
                generalPathX.moveTo(0, 0);
70
                generalPathX.lineTo(1, 1);
71
                generalPathX.lineTo(2, 1);
72
                surface.setGeneralPath(generalPathX);        
73
                
74
                Assert.assertEquals(0.0, surface.getCoordinateAt(0,0),0);
75
                Assert.assertEquals(0.0, surface.getCoordinateAt(0,1),0);
76
                Assert.assertEquals(1.0, surface.getCoordinateAt(1,0),0);
77
                Assert.assertEquals(1.0, surface.getCoordinateAt(1,1),0);
78
                Assert.assertEquals(2.0, surface.getCoordinateAt(2,0),0);
79
                Assert.assertEquals(1.0, surface.getCoordinateAt(2,1),0);
80
                
81
                AffineTransform at = new AffineTransform();
82
            at.translate(1, 1);
83
            surface.transform(at);
84
                
85
                Assert.assertEquals(1.0, surface.getCoordinateAt(0,0),0);
86
                Assert.assertEquals(1.0, surface.getCoordinateAt(0,1),0);
87
                Assert.assertEquals(2.0, surface.getCoordinateAt(1,0),0);
88
                Assert.assertEquals(2.0, surface.getCoordinateAt(1,1),0);
89
                Assert.assertEquals(3.0, surface.getCoordinateAt(2,0),0);
90
                Assert.assertEquals(2.0, surface.getCoordinateAt(2,1),0);
91
                                
92
                PathIterator iterator = surface.getPathIterator(at);
93
                double[] coords = new double[2];
94
                int i=0;
95
                while (!iterator.isDone()){
96
                        i++;
97
                        iterator.next();
98
                        iterator.currentSegment(coords);                        
99
                }
100
                Assert.assertEquals(3, i);                
101

    
102
        }
103
}
104

    
105

    
106