@Override
  protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {
    boolean area = parent instanceof LinearRing;
    int minPoints = area ? 4 : 2;
    if (coords.size() <= minPoints) {
      return coords;
    }
    // make sure we include the first and last points even if they are closer than the simplification threshold
    MutableCoordinateSequence result = new MutableCoordinateSequence();
    result.forceAddPoint(coords.getX(0), coords.getY(0));
    // for polygons, additionally keep at least 2 intermediate points even if they are below simplification threshold
    // to avoid collapse.
    subsimplify(coords, result, 0, coords.size() - 1, minPoints - 2);
    result.forceAddPoint(coords.getX(coords.size() - 1), coords.getY(coords.size() - 1));
    return result;
  }
Returns the square of the number of units that (px, p1) is away from the line segment from (p1x, py1) to (p2x,
p2y).
planetiler-core/src/main/java/com/onthegomap/planetiler/geo/DouglasPeuckerSimplifier.java