This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore Transform changes with NaN parameters
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include "../fixtures/util.hpp" | ||
|
||
#include <mbgl/util/run_loop.hpp> | ||
#include <mbgl/map/map_data.hpp> | ||
#include <mbgl/map/map_context.hpp> | ||
#include <mbgl/platform/default/headless_view.hpp> | ||
#include <mbgl/platform/default/headless_display.hpp> | ||
#include <mbgl/storage/default_file_source.hpp> | ||
|
||
#include <cstdlib> | ||
|
||
using namespace mbgl; | ||
|
||
class MockView : public View { | ||
public: | ||
void activate() override { | ||
} | ||
void deactivate() override { | ||
} | ||
void notify() override { | ||
} | ||
void invalidate(std::function<void()>) override { | ||
} | ||
}; | ||
|
||
TEST(Transform, InvalidScale) { | ||
MockView view; | ||
Transform transform(view); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(1, transform.getScale()); | ||
|
||
transform.setScale(2); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
|
||
const double invalid = std::nan(""); | ||
transform.setScale(invalid); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
|
||
transform.scaleBy(invalid); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
|
||
transform.setZoom(invalid); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
|
||
transform.setLatLngZoom({ 0, 0 }, invalid); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
} | ||
|
||
TEST(Transform, InvalidLatLng) { | ||
MockView view; | ||
Transform transform(view); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(1, transform.getScale()); | ||
|
||
transform.setScale(2); | ||
transform.setLatLng({ 8, 10 }); | ||
|
||
ASSERT_DOUBLE_EQ(8, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(10, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
|
||
transform.setLatLngZoom({ 10, 8 }, 2); | ||
|
||
ASSERT_DOUBLE_EQ(10, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(8, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(4, transform.getScale()); | ||
|
||
const double invalid = std::nan(""); | ||
transform.setLatLngZoom({ invalid, 8 }, 2); | ||
|
||
ASSERT_DOUBLE_EQ(10, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(8, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(4, transform.getScale()); | ||
|
||
transform.setLatLngZoom({ 10, invalid }, 2); | ||
|
||
ASSERT_DOUBLE_EQ(10, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(8, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(4, transform.getScale()); | ||
} | ||
|
||
|
||
TEST(Transform, InvalidBearing) { | ||
MockView view; | ||
Transform transform(view); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(1, transform.getScale()); | ||
|
||
transform.setScale(2); | ||
transform.setAngle(2); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
ASSERT_DOUBLE_EQ(2, transform.getAngle()); | ||
|
||
const double invalid = std::nan(""); | ||
transform.setAngle(invalid); | ||
|
||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); | ||
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); | ||
ASSERT_DOUBLE_EQ(2, transform.getScale()); | ||
ASSERT_DOUBLE_EQ(2, transform.getAngle()); | ||
} |
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