gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.extendline / src / main / java / org / gvsig / vectorediting / lib / prov / extendline / operation / ArcExtendLineOperation.java @ 2204
History | View | Annotate | Download (5.96 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2015 gvSIG Association
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.vectorediting.lib.prov.extendline.operation; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
28 |
import org.gvsig.fmap.geom.Geometry; |
29 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 |
import org.gvsig.fmap.geom.GeometryManager; |
32 |
import org.gvsig.fmap.geom.GeometryUtils; |
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
35 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
36 |
import org.gvsig.fmap.geom.primitive.Arc; |
37 |
import org.gvsig.fmap.geom.primitive.Curve; |
38 |
import org.gvsig.fmap.geom.primitive.Point; |
39 |
|
40 |
/**
|
41 |
* @author llmarques
|
42 |
*
|
43 |
*/
|
44 |
public class ArcExtendLineOperation implements ExtendLineOperation { |
45 |
|
46 |
public Curve extendLine(Curve lineToExtend, Point insertedPoint, |
47 |
FeatureSelection boundaryObjects) |
48 |
throws GeometryOperationNotSupportedException,
|
49 |
GeometryOperationException, DataException, CreateGeometryException { |
50 |
|
51 |
Arc arcToBeExtend = (Arc) lineToExtend; |
52 |
|
53 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
54 |
int subtype = lineToExtend.getGeometryType().getSubType();
|
55 |
Arc extendedArc = (Arc) geoManager.create(TYPES.ARC, subtype); |
56 |
|
57 |
Point startVertex = arcToBeExtend.getInitPoint();
|
58 |
Point endVertex = arcToBeExtend.getEndPoint();
|
59 |
|
60 |
Point startIntersectionPoint = null; |
61 |
Point endIntersectionPoint = null; |
62 |
|
63 |
if (insertedPoint.distance(startVertex) < insertedPoint
|
64 |
.distance(endVertex)) { |
65 |
startIntersectionPoint |
66 |
= ExtendLineOperationUtils.arcIntersection(arcToBeExtend, |
67 |
ExtendLineOperationUtils.START_SIDE, boundaryObjects); |
68 |
|
69 |
} else {
|
70 |
endIntersectionPoint |
71 |
= ExtendLineOperationUtils.arcIntersection(arcToBeExtend, |
72 |
ExtendLineOperationUtils.END_SIDE, boundaryObjects); |
73 |
} |
74 |
|
75 |
if (startIntersectionPoint == null) { |
76 |
startIntersectionPoint = arcToBeExtend.getInitPoint(); |
77 |
} |
78 |
|
79 |
if (endIntersectionPoint == null) { |
80 |
endIntersectionPoint = arcToBeExtend.getEndPoint(); |
81 |
} |
82 |
|
83 |
Point center = arcToBeExtend.getCenterPoint();
|
84 |
double radius = center.distance(arcToBeExtend.getInitPoint());
|
85 |
// double startAngle
|
86 |
// = ExtendLineOperationUtils.getAngle(center, startIntersectionPoint);
|
87 |
// double endAngle
|
88 |
// = ExtendLineOperationUtils.getAngle(center, endIntersectionPoint);
|
89 |
double startAngle
|
90 |
= GeometryUtils.calculateAngle(center, startIntersectionPoint); |
91 |
double endAngle
|
92 |
= GeometryUtils.calculateAngle(center, endIntersectionPoint); |
93 |
|
94 |
extendedArc.setPointsStartEnd(center, radius, startAngle, endAngle); |
95 |
return extendedArc;
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public Curve extendLine(Curve lineToExtend, Point insertedPoint, |
100 |
Geometry boundaryObject) |
101 |
throws GeometryOperationNotSupportedException,
|
102 |
GeometryOperationException, DataException, CreateGeometryException { |
103 |
|
104 |
Arc arcToBeExtend = (Arc) lineToExtend; |
105 |
|
106 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
107 |
int subtype = lineToExtend.getGeometryType().getSubType();
|
108 |
Arc extendedArc = (Arc) geoManager.create(TYPES.ARC, subtype); |
109 |
|
110 |
Point startVertex = arcToBeExtend.getInitPoint();
|
111 |
Point endVertex = arcToBeExtend.getEndPoint();
|
112 |
|
113 |
Point startIntersectionPoint = null; |
114 |
Point endIntersectionPoint = null; |
115 |
|
116 |
if (insertedPoint.distance(startVertex) < insertedPoint
|
117 |
.distance(endVertex)) { |
118 |
startIntersectionPoint |
119 |
= ExtendLineOperationUtils.arcIntersection(arcToBeExtend, |
120 |
ExtendLineOperationUtils.START_SIDE, boundaryObject); |
121 |
|
122 |
} else {
|
123 |
endIntersectionPoint |
124 |
= ExtendLineOperationUtils.arcIntersection(arcToBeExtend, |
125 |
ExtendLineOperationUtils.END_SIDE, boundaryObject); |
126 |
} |
127 |
|
128 |
if (startIntersectionPoint == null) { |
129 |
startIntersectionPoint = arcToBeExtend.getInitPoint(); |
130 |
} |
131 |
|
132 |
if (endIntersectionPoint == null) { |
133 |
endIntersectionPoint = arcToBeExtend.getEndPoint(); |
134 |
} |
135 |
|
136 |
Point center = arcToBeExtend.getCenterPoint();
|
137 |
double radius = center.distance(arcToBeExtend.getInitPoint());
|
138 |
// double startAngle
|
139 |
// = ExtendLineOperationUtils.getAngle(center, startIntersectionPoint);
|
140 |
// double endAngle
|
141 |
// = ExtendLineOperationUtils.getAngle(center, endIntersectionPoint);
|
142 |
double startAngle
|
143 |
= GeometryUtils.calculateAngle(center, startIntersectionPoint); |
144 |
double endAngle
|
145 |
= GeometryUtils.calculateAngle(center, endIntersectionPoint); |
146 |
|
147 |
|
148 |
extendedArc.setPointsStartEnd(center, radius, startAngle, endAngle); |
149 |
return extendedArc;
|
150 |
} |
151 |
} |