-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve LinkSimplify to work less aggressively and handle edge cases … (
#60) * Improve LinkSimplify to work less aggressively and handle edge cases [#53] * allow multiple ways in connectors. * allow connectors to touch a highway at any point, not just endpoints. * formatting
- Loading branch information
Showing
3 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 96 additions & 1 deletion
97
tiles/src/test/java/com/protomaps/basemap/postprocess/LinkSimplifyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,98 @@ | ||
package com.protomaps.basemap.postprocess; | ||
|
||
public class LinkSimplifyTest {} | ||
import static com.onthegomap.planetiler.TestUtils.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.onthegomap.planetiler.VectorTile; | ||
import com.onthegomap.planetiler.geo.GeometryException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class LinkSimplifyTest { | ||
|
||
@Test | ||
void testNoop() throws GeometryException { | ||
List<VectorTile.Feature> items = new ArrayList<>(); | ||
|
||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(0, 0, 10, 0)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
|
||
var result = LinkSimplify.linkSimplify(items, "highway", "tag1", "tag1_link"); | ||
assertEquals(0, result.size()); | ||
} | ||
|
||
@Test | ||
void testLinkConnectsMainAtAnyPoint() throws GeometryException { | ||
List<VectorTile.Feature> items = new ArrayList<VectorTile.Feature>(); | ||
|
||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(0, 0, 10, 0, 20, 0)), | ||
|
||
Map.of("highway", "tag1") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(10, 0, 10, 10)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(0, 10, 10, 10, 20, 10)), | ||
Map.of("highway", "tag1") | ||
)); | ||
|
||
var result = LinkSimplify.linkSimplify(items, "highway", "tag1", "tag1_link"); | ||
assertEquals(3, result.size()); | ||
} | ||
|
||
@Test | ||
void testLinkIsOfframp() throws GeometryException { | ||
List<VectorTile.Feature> items = new ArrayList<VectorTile.Feature>(); | ||
|
||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(0, 0, 10, 0, 20, 0)), | ||
|
||
Map.of("highway", "tag1") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(10, 0, 10, 10)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
|
||
var result = LinkSimplify.linkSimplify(items, "highway", "tag1", "tag1_link"); | ||
assertEquals(1, result.size()); | ||
} | ||
|
||
@Test | ||
void testLinkConnectsLinksAtEdges() throws GeometryException { | ||
List<VectorTile.Feature> items = new ArrayList<VectorTile.Feature>(); | ||
|
||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(0, 0, 10, 0)), | ||
Map.of("highway", "tag1") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(10, 0, 20, 0)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(20, 0, 30, 0)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(30, 0, 40, 0)), | ||
Map.of("highway", "tag1_link") | ||
)); | ||
items.add(new VectorTile.Feature("mylayer", 1, | ||
VectorTile.encodeGeometry(newLineString(40, 0, 50, 0)), | ||
Map.of("highway", "tag1") | ||
)); | ||
|
||
var result = LinkSimplify.linkSimplify(items, "highway", "tag1", "tag1_link"); | ||
assertEquals(5, result.size()); | ||
} | ||
|
||
|
||
} |