[core] Introduce Distance class to store distance and units separately #5286
No reviewers
Labels
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No milestone
No project
No assignees
2 participants
Due date
No due date set.
Dependencies
No dependencies set.
Reference: organicmaps/organicmaps-tmp#5286
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "core/distance-class"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR solves 2 problems:
double
and units for it inMeters/Kilometers/Feet/Miles
Problem 2 can be solved by parsing "old" string values for distance and units as the translation is broken and we always have units in en:
m/km/ft/mi
. When translations fixed - Android Auto is broken.I believe, this is a better solution.
What do you think? If this approach is OK, I will continue the implementation.
measurment_utils
Distance
class to other places where the translation is brokenPotentionaly, it may be extended, f.e. with arithmetic operations to use it directly during route calculations.
Please, check UTs to better understand how it works now.
Thanks!
Is it the simplest approach possible? Looks like it requires a lot of boilerplate code.
Is there an issue for it on Android? Did you see why is it broken?
stod or better fast double converter from base library (we'll later replace it with even more faster converter).
@ -0,0 +54,4 @@
return {measurement_utils::MilesToMeters(distance) / 1000, Distance::Units::Kilometers};
case Distance::Units::Feet:
return {measurement_utils::MilesToFeet(distance), Distance::Units::Feet};
default: UNREACHABLE();
CHECK and crash here and in similar places?
Are they used somewhere? To convert features data in generator?
No global using directives, please. Only in namespaces.
Is it really necessary to pass string-like param here? Declare enums in cpp and java and write comments, that they should have equal values. We did it many times already.
Good, so probably better to replace 2 params in formatUnitsText with one Distance param here?
nit: Why do we use a fancy formatting delimiter here :)
@ -94,11 +93,11 @@
}
nit: Parameters order is mind blowing here :)
nit: With the new line like in other cases is much better, no?
Good here if precision matters.
Also don't understand, Many other strings with GetLocalizedString work fine in Android.
explicit is not needed
Well, I think that nodiscard here and below is useless and makes only visual trash in code, IMO.
Imagine that we will mark like this all our functions now in the whole code ..
@ -0,0 +43,4 @@
Distance ToPlatformUnitsFormatted() const;
double GetDistance() const;
Units GetUnits() const;
BTW, following this logic, why this functions are not nodiscard ?
Is it good for you (if you are using formaters) put 120 symbols in a line?
It looks ugly, no?
Yes, do we really need NauticalMiles and Inches?
That's the first reason of this PR 😁
No, it's not working. Why? Idk.
Anyway, there is no sense to call this function from Android:
It's better to get string in java directly
@ -0,0 +54,4 @@
return {measurement_utils::MilesToMeters(distance) / 1000, Distance::Units::Kilometers};
case Distance::Units::Feet:
return {measurement_utils::MilesToFeet(distance), Distance::Units::Feet};
default: UNREACHABLE();
Yes. To let the developer know that such conversion is not implemented and he has to implement it by himself
nodiscard shows that it's a bad idea to call the function without storing the result (and using it later)
It was just an experiment and I also don't like how it looks
@ -0,0 +43,4 @@
Distance ToPlatformUnitsFormatted() const;
double GetDistance() const;
Units GetUnits() const;
Because these functions just return values and don't perform any time-consuming operations.
I thought about using this class directly in generator (and other places) in future.
But let's leave it for the next iteration. I'll remove them now
What do you prefer more?
or
I'm using
.clang-format
in repo 😄It looks ugly.
I don't mind both variants.
Hm... That's weird but in some cases it works 🤔
@NonNull
is enough here, no?nit: Can add friend function into Distance:
And can write here LOG(LDEBUG, (loc.m_distToTarget));
nit:
nit
What is this case? Should it be logged or should exception be thrown for faster debugging and fixing?
What is this case? Should it be logged or should exception be thrown for faster debugging and fixing?
Why is it not enabled for all platforms? If Linux UI will be rewritten for Navigation, it will need the same logic.
Can longer strings above ("meter") be renamed in strings to "m" so we have the same code for all platforms?
✅ Pixel 6 - Android 13