Class MidpointSplitPointFinder

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12  
13 package org.locationtech.jts.triangulate;
14  
15  
16 import org.locationtech.jts.geom.Coordinate;
17  
18 /**
19  * A simple split point finder which returns the midpoint of the split segment. This is a default
20  * strategy only. Usually a more sophisticated strategy is required to prevent repeated splitting.
21  * Other points which could be used are:
22  * <ul>
23  * <li>The projection of the encroaching point on the segment
24  * <li>A point on the segment which will produce two segments which will not be further encroached
25  * <li>The point on the segment which is the same distance from an endpoint as the encroaching
26  * point
27  * </ul>
28  * 
29  * @author Martin Davis
30  */
31 public class MidpointSplitPointFinder implements ConstraintSplitPointFinder {
32     /**
33      * Gets the midpoint of the split segment
34      */
35     public Coordinate findSplitPoint(Segment seg, Coordinate encroachPt) {
36         Coordinate p0 = seg.getStart();
37         Coordinate p1 = seg.getEnd();
38         return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
39     }
40  
41 }
42