class CommonAlgorithmsFromCartAGen {

  public static ILineString[] splitLine(ILineString line,
      IDirectPosition splitVertex, double tolerance) {

    IDirectPositionList pts1 = new DirectPositionList();
    IDirectPositionList pts2 = new DirectPositionList();
    pts1.add(line.startPoint());
    List<Segment> segments = Segment.getSegmentList(line);
    boolean line1 = true;
    for (int i = 0; i < segments.size(); i++) {
      Segment seg = segments.get(i);
      if (!seg.containsPoint(splitVertex, tolerance) && line1) {
        pts1.add(seg.endPoint());
        continue;
      } else if (seg.containsPoint(splitVertex, tolerance) && line1) {
        pts1.add(splitVertex);
        line1 = false;
        if (!splitVertex.equals(seg.getEndPoint())) {
          pts2.add(splitVertex);
          pts2.add(seg.endPoint());
        }
        continue;
      } else if (seg.containsPoint(splitVertex, tolerance) && !line1) {
        pts2.add(splitVertex);
        pts2.add(seg.endPoint());
        continue;
      }
      pts2.add(seg.endPoint());
    }

    // build the lines and the array
    ILineString[] lines = new ILineString[2];
    lines[0] = GeometryEngine.getFactory().createILineString(pts1);
    lines[1] = GeometryEngine.getFactory().createILineString(pts2);
    return lines;
  }

}