class TrimAreaMeasurementsFn implements Function<ILink, Optional<ILink>> {

    @Override
    public Optional<ILink> apply(ILink link) {
        if (AreaMeasurement.IS_AREA_MEASUREMENT_PREDICATE.test(link)) {
            Polygon polygon = toPolygon.apply(link);
            Area area = new Area(polygon);
            area.intersect(acceptableBounds);

            Polygon trimmedPolygon = areaToPolygon(area);
            if (trimmedPolygon.npoints >= 3) {
                AreaMeasurement trimmedAreaMeasurement = polygonToAreaMeasurement(trimmedPolygon);
                return Optional.of(trimmedAreaMeasurement.toLink());
            }
            else {
                return Optional.empty();
            }
        }
        else {
            return Optional.of(link);
        }
    }

    public  TrimAreaMeasurementsFn(java.util.List<Point2D<Integer>> bounds);

}