public static void setCoordinates(
     final double[] coordinates, final int axisCount, final int i, final Point point) {
   if (point != null && !point.isEmpty()) {
     for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
       final double value = point.getCoordinate(axisIndex);
       coordinates[i * axisCount + axisIndex] = value;
     }
   }
 }
 public static void setCoordinates(
     final GeometryFactory geometryFactory,
     final double[] coordinates,
     final int axisCount,
     final int vertexIndex,
     Point point) {
   if (geometryFactory != null) {
     point = point.convertGeometry(geometryFactory, axisCount);
   }
   for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
     double value = point.getCoordinate(axisIndex);
     value = geometryFactory.makePrecise(axisIndex, value);
     coordinates[vertexIndex * axisCount + axisIndex] = value;
   }
 }
 public void testNormalizeEmptyPoint() throws Exception {
   Point point = this.geometryFactory.geometry("POINT EMPTY");
   point = point.normalize();
   assertEquals(null, point.getPoint());
 }
 public void testComparePoint() throws Exception {
   final Point p1 = this.geometryFactory.geometry("POINT(30 30)");
   final Point p2 = this.geometryFactory.geometry("POINT(30 40)");
   assertTrue(p1.compareTo(p2) < 0);
 }
 public void testNormalizePoint() throws Exception {
   Point point = this.geometryFactory.geometry("POINT (30 30)");
   point = point.normalize();
   CoordinatesTest.assertEquals(point.getPoint(), 30, 30);
 }
  public static List<LineString> intersection(
      final GeometryFactory geometryFactory,
      final LineString points1,
      final LineString points2,
      final double maxDistance) {

    final LineStringGraph graph1 = new LineStringGraph(points1);
    graph1.setPrecisionModel(geometryFactory);
    final LineStringGraph graph2 = new LineStringGraph(points2);
    graph2.setPrecisionModel(geometryFactory);
    final Map<Point, Point> movedNodes = new HashMap<>();
    graph1.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph2, maxDistance, node));
    graph2.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph1, maxDistance, node));

    final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 =
        graph1.getPointsOnEdges(graph2, maxDistance);
    final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge2 =
        graph2.getPointsOnEdges(graph1, maxDistance);
    graph1.splitEdges(pointsOnEdge1);
    graph2.splitEdges(pointsOnEdge2);
    Point startPoint = points1.getPoint(0);
    if (movedNodes.containsKey(startPoint)) {
      startPoint = movedNodes.get(startPoint);
    }
    Point endPoint = points1.getPoint(points1.getVertexCount() - 1);
    if (movedNodes.containsKey(endPoint)) {
      endPoint = movedNodes.get(endPoint);
    }
    final List<LineString> intersections = new ArrayList<>();
    final List<Point> currentCoordinates = new ArrayList<>();
    Node<LineSegment> previousNode = graph1.getNode(startPoint);
    do {
      final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
      if (outEdges.isEmpty()) {
        previousNode = null;
      } else if (outEdges.size() > 1) {
        throw new IllegalArgumentException("Cannot handle overlaps\n" + points1 + "\n " + points2);
      } else {
        final Edge<LineSegment> edge = outEdges.get(0);
        final LineSegment line = edge.getObject();
        final Node<LineSegment> nextNode = edge.getToNode();
        if (graph2.hasEdgeBetween(previousNode, nextNode)) {
          if (currentCoordinates.size() == 0) {
            currentCoordinates.add(line.getPoint(0));
          }
          currentCoordinates.add(line.getPoint(1));
        } else {
          if (currentCoordinates.size() > 0) {
            final LineString points =
                new LineStringDouble(points1.getAxisCount(), currentCoordinates);
            intersections.add(points);
            currentCoordinates.clear();
          }
        }
        previousNode = nextNode;
      }

    } while (previousNode != null && !endPoint.equals(2, startPoint));
    if (currentCoordinates.size() > 0) {
      final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
      intersections.add(points);
    }
    return intersections;
  }