[ios] Add random smoothly changed elevation to iOS Simulator for testing track recording

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-06-09 00:24:48 +02:00
committed by Yannik Bloscheck
parent 529272cd54
commit f3bc6d9d8b
3 changed files with 92 additions and 0 deletions

View File

@@ -10,6 +10,10 @@
#include "map/gps_tracker.hpp" #include "map/gps_tracker.hpp"
#if TARGET_OS_SIMULATOR
#include "MountainElevationGenerator.hpp"
#endif
namespace namespace
{ {
using Observer = id<MWMLocationObserver>; using Observer = id<MWMLocationObserver>;
@@ -472,6 +476,25 @@ void setShowLocationAlert(BOOL needShow) {
if (location.horizontalAccuracy < 0.) if (location.horizontalAccuracy < 0.)
return; return;
#if TARGET_OS_SIMULATOR
// There is no simulator < 15.0 in the new XCode.
if (@available(iOS 15.0, *))
{
// iOS Simulator doesn't provide any elevation in its locations. Mock it.
static MountainElevationGenerator generator;
location = [[CLLocation alloc] initWithCoordinate:location.coordinate
altitude:generator.NextElevation()
horizontalAccuracy:location.horizontalAccuracy
verticalAccuracy:location.horizontalAccuracy
course:location.course
courseAccuracy:location.courseAccuracy
speed:location.speed
speedAccuracy:location.speedAccuracy
timestamp:location.timestamp
sourceInfo:location.sourceInformation];
}
#endif
self.lastLocationStatus = MWMLocationStatusNoError; self.lastLocationStatus = MWMLocationStatusNoError;
self.locationSource = location::EAppleNative; self.locationSource = location::EAppleNative;
[self processLocationUpdate:location]; [self processLocationUpdate:location];

View File

@@ -0,0 +1,67 @@
#pragma once
#include <ctime>
#include <random>
class MountainElevationGenerator
{
static double constexpr kRandom{-1.};
std::mt19937_64 rng;
double const minElevation;
double const maxElevation;
double const maxSlopeChange;
std::normal_distribution<double> slopeChangeDist;
double currentElevation;
double currentSlope;
double ValueOrRandomInRange(double value, double min, double max)
{
if (value != kRandom)
return value;
return std::uniform_int_distribution<>(min, max)(rng);
}
public:
MountainElevationGenerator(double minElevation = kRandom, double maxElevation = kRandom,
double startElevation = kRandom, double maxSlopeChange = kRandom,
time_t seed = std::time(nullptr))
: rng(seed)
, minElevation(ValueOrRandomInRange(minElevation, 0., 2000.))
, maxElevation(ValueOrRandomInRange(maxElevation, 3000., 7000.))
, maxSlopeChange(ValueOrRandomInRange(maxSlopeChange, 1., 5.))
, slopeChangeDist(0.0, maxSlopeChange)
, currentElevation(ValueOrRandomInRange(startElevation, minElevation, maxElevation))
, currentSlope(0.0)
{}
double NextElevation()
{
// Change the slope gradually
currentSlope += slopeChangeDist(rng);
// Limit maximum steepness
currentSlope = std::max(-maxSlopeChange, std::min(maxSlopeChange, currentSlope));
// Update elevation based on current slope
currentElevation += currentSlope;
// Ensure we stay within elevation bounds
if (currentElevation < minElevation)
{
currentElevation = minElevation;
currentSlope = std::abs(currentSlope) * 0.5; // Bounce back up
}
if (currentElevation > maxElevation)
{
currentElevation = maxElevation;
currentSlope = -std::abs(currentSlope) * 0.5; // Start going down
}
return currentElevation;
}
};

View File

@@ -1746,6 +1746,7 @@
FA3C4FE52D0DB7A600E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/InfoPlist.strings; sourceTree = "<group>"; }; FA3C4FE52D0DB7A600E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
FA3C4FE62D0DB7A700E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = "<group>"; }; FA3C4FE62D0DB7A700E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = "<group>"; };
FA3C4FE72D0DB7A700E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = sr; path = sr.lproj/Localizable.stringsdict; sourceTree = "<group>"; }; FA3C4FE72D0DB7A700E6C03A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = sr; path = sr.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
FA439D842DF618670023C181 /* MountainElevationGenerator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MountainElevationGenerator.hpp; sourceTree = "<group>"; };
FA456C3B26BDC6AD00B83C20 /* Chart.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Chart.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FA456C3B26BDC6AD00B83C20 /* Chart.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Chart.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FA456C4026BDCC8E00B83C20 /* shaders.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = shaders.xcodeproj; path = ../../xcode/shaders/shaders.xcodeproj; sourceTree = "<group>"; }; FA456C4026BDCC8E00B83C20 /* shaders.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = shaders.xcodeproj; path = ../../xcode/shaders/shaders.xcodeproj; sourceTree = "<group>"; };
FA459EB314327AF700B5BB3C /* WorldCoasts.mwm */ = {isa = PBXFileReference; lastKnownFileType = file; name = WorldCoasts.mwm; path = ../../data/WorldCoasts.mwm; sourceTree = "<group>"; }; FA459EB314327AF700B5BB3C /* WorldCoasts.mwm */ = {isa = PBXFileReference; lastKnownFileType = file; name = WorldCoasts.mwm; path = ../../data/WorldCoasts.mwm; sourceTree = "<group>"; };
@@ -2098,6 +2099,7 @@
340475291E081A4600C92850 /* Location */ = { 340475291E081A4600C92850 /* Location */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
FA439D842DF618670023C181 /* MountainElevationGenerator.hpp */,
3404752A1E081A4600C92850 /* MWMLocationHelpers.h */, 3404752A1E081A4600C92850 /* MWMLocationHelpers.h */,
3404752B1E081A4600C92850 /* MWMLocationManager.h */, 3404752B1E081A4600C92850 /* MWMLocationManager.h */,
3404752C1E081A4600C92850 /* MWMLocationManager.mm */, 3404752C1E081A4600C92850 /* MWMLocationManager.mm */,