private IntRangeSet sliceY(CoordinateSequence stripeSegment, int x, boolean outer,
    Map<TileCoord, List<CoordinateSequence>> inProgressShapes) throws GeometryException {
    if (stripeSegment.size() == 0) {
      return null;
    }
    double leftEdge = -buffer;
    double rightEdge = 1 + buffer;

    TreeSet<Integer> tileYsWithDetail = null;
    IntRangeSet rightFilled = null;
    IntRangeSet leftFilled = null;

    IntObjectMap<MutableCoordinateSequence> ySlices = Hppc.newIntObjectHashMap();
    if (x < 0 || x >= maxTilesAtThisZoom) {
      return null;
    }

    // keep a record of filled tiles that we skipped because an edge of the polygon that gets processed
    // later may intersect the edge of a filled tile, and we'll need to replay all the edges we skipped
    record SkippedSegment(Direction side, int lo, int hi, boolean asc) {}
    List<SkippedSegment> skipped = null;

    for (int i = 0; i < stripeSegment.size() - 1; i++) {
      double ax = stripeSegment.getX(i);
      double ay = stripeSegment.getY(i);
      double bx = stripeSegment.getX(i + 1);
      double by = stripeSegment.getY(i + 1);

      double minY = Math.min(ay, by);
      double maxY = Math.max(ay, by);

      int extentMinY = extents.minY();
      int extentMaxY = extents.maxY();
      int startY = Math.max(extentMinY, (int) Math.floor(minY - neighborBuffer));
      int endStartY = Math.max(extentMinY, (int) Math.floor(minY + neighborBuffer));
      int startEndY = Math.min(extentMaxY - 1, (int) Math.floor(maxY - neighborBuffer));
      int endY = Math.min(extentMaxY - 1, (int) Math.floor(maxY + neighborBuffer));

      // inside a fill if one edge of the polygon runs straight down the right side or up the left side of the column
      boolean onRightEdge = area && ax == bx && ax == rightEdge;
      boolean onLeftEdge = area && ax == bx && ax == leftEdge;

      for (int y = startY; y <= endY; y++) {
        // skip over filled tiles until we get to the next tile that already has detail on it
        if (area && y > endStartY && y < startEndY) {
          if (onRightEdge || onLeftEdge) {
            if (tileYsWithDetail == null) {
              tileYsWithDetail = new TreeSet<>();
              for (IntCursor cursor : ySlices.keys()) {
                tileYsWithDetail.add(cursor.value);
              }
            }
            Integer next = tileYsWithDetail.ceiling(y);
            int nextNonEdgeTile = next == null ? startEndY : Math.min(next, startEndY);
            int endSkip = nextNonEdgeTile - 1;
            // save the Y range that we skipped in case a later edge intersects a filled tile
            if (endSkip >= y) {
              if (skipped == null) {
                skipped = new ArrayList<>();
              }
              var skippedSegment = new SkippedSegment(
                onLeftEdge ? Direction.LEFT : Direction.RIGHT,
                y,
                endSkip,
                by > ay
              );
              skipped.add(skippedSegment);

              //              System.err.println("    " + skippedSegment);
              if (rightFilled == null) {
                rightFilled = new IntRangeSet();
                leftFilled = new IntRangeSet();
              }
              /*
              A tile is inside a filled region when there is an odd number of vertical edges to the left and right

              for example a simple shape:
                     ---------
               out   |  in   | out
               (0/2) | (1/1) | (2/0)
                     ---------

              or a more complex shape
                     ---------       ---------
               out   |  in   | out   | in    |
               (0/4) | (1/3) | (2/2) | (3/1) |
                     |       ---------       |
                     -------------------------

              So we keep track of this number by xor'ing the left and right fills repeatedly,
              then and'ing them together at the end.
               */
              (onRightEdge ? rightFilled : leftFilled).xor(y, endSkip);

              y = nextNonEdgeTile;
            }
          }
        }

        // emit linestring/polygon ring detail
        double topLimit = y - buffer;
        double bottomLimit = y + 1 + buffer;
        MutableCoordinateSequence slice = ySlices.get(y);
        if (slice == null) {
          if (tileYsWithDetail != null) {
            tileYsWithDetail.add(y);
          }
          // X is already relative to tile, but we need to adjust Y
          ySlices.put(y, slice = MutableCoordinateSequence.newScalingSequence(0, y, 256));
          TileCoord tileID = TileCoord.ofXYZ(x, y, z);
          List<CoordinateSequence> toAddTo = inProgressShapes.computeIfAbsent(tileID, tile -> new ArrayList<>());

          // if this is tile is inside a fill from an outer tile, infer that fill here
          if (area && !outer && toAddTo.isEmpty()) {
            // since we process outer shells before holes, if a hole is the first thing to intersect
            // a tile then it must be inside a filled tile from the outer shell. If that's not the case
            // then the geometry is invalid, so throw an exception so the caller can decide how to handle,
            // for example fix the polygon then try again.
            if (!isFilled(x, y)) {
              throw new GeometryException("bad_polygon_fill", x + ", " + y + " is not filled!");
            }
            toAddTo.add(fill(buffer));
          }
          toAddTo.add(slice);

          // if this tile was skipped because we skipped an edge, and now it needs more points,
          // backfill all the edges that we skipped for it
          if (area && leftFilled != null && skipped != null && (leftFilled.contains(y) || rightFilled.contains(y))) {
            for (SkippedSegment skippedSegment : skipped) {
              if (skippedSegment.lo <= y && skippedSegment.hi >= y) {
                double top = y - buffer;
                double bottom = y + 1 + buffer;
                double start = skippedSegment.asc ? top : bottom;
                double end = skippedSegment.asc ? bottom : top;
                double edgeX = skippedSegment.side == Direction.LEFT ? -buffer : (1 + buffer);
                slice.addPoint(edgeX, start);
                slice.addPoint(edgeX, end);
              }
            }
          }
        }

        boolean exited = false;

        if (ay < topLimit) {
          // ---|-->  | (line enters the clip region from the top)
          if (by > topLimit) {
            intersectY(slice, ax, ay, bx, by, topLimit);
          }
        } else if (ay > bottomLimit) {
          // |  <--|--- (line enters the clip region from the bottom)
          if (by < bottomLimit) {
            intersectY(slice, ax, ay, bx, by, bottomLimit);
          }
        } else {
          // | --> | (line starts inside the clip region)
          slice.addPoint(ax, ay);
        }
        if (by < topLimit && ay >= topLimit) {
          // <--|---  | or <--|-----|--- (line exits the clip region on the top)
          intersectY(slice, ax, ay, bx, by, topLimit);
          exited = true;
        }
        if (by > bottomLimit && ay <= bottomLimit) {
          // |  ---|--> or ---|-----|--> (line exits the clip region on the bottom)
          intersectY(slice, ax, ay, bx, by, bottomLimit);
          exited = true;
        }

        if (!area && exited) {
          ySlices.remove(y);
        }
      }
    }

    // add the last point
    int last = stripeSegment.size() - 1;
    double ax = stripeSegment.getX(last);
    double ay = stripeSegment.getY(last);
    int startY = (int) Math.floor(ay - neighborBuffer);
    int endY = (int) Math.floor(ay + neighborBuffer);

    for (int y = startY - 1; y <= endY + 1; y++) {
      MutableCoordinateSequence slice = ySlices.get(y);
      double k1 = y - buffer;
      double k2 = y + 1 + buffer;
      if (ay >= k1 && ay <= k2 && slice != null) {
        slice.addPoint(ax, ay);
      }
    }
    // close the polygons if endpoints are not the same after clipping
    if (area) {
      for (IntObjectCursor<MutableCoordinateSequence> cursor : ySlices) {
        cursor.value.closeRing();
      }
    }
    // a tile is filled if we skipped over the entire left and right side of it while processing a polygon
    return rightFilled != null ? rightFilled.intersect(leftFilled) : null;
  }
Splits an entire vertical X column of edge segments into Y rows that form (X, Y) tile coordinates at this zoom
level, stores the result in {@link #tileContents} and returns the Y ranges of filled tile coordinates if this is a
polygon.
planetiler-core/src/main/java/com/onthegomap/planetiler/render/TiledGeometry.java