Statistics
| Revision:

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

History | View | Annotate | Download (5.2 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.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