Insert a point into a given edge. There can be only edges if there are at least 2 points in a LineString
geometry.
437397
private void insertAfterEdge(Geometry geom, GeometryIndex index, Coordinate coordinate)
			throws GeometryIndexNotFoundException {
		// First we check the geometry type:
		if (!Geometry.LINE_STRING.equals(geom.getGeometryType())
				&& !Geometry.LINEAR_RING.equals(geom.getGeometryType())) {
			throw new GeometryIndexNotFoundException("Could not match index with given geometry.");
		}
		if (index.getValue() < 0) {
			throw new GeometryIndexNotFoundException("Cannot insert in a negative index.");
		}

		// Then we check if the edge exists:
		if (geom.getCoordinates() != null && geom.getCoordinates().length > index.getValue() + 1) {
			// Inserting on edges allows only to insert on existing edges. No adding at the end:
			Coordinate[] result = new Coordinate[geom.getCoordinates().length + 1];
			int count = 0;
			for (int i = 0; i < geom.getCoordinates().length; i++) {
				if (i == (index.getValue() + 1)) {
					result[i] = coordinate;
					count++;
				}
				result[i + count] = geom.getCoordinates()[i];
			}
			geom.setCoordinates(result);
		} else {
			throw new GeometryIndexNotFoundException("Cannot insert a vertex into an edge that does not exist.");
		}
	}
1327384
void insert(Suffix<I, S> suffix) {
        if (activePoint.isNode()) {
            Node<I, S> node = activePoint.getNode();
            node.insert(suffix, activePoint);
        } else if (activePoint.isEdge()) {
            Edge<I, S> edge = activePoint.getEdge();
            edge.insert(suffix, activePoint);
        }
    }
205160
private static Polygon extrudeEdge(final Coordinate beginPoint,
            Coordinate endPoint, final double height, GeometryFactory factory) {
        beginPoint.z = Double.isNaN(beginPoint.z) ? 0 : beginPoint.z;
        endPoint.z = Double.isNaN(endPoint.z) ? 0 : endPoint.z;        
        return factory.createPolygon(new Coordinate[]{
            beginPoint,
            new Coordinate(beginPoint.x, beginPoint.y, beginPoint.z
            + height),
            new Coordinate(endPoint.x, endPoint.y, endPoint.z
            + height), endPoint, beginPoint});
    }
248150
private static Polygon insertVertexInPolygon(Polygon polygon,
            Point vertexPoint, double tolerance) throws SQLException {        
        Polygon geom =polygon;
        LineString linearRing = polygon.getExteriorRing();
        int index = -1;
        for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
            double distCurr = computeDistance(polygon.getInteriorRingN(i),vertexPoint, tolerance);
            if (distCurr<tolerance){
                index = i;
            }
        }        
        if(index==-1){
            //The point is a on the exterior ring.
            LinearRing inserted = insertVertexInLinearRing(linearRing, vertexPoint, tolerance);
            if(inserted!=null){
            LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
            for (int i = 0; i < holes.length; i++) {
                holes[i]= (LinearRing) polygon.getInteriorRingN(i);
            }
            geom = FACTORY.createPolygon(inserted, holes);
            }
        }
        else{
            //We add the vertex on the first hole
            LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
            for (int i = 0; i < holes.length; i++) {
                if (i == index) {
                    holes[i] = insertVertexInLinearRing(polygon.getInteriorRingN(i), vertexPoint, tolerance);
                } else {
                    holes[i] = (LinearRing) polygon.getInteriorRingN(i);
                }
            }
            geom = FACTORY.createPolygon((LinearRing) linearRing, holes);
        }       
        if(geom!=null){
        if (!geom.isValid()) {
            throw new SQLException("Geometry not valid");
        }
        }
        return geom;
    }
552596
def addPoint( self, x, y ):
        
        self._points.append((x, y))
        self._dirty = True
1075580
def geo_line(self, edge):
        
        with context(self.fname, edge.LineString.posList) as plist:
            coords = split_coords_2d(~plist)
        return geo.Line([geo.Point(*p) for p in coords])
47601
def _appendSegment(self, type=None, points=None, smooth=False, **kwargs):
        
        self._insertSegment(len(self), type=type, points=points,
                            smooth=smooth, **kwargs)
1029527
private static MultiLineString splitLineWithPoint(LineString line, Point pointToSplit, double tolerance) {
        return FACTORY.createMultiLineString(splitLineStringWithPoint(line, pointToSplit, tolerance));
    }
1320308
def p_edgesigs(self, p):
        ''
        p[0] = p[1] + (p[3],)
        p.set_lineno(0, p.lineno(1))
