createSplitEdge method

Edge createSplitEdge(
  1. EdgeIntersection ei0,
  2. EdgeIntersection ei1
)

Create a new "split edge" with the section of points between (and including) the two intersections. The label for the new edge is the same as the label for the parent edge.

Implementation

Edge createSplitEdge(EdgeIntersection ei0, EdgeIntersection ei1) {
//Debug.print("\ncreateSplitEdge"); Debug.print(ei0); Debug.print(ei1);
  int npts = ei1.segmentIndex - ei0.segmentIndex + 2;

  Coordinate lastSegStartPt = edge.pts[ei1.segmentIndex];
  // if the last intersection point is not equal to the its segment start pt,
  // add it to the points list as well.
  // (This check is needed because the distance metric is not totally reliable!)
  // The check for point equality is 2D only - Z values are ignored
  bool useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);
  if (!useIntPt1) {
    npts--;
  }

  List<Coordinate> pts = []; //..length = (npts);
  // int ipt = 0;
  pts.add(Coordinate.fromCoordinate(ei0.coord));
  // pts[ipt++] = new Coordinate.fromCoordinate(ei0.coord);
  for (int i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
    pts.add(edge.pts[i]);
    // pts[ipt++] = edge.pts[i];
  }
  if (useIntPt1) pts.add(ei1.coord);
  // if (useIntPt1) pts[ipt] = ei1.coord;
  return new Edge(pts, new Label.fromLabel(edge.label!));
}