Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / GeometryAPITest.java @ 39365

History | View | Annotate | Download (3.57 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;
29

    
30
import java.awt.geom.Rectangle2D;
31

    
32
import junit.framework.Assert;
33

    
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.fmap.geom.exception.CreateGeometryException;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40
import org.gvsig.fmap.geom.primitive.Point;
41
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
42

    
43
/**
44
 * Tests some methods in geometry API with various instances.
45
 * 
46
 * @author jldominguez
47
 *
48
 */
49
public class GeometryAPITest extends AbstractLibraryAutoInitTestCase {
50
        private GeometryManager manager;
51
        
52
        final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
53

    
54
        protected void doSetUp() throws Exception {
55
                manager = GeometryLocator.getGeometryManager();                
56
        }
57
        
58
        public void testMethods() throws InstantiationException, IllegalAccessException, CreateGeometryException{
59

    
60
            try {
61
            Envelope env0 = manager.createEnvelope(0,0,1,1, SUBTYPES.GEOM2D);
62
            Envelope env1 = manager.createEnvelope(2,0,3,1, SUBTYPES.GEOM2D);
63
            Geometry g0 = env0.getGeometry();
64
            Geometry g1 = env1.getGeometry();
65
            Geometry gm = g0.union(g1);
66
            
67
            gm.move(-2,2);
68
            
69
            double cxy = gm.getBounds2D().getCenterX()
70
                *gm.getBounds2D().getCenterY();
71
            // test move ============================
72
            Assert.assertEquals(-1.25, cxy, 0.0000000001);
73
            // ==========================================
74
            
75
            gm.move(2,-2);
76
            gm.rotate(30.0*Math.PI/180.0, 0,1);
77
            
78
            double maxy = 1 + 3 * Math.sin(30.0*Math.PI/180.0);
79
            // test rotation ============================
80
            Assert.assertEquals(maxy, gm.getBounds2D().getMaxY(), 0.0000000001);
81
            // ==========================================
82
            
83
            
84
            gm.rotate(-30.0*Math.PI/180.0, 0,1);
85
            Point p = manager.createPoint(1.5, 0.5, SUBTYPES.GEOM2D);
86
            gm.scale(p, 0.5, 1.5);
87
            
88
            Rectangle2D bb = gm.getBounds2D();
89
            // test scale ============================
90
            Assert.assertEquals(0.75, bb.getMinX(), 0.0000000001);
91
            Assert.assertEquals(-0.25, bb.getMinY(), 0.0000000001);
92
            Assert.assertEquals(2.25, bb.getMaxX(), 0.0000000001);
93
            Assert.assertEquals(1.25, bb.getMaxY(), 0.0000000001);
94
            // =======================================
95
            
96
        } catch (Exception e) {
97
            logger.info("Error while checking Geometry API.", e);
98
            Assert.assertTrue(e == null);
99
        }
100

    
101
        }        
102
}
103