kopia lustrzana https://github.com/onthegomap/planetiler
CachedByZoom and TileExtents tests
rodzic
2d4d6187bf
commit
72679b1b36
|
@ -42,7 +42,8 @@ public abstract class Reader implements Closeable {
|
|||
var featureCollectors = new FeatureCollector.Factory(config);
|
||||
var encoder = writer.newRenderedFeatureEncoder();
|
||||
FeatureRenderer renderer = new FeatureRenderer(
|
||||
config, encoder, next
|
||||
config,
|
||||
rendered -> next.accept(encoder.apply(rendered))
|
||||
);
|
||||
while ((sourceFeature = prev.get()) != null) {
|
||||
featuresRead.incrementAndGet();
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.onthegomap.flatmap.geo.GeoUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
|
||||
public class TileExtentsTest {
|
||||
|
||||
private static final double eps = Math.pow(2, -30);
|
||||
|
||||
@Test
|
||||
public void testFullWorld() {
|
||||
TileExtents extents = TileExtents.computeFromWorldBounds(14, GeoUtils.WORLD_BOUNDS);
|
||||
for (int z = 0; z <= 14; z++) {
|
||||
int max = 1 << z;
|
||||
assertEquals(0, extents.getForZoom(z).minX(), "z" + z + " minX");
|
||||
assertEquals(max, extents.getForZoom(z).maxX(), "z" + z + " maxX");
|
||||
assertEquals(0, extents.getForZoom(z).minY(), "z" + z + " minY");
|
||||
assertEquals(max, extents.getForZoom(z).maxY(), "z" + z + " maxY");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topLeft() {
|
||||
TileExtents extents = TileExtents
|
||||
.computeFromWorldBounds(14, new Envelope(0, eps, 0, eps));
|
||||
for (int z = 0; z <= 14; z++) {
|
||||
assertEquals(0, extents.getForZoom(z).minX(), "z" + z + " minX");
|
||||
assertEquals(1, extents.getForZoom(z).maxX(), "z" + z + " maxX");
|
||||
assertEquals(0, extents.getForZoom(z).minY(), "z" + z + " minY");
|
||||
assertEquals(1, extents.getForZoom(z).maxY(), "z" + z + " maxY");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topRight() {
|
||||
TileExtents extents = TileExtents
|
||||
.computeFromWorldBounds(14, new Envelope(1 - eps, 1, 0, eps));
|
||||
for (int z = 0; z <= 14; z++) {
|
||||
assertEquals((1 << z) - 1, extents.getForZoom(z).minX(), "z" + z + " minX");
|
||||
assertEquals((1 << z), extents.getForZoom(z).maxX(), "z" + z + " maxX");
|
||||
assertEquals(0, extents.getForZoom(z).minY(), "z" + z + " minY");
|
||||
assertEquals(1, extents.getForZoom(z).maxY(), "z" + z + " maxY");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bottomLeft() {
|
||||
TileExtents extents = TileExtents
|
||||
.computeFromWorldBounds(14, new Envelope(0, eps, 1 - eps, 1));
|
||||
for (int z = 0; z <= 14; z++) {
|
||||
assertEquals(0, extents.getForZoom(z).minX(), "z" + z + " minX");
|
||||
assertEquals(1, extents.getForZoom(z).maxX(), "z" + z + " maxX");
|
||||
assertEquals((1 << z) - 1, extents.getForZoom(z).minY(), "z" + z + " minY");
|
||||
assertEquals(1 << z, extents.getForZoom(z).maxY(), "z" + z + " maxY");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.onthegomap.flatmap.collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.onthegomap.flatmap.Arguments;
|
||||
import com.onthegomap.flatmap.CommonParams;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CacheByZoomTest {
|
||||
|
||||
@Test
|
||||
public void testCacheZoom() {
|
||||
List<Integer> calls = new ArrayList<>();
|
||||
CacheByZoom<Integer> cached = CacheByZoom.create(CommonParams.from(Arguments.of(
|
||||
"minzoom", "1",
|
||||
"maxzoom", "10"
|
||||
)), i -> {
|
||||
calls.add(i);
|
||||
return i + 1;
|
||||
});
|
||||
assertEquals(3, cached.get(2));
|
||||
assertEquals(3, cached.get(2));
|
||||
assertEquals(6, cached.get(5));
|
||||
assertEquals(List.of(2, 5), calls);
|
||||
}
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue