|
| 1 | +// Copyright 2021 The Open GEE Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +#include "common/khTileAddr.h" |
| 18 | + |
| 19 | +#include "common/khGeomUtils.h" |
| 20 | + |
| 21 | +extern const khTilespaceFlat RasterProductTilespaceFlat; |
| 22 | +extern const khTilespaceMercator RasterProductTilespaceMercator; |
| 23 | + |
| 24 | +double MetersToDegrees(double meters) { |
| 25 | + return meters / khGeomUtils::khEarthCircumferencePerDegree; |
| 26 | +} |
| 27 | + |
| 28 | +double MetersToDegreesMerc(double meters) { |
| 29 | + return meters / khGeomUtilsMercator::khEarthCircumferencePerDegree; |
| 30 | +} |
| 31 | + |
| 32 | +TEST(TileAddrTest, FlatLowRes) { |
| 33 | + double degrees = MetersToDegrees(400000000); |
| 34 | + unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees); |
| 35 | + ASSERT_EQ(0, level); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(TileAddrTest, FlatMedRes) { |
| 39 | + double degrees = MetersToDegrees(4000); // Same as bluemarble |
| 40 | + unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees); |
| 41 | + // The reported level will be 8 levels off from the level in the Fusion UI |
| 42 | + ASSERT_EQ(6 + 8, level); |
| 43 | +} |
| 44 | + |
| 45 | +TEST(TileAddrTest, FlatHighRes) { |
| 46 | + double degrees = MetersToDegrees(0.0187); |
| 47 | + unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees); |
| 48 | + ASSERT_EQ(31, level); |
| 49 | +} |
| 50 | + |
| 51 | +// Make sure the level tops out at 31 |
| 52 | +TEST(TileAddrTest, FlatTooHighRes) { |
| 53 | + double degrees = MetersToDegrees(0.00000001); |
| 54 | + unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees); |
| 55 | + ASSERT_EQ(31, level); |
| 56 | +} |
| 57 | + |
| 58 | +TEST(TileAddrTest, MercLowRes) { |
| 59 | + unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(400000000); |
| 60 | + ASSERT_EQ(0, level); |
| 61 | +} |
| 62 | + |
| 63 | +TEST(TileAddrTest, MercMedRes) { |
| 64 | + // Same resolution as bluemarble |
| 65 | + unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(4000); |
| 66 | + // The reported level will be 8 levels off from the level in the Fusion UI |
| 67 | + ASSERT_EQ(6 + 8, level); |
| 68 | +} |
| 69 | + |
| 70 | +TEST(TileAddrTest, MercHighRes) { |
| 71 | + unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.0187); |
| 72 | + ASSERT_EQ(31, level); |
| 73 | +} |
| 74 | + |
| 75 | +// Make sure the level tops out at 31 |
| 76 | +TEST(TileAddrTest, MercTooHighRes) { |
| 77 | + unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.00000001); |
| 78 | + ASSERT_EQ(31, level); |
| 79 | +} |
| 80 | + |
| 81 | +// The purpose of this test is to demonstrate that flat and mercator behave |
| 82 | +// differently. |
| 83 | +TEST(TileAddrTest, FlatVsMercDiff) { |
| 84 | + double meters = 2504689.303265145; |
| 85 | + double degrees = MetersToDegrees(meters); |
| 86 | + unsigned int mercLevel = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(meters); |
| 87 | + unsigned int flatLevel = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees); |
| 88 | + ASSERT_EQ(4, mercLevel); |
| 89 | + ASSERT_EQ(5, flatLevel); |
| 90 | +} |
| 91 | + |
| 92 | +int main(int argc, char **argv) { |
| 93 | + testing::InitGoogleTest(&argc, argv); |
| 94 | + return RUN_ALL_TESTS(); |
| 95 | +} |
0 commit comments