root / tags / v2_0_0_Build_2059 / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / primitive / ArcTest.java @ 39313
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.primitive; |
29 |
|
30 |
import java.awt.geom.Rectangle2D; |
31 |
|
32 |
import junit.framework.Assert; |
33 |
|
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
35 |
import org.gvsig.fmap.geom.GeometryManager; |
36 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
37 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
38 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
39 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
/**
|
44 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
45 |
*/
|
46 |
public class ArcTest extends AbstractLibraryAutoInitTestCase { |
47 |
private GeometryManager manager;
|
48 |
|
49 |
final static private Logger logger = LoggerFactory.getLogger("org.gvsig"); |
50 |
|
51 |
protected void doSetUp() throws Exception { |
52 |
manager = GeometryLocator.getGeometryManager(); |
53 |
} |
54 |
|
55 |
public void testCreateArc2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{ |
56 |
Arc arc = (Arc)manager.create(TYPES.ARC, SUBTYPES.GEOM2D); |
57 |
GeneralPathX generalPathX = new GeneralPathX();
|
58 |
Exception e = null; |
59 |
try{
|
60 |
arc.setGeneralPath(generalPathX); |
61 |
}catch (UnsupportedOperationException e1){ |
62 |
e = e1; |
63 |
} |
64 |
Assert.assertTrue(e instanceof UnsupportedOperationException); |
65 |
|
66 |
|
67 |
Point initPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
68 |
initPoint.setCoordinateAt(0, 1); |
69 |
initPoint.setCoordinateAt(1, 1); |
70 |
|
71 |
Point middle = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
72 |
middle.setCoordinateAt(0, 0); |
73 |
middle.setCoordinateAt(1, 0); |
74 |
|
75 |
|
76 |
Point endPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
77 |
endPoint.setCoordinateAt(0, 0); |
78 |
endPoint.setCoordinateAt(1, 1); |
79 |
|
80 |
arc.setPoints(initPoint, middle, endPoint); |
81 |
|
82 |
assertEquals(0.5, arc.getCenterPoint().getX(), 0); |
83 |
assertEquals(0.5, arc.getCenterPoint().getY(), 0); |
84 |
assertEquals(1.0, arc.getInitPoint().getX(), 0); |
85 |
assertEquals(1.0, arc.getInitPoint().getY(), 0); |
86 |
assertEquals(0, arc.getEndPoint().getX(), 0); |
87 |
assertEquals(1, arc.getEndPoint().getY(), 0); |
88 |
|
89 |
// =================================
|
90 |
|
91 |
double deg_rad = Math.PI / 180.0; |
92 |
Point cp = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
93 |
cp.setX(10);
|
94 |
cp.setY(2);
|
95 |
|
96 |
arc.setPointsStartExt(cp, 5, 45*deg_rad, 135*deg_rad); |
97 |
assertEquals(10, arc.getEndPoint().getX(), 0.000001); |
98 |
assertEquals(-3, arc.getEndPoint().getY(), 0.000001); |
99 |
|
100 |
Rectangle2D rect = new Rectangle2D.Double(0, 0, 9, 9); |
101 |
|
102 |
arc.setPointsStartEnd(cp, 5, 45*deg_rad, -90*deg_rad); |
103 |
assertFalse(arc.intersects(rect)); |
104 |
|
105 |
arc.setPointsStartEnd(cp, 5, 45*deg_rad, 5d*Math.PI/2d); |
106 |
assertTrue(arc.intersects(rect)); |
107 |
|
108 |
} |
109 |
|
110 |
|
111 |
|
112 |
} |
113 |
|
114 |
|
115 |
|