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

History | View | Annotate | Download (5.29 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
    @Override
47
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
48
            FeatureSelection boundaryObjects)
49
            throws GeometryOperationNotSupportedException,
50
            GeometryOperationException, DataException, CreateGeometryException {
51

    
52
        Arc arcToBeExtend = (Arc) lineToExtend;
53

    
54
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
55
        int subtype = lineToExtend.getGeometryType().getSubType();
56
        Arc extendedArc = (Arc) geoManager.create(TYPES.ARC, subtype);
57

    
58
        Point startVertex = arcToBeExtend.getInitPoint();
59
        Point endVertex = arcToBeExtend.getEndPoint();
60

    
61
        Point startIntersectionPoint = null;
62
        Point endIntersectionPoint = null;
63

    
64
        if (insertedPoint.distance(startVertex) < insertedPoint
65
                .distance(endVertex)) {
66
            startIntersectionPoint
67
                    = ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
68
                            ExtendLineOperationUtils.START_SIDE, boundaryObjects);
69

    
70
        } else {
71
            endIntersectionPoint
72
                    = ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
73
                            ExtendLineOperationUtils.END_SIDE, boundaryObjects);
74
        }
75

    
76
        if (startIntersectionPoint == null) {
77
            startIntersectionPoint = arcToBeExtend.getInitPoint();
78
        }
79

    
80
        if (endIntersectionPoint == null) {
81
            endIntersectionPoint = arcToBeExtend.getEndPoint();
82
        }
83

    
84
        Point center = arcToBeExtend.getCenterPoint();
85
        double radius = center.distance(arcToBeExtend.getInitPoint());
86
        double startAngle
87
                = GeometryUtils.calculateAngle(center, startIntersectionPoint);
88
        double endAngle
89
                = GeometryUtils.calculateAngle(center, endIntersectionPoint);
90

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

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

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

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

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

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

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

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