Statistics
| Revision:

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

History | View | Annotate | Download (3.45 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.GeometryLibrary;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.GeometryManager;
39
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
40
import org.gvsig.fmap.geom.Geometry.TYPES;
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 PointTest 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
                GeometryLibrary lib = new GeometryLibrary();                
60
                lib.initialize();
61
                lib.postInitialize();
62
                
63
                manager = GeometryLocator.getGeometryManager();
64
        }
65
        
66
        public void testCreatePoint2D() throws InstantiationException, IllegalAccessException{
67
                Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
68
                point.setCoordinateAt(0, 1.0);
69
                point.setCoordinateAt(1, 2.0);
70
                
71
                AffineTransform at = new AffineTransform();
72
            at.translate(1, 1);
73
                point.transform(at);
74
                
75
                Assert.assertEquals(2.0, point.getCoordinateAt(0),0);
76
                Assert.assertEquals(3.0, point.getCoordinateAt(1),0);
77
                
78
                PathIterator iterator = point.getPathIterator(at);
79
                double[] coords = new double[2];
80
                int i=0;
81
                while (!iterator.isDone()){
82
                        i++;
83
                        iterator.next();
84
                        iterator.currentSegment(coords);                        
85
                }
86
                Assert.assertEquals(1, i);
87
                Assert.assertEquals(3.0, coords[0], 0);
88
                Assert.assertEquals(4.0, coords[1] ,0);
89
        }
90
        
91
        public void testCreatePoint2DZ() throws InstantiationException, IllegalAccessException{
92
                Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2DZ);
93
                point.setCoordinateAt(0, 1.0);
94
                point.setCoordinateAt(1, 2.0);
95
                point.setCoordinateAt(2, 3.0);
96
                
97
                AffineTransform at = new AffineTransform();
98
            at.translate(1, 1);
99
                point.transform(at);
100
                
101
                Assert.assertEquals(2.0, point.getCoordinateAt(0),0);
102
                Assert.assertEquals(3.0, point.getCoordinateAt(1),0);
103
                Assert.assertEquals(3.0, point.getCoordinateAt(2),0);
104
                
105
                PathIterator iterator = point.getPathIterator(at);
106
                double[] coords = new double[2];
107
                int i=0;
108
                while (!iterator.isDone()){
109
                        i++;
110
                        iterator.next();
111
                        iterator.currentSegment(coords);                        
112
                }
113
                Assert.assertEquals(1, i);
114
                Assert.assertEquals(3.0, coords[0], 0);
115
                Assert.assertEquals(4.0, coords[1] ,0);
116
        }
117
}
118