Statistics
| Revision:

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

History | View | Annotate | Download (4.58 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 CurveTest 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 testCreateCurve2D() throws InstantiationException, IllegalAccessException{
67
                Curve curve = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
68
                GeneralPathX generalPathX = new GeneralPathX();
69
                generalPathX.moveTo(0, 0);
70
                generalPathX.lineTo(1, 1);
71
                generalPathX.lineTo(2, 1);                
72
                curve.setGeneralPath(generalPathX);        
73
                
74
                Assert.assertEquals(0.0, curve.getCoordinateAt(0,0),0);
75
                Assert.assertEquals(0.0, curve.getCoordinateAt(0,1),0);
76
                Assert.assertEquals(1.0, curve.getCoordinateAt(1,0),0);
77
                Assert.assertEquals(1.0, curve.getCoordinateAt(1,1),0);
78
                Assert.assertEquals(2.0, curve.getCoordinateAt(2,0),0);
79
                Assert.assertEquals(1.0, curve.getCoordinateAt(2,1),0);
80
                
81
                AffineTransform at = new AffineTransform();
82
            at.translate(1, 1);
83
                curve.transform(at);
84
                
85
                Assert.assertEquals(1.0, curve.getCoordinateAt(0,0),0);
86
                Assert.assertEquals(1.0, curve.getCoordinateAt(0,1),0);
87
                Assert.assertEquals(2.0, curve.getCoordinateAt(1,0),0);
88
                Assert.assertEquals(2.0, curve.getCoordinateAt(1,1),0);
89
                Assert.assertEquals(3.0, curve.getCoordinateAt(2,0),0);
90
                Assert.assertEquals(2.0, curve.getCoordinateAt(2,1),0);
91
                                
92
                PathIterator iterator = curve.getPathIterator(at);
93
                double[] coords = new double[3];
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
        public void testCreateCurve2DZ() throws InstantiationException, IllegalAccessException{
104
                Curve curve = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2DZ);
105
                GeneralPathX generalPathX = new GeneralPathX();
106
                generalPathX.moveTo(0, 0);
107
                generalPathX.lineTo(1, 1);
108
                generalPathX.lineTo(2, 1);
109
                curve.setGeneralPath(generalPathX);        
110
                
111
                Assert.assertEquals(0.0, curve.getCoordinateAt(0,0),0);
112
                Assert.assertEquals(0.0, curve.getCoordinateAt(0,1),0);
113
                Assert.assertEquals(1.0, curve.getCoordinateAt(1,0),0);
114
                Assert.assertEquals(1.0, curve.getCoordinateAt(1,1),0);
115
                Assert.assertEquals(2.0, curve.getCoordinateAt(2,0),0);
116
                Assert.assertEquals(1.0, curve.getCoordinateAt(2,1),0);
117
                
118
                AffineTransform at = new AffineTransform();
119
            at.translate(1, 1);
120
                curve.transform(at);
121
                
122
                Assert.assertEquals(1.0, curve.getCoordinateAt(0,0),0);
123
                Assert.assertEquals(1.0, curve.getCoordinateAt(0,1),0);
124
                Assert.assertEquals(2.0, curve.getCoordinateAt(1,0),0);
125
                Assert.assertEquals(2.0, curve.getCoordinateAt(1,1),0);
126
                Assert.assertEquals(3.0, curve.getCoordinateAt(2,0),0);
127
                Assert.assertEquals(2.0, curve.getCoordinateAt(2,1),0);
128
                                
129
                PathIterator iterator = curve.getPathIterator(at);
130
                double[] coords = new double[2];
131
                int i=0;
132
                while (!iterator.isDone()){
133
                        i++;
134
                        iterator.next();
135
                        iterator.currentSegment(coords);                        
136
                }
137
                Assert.assertEquals(3, i);                
138

    
139
        }
140
}
141

    
142