Revision 2204 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

View differences:

ArcExtendLineOperation.java
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23 23
 */
24

  
25 24
package org.gvsig.vectorediting.lib.prov.extendline.operation;
26 25

  
27 26
import org.gvsig.fmap.dal.exception.DataException;
28 27
import org.gvsig.fmap.dal.feature.FeatureSelection;
28
import org.gvsig.fmap.geom.Geometry;
29 29
import org.gvsig.fmap.geom.Geometry.TYPES;
30 30
import org.gvsig.fmap.geom.GeometryLocator;
31 31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.geom.GeometryUtils;
32 33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
33 34
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34 35
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
......
43 44
public class ArcExtendLineOperation implements ExtendLineOperation {
44 45

  
45 46
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
46
        FeatureSelection boundaryObjects)
47
        throws GeometryOperationNotSupportedException,
48
        GeometryOperationException, DataException, CreateGeometryException {
47
            FeatureSelection boundaryObjects)
48
            throws GeometryOperationNotSupportedException,
49
            GeometryOperationException, DataException, CreateGeometryException {
49 50

  
50 51
        Arc arcToBeExtend = (Arc) lineToExtend;
51 52

  
......
60 61
        Point endIntersectionPoint = null;
61 62

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

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

  
74 75
        if (startIntersectionPoint == null) {
......
81 82

  
82 83
        Point center = arcToBeExtend.getCenterPoint();
83 84
        double radius = center.distance(arcToBeExtend.getInitPoint());
84
        double startAngle =
85
            ExtendLineOperationUtils.getAngle(center, startIntersectionPoint);
86
        double endAngle =
87
            ExtendLineOperationUtils.getAngle(center, endIntersectionPoint);
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);
88 93

  
89 94
        extendedArc.setPointsStartEnd(center, radius, startAngle, endAngle);
90 95
        return extendedArc;
91 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
    }
92 151
}

Also available in: Unified diff