Statistics
| Revision:

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

History | View | Annotate | Download (4.51 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
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.next();
88
                        iterator.currentSegment(coords);                        
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.next();
125
                        iterator.currentSegment(coords);                        
126
                }
127
                Assert.assertEquals(3, i);                
128

    
129
        }
130
}
131

    
132