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

History | View | Annotate | Download (3.2 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
    public Curve[] split(Geometry geometry, Point projectedPoint)
44
        throws CreateGeometryException, GeometryOperationNotSupportedException,
45
        GeometryOperationException {
46

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

    
50
        Arc arcToSplit = (Arc) geometry;
51

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

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

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

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

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

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

    
80
}