svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 1100
History | View | Annotate | Download (4.44 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.core; |
42 |
|
43 |
import org.cresques.cts.ICoordTrans; |
44 |
|
45 |
import java.awt.Rectangle; |
46 |
import java.awt.geom.AffineTransform; |
47 |
import java.awt.geom.PathIterator; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
|
51 |
|
52 |
/**
|
53 |
* Punto 2D.
|
54 |
*
|
55 |
* @author Vicente Caballero Navarro
|
56 |
*/
|
57 |
public class FPoint2D implements FShape { |
58 |
protected Point2D p; |
59 |
|
60 |
/**
|
61 |
* Crea un nuevo Point2D.
|
62 |
*
|
63 |
* @param x Coordenada x del punto.
|
64 |
* @param y Coordenada y del punto.
|
65 |
*/
|
66 |
public FPoint2D(double x, double y) { |
67 |
p = new Point2D.Double(x, y); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
|
72 |
* par?metro.
|
73 |
*
|
74 |
* @param at Matriz de transformaci?n.
|
75 |
*/
|
76 |
public void transform(AffineTransform at) { |
77 |
at.transform(p, p); |
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see java.awt.Shape#contains(double, double)
|
82 |
*/
|
83 |
public boolean contains(double x, double y) { |
84 |
if ((x == p.getX()) || (y == p.getY())) {
|
85 |
return true; |
86 |
} else {
|
87 |
return false; |
88 |
} |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see java.awt.Shape#contains(double, double, double, double)
|
93 |
*/
|
94 |
public boolean contains(double x, double y, double w, double h) { |
95 |
return false; |
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see java.awt.Shape#intersects(double, double, double, double)
|
100 |
*/
|
101 |
public boolean intersects(double x, double y, double w, double h) { |
102 |
Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
103 |
|
104 |
return rAux.contains(p.getX(), p.getY());
|
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see java.awt.Shape#getBounds()
|
109 |
*/
|
110 |
public Rectangle getBounds() { |
111 |
return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Devuelve la coordenada x del punto.
|
116 |
*
|
117 |
* @return Coordenada x.
|
118 |
*/
|
119 |
public double getX() { |
120 |
return p.getX();
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Devuelve la coordenada y del punto.
|
125 |
*
|
126 |
* @return Coordenada y.
|
127 |
*/
|
128 |
public double getY() { |
129 |
return p.getY();
|
130 |
} |
131 |
|
132 |
/* (non-Javadoc)
|
133 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
134 |
*/
|
135 |
public boolean contains(Point2D p) { |
136 |
return false; |
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see java.awt.Shape#getBounds2D()
|
141 |
*/
|
142 |
public Rectangle2D getBounds2D() { |
143 |
return new Rectangle2D.Double(p.getX(), p.getY(), 0, 0); |
144 |
} |
145 |
|
146 |
/* (non-Javadoc)
|
147 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
148 |
*/
|
149 |
public boolean contains(Rectangle2D r) { |
150 |
return false; |
151 |
} |
152 |
|
153 |
/* (non-Javadoc)
|
154 |
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
|
155 |
*/
|
156 |
public boolean intersects(Rectangle2D r) { |
157 |
return r.contains(this.p); |
158 |
} |
159 |
|
160 |
/* (non-Javadoc)
|
161 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
162 |
*/
|
163 |
public PathIterator getPathIterator(AffineTransform at) { |
164 |
return new FPointIterator(p, at); |
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
|
169 |
*/
|
170 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
171 |
return new FPointIterator(p, at); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
176 |
*/
|
177 |
public int getShapeType() { |
178 |
return FShape.POINT;
|
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
183 |
*/
|
184 |
public FShape cloneFShape() {
|
185 |
return new FPoint2D(p.getX(), p.getY()); |
186 |
} |
187 |
|
188 |
/* (non-Javadoc)
|
189 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
190 |
*/
|
191 |
public void reProject(ICoordTrans ct) { |
192 |
p = ct.convert(p, p); |
193 |
} |
194 |
} |