302647
def _prepPointsForSegments(points):
    
    while 1:
        point = points[-1]
        if point.segmentType:
            break
        else:
            point = points.pop()
            points.insert(0, point)
            continue
        break
932961
private static Point getShapeIntersection(Shape shape,
                                              Line2D.Double line) {
        PathIterator it = shape.getPathIterator(null);
        double[] coords = new double[6];
        double[] pos = new double[2];
        Line2D.Double l = new Line2D.Double();
        while (!it.isDone()) {
            int type = it.currentSegment(coords);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    pos[0] = coords[0];
                    pos[1] = coords[1];
                    break;
                case PathIterator.SEG_LINETO:
                    l = new Line2D.Double(pos[0],
                                          pos[1],
                                          coords[0],
                                          coords[1]);
                    if (line.intersectsLine(l)) {
                        return getLinesIntersection(line,
                                                    l);
                    }
                    pos[0] = coords[0];
                    pos[1] = coords[1];
                    break;
                case PathIterator.SEG_CLOSE:
                    break;
                default:
                    // whatever
            }
            it.next();
        }
        return null;
    }
1173542
private static Geometry splitMultiLineStringWithLine(MultiLineString input, LineString cut) {
        Geometry lines = input.difference(cut);
        //Only to preserve SQL constrains
        if (lines instanceof LineString) {
            return FACTORY.createMultiLineString(new LineString[]{(LineString) lines.getGeometryN(0)});
        }
        return lines;
    }
1160294
private static Collection<Polygon> polygonWithLineSplitter(Polygon polygon, LineString lineString) throws SQLException {
        Collection<Polygon> polygons = splitPolygonizer(polygon, lineString);
        if (polygons != null && polygons.size() > 1) {
            List<Polygon> pols = new ArrayList<Polygon>();
            for (Polygon pol : polygons) {
                if (polygon.contains(pol.getInteriorPoint())) {
                    pols.add(pol);
                }
            }
            return pols;
        }
        return null;
    }
1099109
public static LineString createLine(Geometry pointA, Geometry... optionalPoints) throws SQLException {
        if( pointA == null || optionalPoints.length > 0 && optionalPoints[0] == null) {
            return null;
        }
        if (pointA.getNumGeometries() == 1 && !atLeastTwoPoints(optionalPoints, countPoints(pointA))) {
            throw new SQLException("At least two points are required to make a line.");
        }
        List<Coordinate> coordinateList = new LinkedList<Coordinate>();
        addCoordinatesToList(pointA, coordinateList);
        for (Geometry optionalPoint : optionalPoints) {
            addCoordinatesToList(optionalPoint, coordinateList);
        }
        return ((Geometry) pointA).getFactory().createLineString(
                coordinateList.toArray(new Coordinate[optionalPoints.length]));
    }
103971
def _rewrite_geometry(geom, new_lines):
    

    new_geom = []
    x = 0
    y = 0
    for line in new_lines:
        moveto, endsat, lineto_cmds = line

        dx = moveto.x - x
        dy = moveto.y - y
        x = endsat.x
        y = endsat.y

        new_geom.append(9)  # move to, run_length = 1
        new_geom.append(zigzag(dx))
        new_geom.append(zigzag(dy))
        new_geom.extend(lineto_cmds)

    # write the lines back out to geom
    del geom[:]
    geom.extend(new_geom)
397759
final int internalEdgeAdd(int newEdgeId, int nodeA, int nodeB) {
        writeEdge(newEdgeId, nodeA, nodeB, EdgeIterator.NO_EDGE, EdgeIterator.NO_EDGE);
        long edgePointer = toPointer(newEdgeId);

        int edge = getEdgeRef(nodeA);
        if (edge > EdgeIterator.NO_EDGE)
            edges.setInt(E_LINKA + edgePointer, edge);
        setEdgeRef(nodeA, newEdgeId);

        if (nodeA != nodeB) {
            edge = getEdgeRef(nodeB);
            if (edge > EdgeIterator.NO_EDGE)
                edges.setInt(E_LINKB + edgePointer, edge);
            setEdgeRef(nodeB, newEdgeId);
        }
        return newEdgeId;
    }
603018
def appendPoint(self, position=None, type="line", smooth=False, name=None, identifier=None, point=None):
        
        if point is not None:
            if position is None:
                position = point.position
            type = point.type
            smooth = point.smooth
            if name is None:
                name = point.name
            if identifier is not None:
                identifier = point.identifier
        self.insertPoint(
            len(self.points),
            position=position,
            type=type,
            smooth=smooth,
            name=name,
            identifier=identifier
        )