Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Nov 22, 2024
1 parent 339362f commit 7b40b58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.GeometryType;
import com.onthegomap.planetiler.geo.SimplifyStrategy;
import com.onthegomap.planetiler.geo.SimplifyMethod;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.reader.Struct;
import com.onthegomap.planetiler.render.FeatureRenderer;
Expand Down Expand Up @@ -503,8 +503,8 @@ public final class Feature implements WithZoomRange<Feature>, WithAttrs<Feature>
private double pixelToleranceAtMaxZoom = config.simplifyToleranceAtMaxZoom();
private ZoomFunction<Number> pixelTolerance = null;

private SimplifyStrategy defaultSimplifyStrategy = SimplifyStrategy.DOUGLAS_PEUCKER;
private ZoomFunction<SimplifyStrategy> simplifyStrategy = null;
private SimplifyMethod defaultSimplifyMethod = SimplifyMethod.DOUGLAS_PEUCKER;
private ZoomFunction<SimplifyMethod> simplifyMethod = null;

private String numPointsAttr = null;
private List<OverrideCommand> partialOverrides = null;
Expand Down Expand Up @@ -719,25 +719,25 @@ public double getPixelToleranceAtZoom(int zoom) {
}

/**
* Sets the fallback line and polygon simplify method when not overriden by
* {@link #setSimplifyStrategyOverrides(ZoomFunction)}.
* Sets the fallback line and polygon simplify method when not overriden by *
* {@link #setSimplifyMethodOverrides(ZoomFunction)}.
*/
public FeatureCollector.Feature setSimplifyStrategy(SimplifyStrategy strategy) {
defaultSimplifyStrategy = strategy;
public FeatureCollector.Feature setSimplifyMethod(SimplifyMethod strategy) {
defaultSimplifyMethod = strategy;
return this;
}

/** Set simplify strategy to use at different zoom levels. */
public FeatureCollector.Feature setSimplifyStrategyOverrides(ZoomFunction<SimplifyStrategy> overrides) {
simplifyStrategy = overrides;
/** Set simplification algorithm to use at different zoom levels. */
public FeatureCollector.Feature setSimplifyMethodOverrides(ZoomFunction<SimplifyMethod> overrides) {
simplifyMethod = overrides;
return this;
}

/**
* Returns the simplification strategy for lines and polygons in tile pixels at {@code zoom}.
* Returns the simplification method for lines and polygons in tile pixels at {@code zoom}.
*/
public SimplifyStrategy getSimplifyStrategyAtZoom(int zoom) {
return ZoomFunction.applyOrElse(simplifyStrategy, zoom, defaultSimplifyStrategy);
public SimplifyMethod getSimplifyMethodAtZoom(int zoom) {
return ZoomFunction.applyOrElse(simplifyMethod, zoom, defaultSimplifyMethod);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.onthegomap.planetiler.geo;

public enum SimplifyMethod {
RETAIN_IMPORTANT_POINTS,
RETAIN_EFFECTIVE_AREAS,
RETAIN_WEIGHTED_EFFECTIVE_AREAS;

public static final SimplifyMethod DOUGLAS_PEUCKER = RETAIN_IMPORTANT_POINTS;
public static final SimplifyMethod VISVALINGAM_WHYATT = RETAIN_EFFECTIVE_AREAS;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.onthegomap.planetiler.geo.DouglasPeuckerSimplifier;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.SimplifyStrategy;
import com.onthegomap.planetiler.geo.SimplifyMethod;
import com.onthegomap.planetiler.geo.TileCoord;
import com.onthegomap.planetiler.geo.TileExtents;
import com.onthegomap.planetiler.geo.VWSimplifier;
Expand Down Expand Up @@ -205,7 +205,7 @@ private void renderLineOrPolygonGeometry(FeatureCollector.Feature feature, Geome
int z, double minSize, boolean area) {
double scale = 1 << z;
double tolerance = feature.getPixelToleranceAtZoom(z) / 256d;
SimplifyStrategy strategy = feature.getSimplifyStrategyAtZoom(z);
SimplifyMethod simplifyMethod = feature.getSimplifyMethodAtZoom(z);
double buffer = feature.getBufferPixelsAtZoom(z) / 256;
TileExtents.ForZoom extents = config.bounds().tileExtents().getForZoom(z);

Expand All @@ -214,10 +214,10 @@ private void renderLineOrPolygonGeometry(FeatureCollector.Feature feature, Geome
Geometry scaled = AffineTransformation.scaleInstance(scale, scale).transform(input);
TiledGeometry sliced;
// TODO replace with geometry pipeline when available
Geometry geom = switch (strategy) {
Geometry geom = switch (simplifyMethod) {
case RETAIN_IMPORTANT_POINTS -> DouglasPeuckerSimplifier.simplify(scaled, tolerance);
// Douglas Peucker tolerance is distance off the line, and VW tolerance is area, so square what the user entered
// to convert from DP to VW tolerance
// DP tolerance is displacement, and VW tolerance is area, so square what the user entered to convert from
// DP to VW tolerance
case RETAIN_EFFECTIVE_AREAS -> new VWSimplifier().setTolerance(tolerance * tolerance).transform(scaled);
case RETAIN_WEIGHTED_EFFECTIVE_AREAS ->
new VWSimplifier().setWeight(0.7).setTolerance(tolerance * tolerance).transform(scaled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.onthegomap.planetiler.files.ReadableFilesArchive;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.SimplifyStrategy;
import com.onthegomap.planetiler.geo.SimplifyMethod;
import com.onthegomap.planetiler.geo.TileCoord;
import com.onthegomap.planetiler.geo.TileOrder;
import com.onthegomap.planetiler.mbtiles.Mbtiles;
Expand Down Expand Up @@ -436,7 +436,7 @@ void testLabelGridLimit() throws Exception {
"false,RETAIN_WEIGHTED_EFFECTIVE_AREAS",
"true,RETAIN_IMPORTANT_POINTS",
})
void testLineString(boolean anyGeom, SimplifyStrategy simplifyStrategy) throws Exception {
void testLineString(boolean anyGeom, SimplifyMethod simplifyStrategy) throws Exception {
double x1 = 0.5 + Z14_WIDTH / 2;
double y1 = 0.5 + Z14_WIDTH / 2;
double x2 = x1 + Z14_WIDTH;
Expand All @@ -460,7 +460,7 @@ void testLineString(boolean anyGeom, SimplifyStrategy simplifyStrategy) throws E
(in, features) -> (anyGeom ? features.anyGeometry("layer") : features.line("layer"))
.setZoomRange(13, 14)
.setPixelTolerance(1)
.setSimplifyStrategy(simplifyStrategy)
.setSimplifyMethod(simplifyStrategy)
.setBufferPixels(4)
);

Expand Down Expand Up @@ -2567,7 +2567,7 @@ void testBoundFilters() throws Exception {
"RETAIN_EFFECTIVE_AREAS",
"RETAIN_WEIGHTED_EFFECTIVE_AREAS",
})
void testSimplePolygon(SimplifyStrategy strategy) throws Exception {
void testSimplePolygon(SimplifyMethod strategy) throws Exception {
List<Coordinate> points = z14PixelRectangle(0, 40);

var results = runWithReaderFeatures(
Expand All @@ -2579,7 +2579,7 @@ void testSimplePolygon(SimplifyStrategy strategy) throws Exception {
.setZoomRange(0, 14)
.setBufferPixels(0)
.setPixelTolerance(1)
.setSimplifyStrategy(strategy)
.setSimplifyMethod(strategy)
.setMinPixelSize(10) // should only show up z14 (40) z13 (20) and z12 (10)
);

Expand Down

0 comments on commit 7b40b58

Please sign in to comment.