class CommonAlgorithmsFromCartAGen {

  public static ILineString getSubLine(ILineString line, IDirectPosition pt1,
      IDirectPosition pt2) {
    // first, insert both pts as vertices of the line
    ILineString updatedLine = insertVertex(insertVertex(line, pt1, 0.01), pt2,
        0.01);
    IDirectPositionList subLine = new DirectPositionList();
    boolean start = false;
    boolean end = false;
    for (IDirectPosition vertex : updatedLine.coord()) {
      if (vertex.equals(pt1, 0.01))
        start = true;
      if (end)
        break;
      if (vertex.equals(pt2, 0.01))
        end = true;
      if (!start)
        continue;
      subLine.add(vertex);
    }

    // case where the line is not in the same direction as the given points
    if (subLine.size() == 0) {
      start = false;
      end = false;
      subLine.clear();
      for (IDirectPosition vertex : updatedLine.coord().reverse()) {
        if (vertex.equals(pt1, 0.01))
          start = true;
        if (!start)
          continue;
        if (end)
          break;
        if (vertex.equals(pt2, 0.01))
          end = true;
        subLine.add(vertex);
      }
    }

    return new GM_LineString(subLine);
  }

}