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.splitline / src / main / java / org / gvsig / vectorediting / lib / prov / splitline / operation / ArcSplitLineOperation.java @ 2616

History | View | Annotate | Download (3.22 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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

    
25
package org.gvsig.vectorediting.lib.prov.splitline.operation;
26

    
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryLocator;
29
import org.gvsig.fmap.geom.GeometryManager;
30
import org.gvsig.fmap.geom.exception.CreateGeometryException;
31
import org.gvsig.fmap.geom.operation.GeometryOperationException;
32
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
33
import org.gvsig.fmap.geom.primitive.Arc;
34
import org.gvsig.fmap.geom.primitive.Curve;
35
import org.gvsig.fmap.geom.primitive.Point;
36

    
37
/**
38
 * @author llmarques
39
 *
40
 */
41
public class ArcSplitLineOperation implements SplitLineOperation {
42

    
43
    @Override
44
    public Curve[] split(Geometry geometry, Point projectedPoint)
45
        throws CreateGeometryException, GeometryOperationNotSupportedException,
46
        GeometryOperationException {
47

    
48
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
49
        int subtype = geometry.getGeometryType().getSubType();
50

    
51
        Arc arcToSplit = (Arc) geometry;
52

    
53
        Point center = arcToSplit.getCenterPoint();
54
        //Si center es null es porque dos de los puntos coinciden.
55
        if(arcToSplit.getInitPoint().equals(arcToSplit.getEndPoint())){
56
            //Si son el inicial y el final es porque es una circunferencia completa, tomamos como "center" el centro del Envelope
57
            if (center==null){
58
                center = geoManager.createPoint(arcToSplit.getEnvelope().getCenter(0), arcToSplit.getEnvelope().getCenter(1), subtype);
59
            }
60
        }
61

    
62
        Point firstPoint = arcToSplit.getInitPoint();
63
        Point endPoint = arcToSplit.getEndPoint();
64

    
65
        double startAngle =
66
            SplitLineOperationUtils.getAngle(center, firstPoint);
67
        double splitAngle =
68
            SplitLineOperationUtils.getAngle(center, projectedPoint);
69
        double endAngle = SplitLineOperationUtils.getAngle(center, endPoint);
70
        double radius = center.distance(firstPoint);
71

    
72
        Arc arcSplitted1 = (Arc) geoManager.create(Geometry.TYPES.ARC, subtype);
73
        Arc arcSplitted2 = (Arc) geoManager.create(Geometry.TYPES.ARC, subtype);
74

    
75
        arcSplitted1.setPointsStartEnd(center, radius, startAngle, splitAngle);
76
        arcSplitted2.setPointsStartEnd(center, radius, splitAngle, endAngle);
77

    
78
        return new Curve[] { arcSplitted1, arcSplitted2 };
79
    }
80

    
81
}