@Override
    public void accept(VectorGeometry vectorGeometry) {
      if (vectorGeometry.geomType != geometryType) {
        throw new IllegalArgumentException(
          "Cannot merge a " + vectorGeometry.geomType.name().toLowerCase(Locale.ROOT) + " geometry into a multi" +
            vectorGeometry.geomType.name().toLowerCase(Locale.ROOT));
      }
      if (vectorGeometry.isEmpty()) {
        return;
      }
      var commands = vectorGeometry.unscale().commands();
      int x = 0;
      int y = 0;

      int geometryCount = commands.length;
      int length = 0;
      int command = 0;
      int i = 0;

      result.ensureCapacity(result.elementsCount + commands.length);
      // and multipoints will end up with only one command ("move to" with length=# points)
      if (geometryType != GeometryType.POINT || result.isEmpty()) {
        result.add(commands[0]);
      }
      result.add(zigZagEncode(zigZagDecode(commands[1]) - overallX));
      result.add(zigZagEncode(zigZagDecode(commands[2]) - overallY));
      if (commands.length > 3) {
        result.add(commands, 3, commands.length - 3);
      }

      while (i < geometryCount) {
        if (length <= 0) {
          length = commands[i++];
          command = length & ((1 << 3) - 1);
          length = length >> 3;
        }

        if (length > 0) {
          length--;
          if (command != Command.CLOSE_PATH.value) {
            x += zigZagDecode(commands[i++]);
            y += zigZagDecode(commands[i++]);
          }
        }
      }
      overallX = x;
      overallY = y;
    }
Utility that combines encoded geometries of the same type into a merged multipoint, multilinestring, or
multipolygon.
planetiler-core/src/main/java/com/onthegomap/planetiler/VectorTile.java