diff options
| author | Johannes Schauer Marin Rodrigues <josch@mister-muffin.de> | 2021-10-16 15:38:17 +0200 |
|---|---|---|
| committer | Johannes Schauer Marin Rodrigues <josch@mister-muffin.de> | 2021-10-21 22:18:29 +0200 |
| commit | f5aed82fc6eee896606e95dc15e578cd9f058a2c (patch) | |
| tree | 94ed60520c61a765cb2515aaea4f3d21183d6b74 /test | |
| parent | 576a075d309056382cadc26ddf04c9eb779114a0 (diff) | |
| download | PROJ-f5aed82fc6eee896606e95dc15e578cd9f058a2c.tar.gz PROJ-f5aed82fc6eee896606e95dc15e578cd9f058a2c.zip | |
Add fallback_strategy to tinshift transform
- this bumps format_version of tinshift JSON to 1.1 for the new field
fallback_strategy
- the default behaviour without that field is retained
- if fallback_strategy is set to "nearest_side", then points that do not fall
into any of the triangles will be transformed according to the nearest
triangle
- if fallback_centroid is set to "nearest_side", then points that do not fall
into any of the triangles will be transformed according to the triangle
with the nearest centroid
Diffstat (limited to 'test')
| -rw-r--r-- | test/gie/tinshift.gie | 12 | ||||
| -rw-r--r-- | test/unit/test_tinshift.cpp | 67 |
2 files changed, 79 insertions, 0 deletions
diff --git a/test/gie/tinshift.gie b/test/gie/tinshift.gie index f16c16bb..85009537 100644 --- a/test/gie/tinshift.gie +++ b/test/gie/tinshift.gie @@ -47,4 +47,16 @@ accept 3210000.0000 6700000.0000 10.0 expect 3210000.0000 6700000.0000 10.2886 roundtrip 1 +# Test fallback strategy nearest_side +operation +proj=tinshift +file=tests/tinshift_fallback_nearest_side.json +accept 2 3 +expect 4 6 +roundtrip 1 + +# Test fallback strategy nearest_centroid +operation +proj=tinshift +file=tests/tinshift_fallback_nearest_centroid.json +accept 3 0 +expect 3 0 +roundtrip 1 + </gie-strict> diff --git a/test/unit/test_tinshift.cpp b/test/unit/test_tinshift.cpp index 96da6e25..2b42294f 100644 --- a/test/unit/test_tinshift.cpp +++ b/test/unit/test_tinshift.cpp @@ -65,6 +65,7 @@ TEST(tinshift, basic) { EXPECT_EQ(f->formatVersion(), "1.0"); EXPECT_EQ(f->inputCRS(), "EPSG:2393"); EXPECT_EQ(f->outputCRS(), "EPSG:3067"); + EXPECT_EQ(f->fallbackStrategy(), FALLBACK_NONE); auto eval = Evaluator(std::move(f)); double x_out = 0; @@ -206,6 +207,72 @@ TEST(tinshift, basic) { EXPECT_EQ(y_out, 0.75); EXPECT_EQ(z_out, 1000.0); } + + // invalid fallback_strategy field with 1.0 version + { + auto j(jMinValid); + j["fallback_strategy"] = "none"; + EXPECT_THROW(TINShiftFile::parse(j.dump()), ParsingException); + } + + // invalid fallback_strategy field with 1.1 version + { + auto j(jMinValid); + j["format_version"] = "1.1"; + j["fallback_strategy"] = "invalid"; + EXPECT_THROW(TINShiftFile::parse(j.dump()), ParsingException); + } + + // fail with no triangles and fallback nearest_side + { + auto j(jMinValid); + j["format_version"] = "1.1"; + j["fallback_strategy"] = "nearest_side"; + j["triangles"] = json::array(); // empty + + auto f = TINShiftFile::parse(j.dump()); + auto eval = Evaluator(std::move(f)); + double x_out = 0; + double y_out = 0; + double z_out = 0; + + EXPECT_FALSE(eval.forward(1.0, 1.0, 1.0, x_out, y_out, z_out)); + } + + // fail with only degenerate triangles (one size is zero length) and + // fallback nearest_side + { + auto j(jMinValid); + j["format_version"] = "1.1"; + j["fallback_strategy"] = "nearest_side"; + j["vertices"] = {{0, 0, 101, 101}, {0, 1, 100, 101}, {0, 1, 100, 100}}; + + auto f = TINShiftFile::parse(j.dump()); + auto eval = Evaluator(std::move(f)); + double x_out = 0; + double y_out = 0; + double z_out = 0; + + EXPECT_FALSE(eval.forward(1.0, 1.0, 1.0, x_out, y_out, z_out)); + } + + // fail with only degenerate triangles (two angles are 0°) and fallback + // nearest_side + { + auto j(jMinValid); + j["format_version"] = "1.1"; + j["fallback_strategy"] = "nearest_side"; + j["vertices"] = { + {0, 0, 101, 101}, {0, 0.5, 100, 101}, {0, 1, 100, 100}}; + + auto f = TINShiftFile::parse(j.dump()); + auto eval = Evaluator(std::move(f)); + double x_out = 0; + double y_out = 0; + double z_out = 0; + + EXPECT_FALSE(eval.forward(1.0, 1.0, 1.0, x_out, y_out, z_out)); + } } } // namespace |
