Statistics
| Revision:

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 @ 2211

History | View | Annotate | Download (5.28 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
                = GeometryUtils.calculateAngle(center, startIntersectionPoint);
87
        double endAngle
88
                = GeometryUtils.calculateAngle(center, endIntersectionPoint);
89

    
90
        extendedArc.setPointsStartEnd(center, radius, startAngle, endAngle);
91
        return extendedArc;
92
    }
93

    
94
    @Override
95
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
96
            Geometry boundaryObject)
97
            throws GeometryOperationNotSupportedException,
98
            GeometryOperationException, DataException, CreateGeometryException {
99
        
100
        Arc arcToBeExtend = (Arc) lineToExtend;
101

    
102
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
103
        int subtype = lineToExtend.getGeometryType().getSubType();
104
        Arc extendedArc = (Arc) geoManager.create(TYPES.ARC, subtype);
105

    
106
        Point startVertex = arcToBeExtend.getInitPoint();
107
        Point endVertex = arcToBeExtend.getEndPoint();
108
        Point midVertex = arcToBeExtend.getMiddlePoint();
109
        
110
        Point startIntersectionPoint = null;
111
        Point endIntersectionPoint = null;
112

    
113
        if (insertedPoint.distance(startVertex) < insertedPoint
114
                .distance(endVertex)) {
115
            startIntersectionPoint
116
                    = ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
117
                            ExtendLineOperationUtils.START_SIDE, boundaryObject);
118

    
119
        } else {
120
            endIntersectionPoint
121
                    = ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
122
                            ExtendLineOperationUtils.END_SIDE, boundaryObject);
123
        }
124

    
125
        if (startIntersectionPoint == null) {
126
            startIntersectionPoint = arcToBeExtend.getInitPoint();
127
        }
128

    
129
        if (endIntersectionPoint == null) {
130
            endIntersectionPoint = arcToBeExtend.getEndPoint();
131
        }
132
        
133
          extendedArc.setPoints(startIntersectionPoint, midVertex, endIntersectionPoint);
134
        return extendedArc;
135
    }
136
    
137
}