-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Expand file tree
/
Copy pathdata_location.cpp
More file actions
86 lines (69 loc) · 1.85 KB
/
Copy pathdata_location.cpp
File metadata and controls
86 lines (69 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_location.h"
#include "ui/image/image.h"
#include "data/data_file_origin.h"
namespace Data {
namespace {
[[nodiscard]] QString AsString(float64 value) {
constexpr auto kPrecision = 6;
return QString::number(value, 'f', kPrecision);
}
} // namespace
LocationPoint::LocationPoint(const MTPDgeoPoint &point)
: _lat(point.vlat().v)
, _lon(point.vlong().v)
, _access(point.vaccess_hash().v) {
}
LocationPoint::LocationPoint(float64 lat, float64 lon, IgnoreAccessHash)
: _lat(lat)
, _lon(lon) {
}
QString LocationPoint::latAsString() const {
return AsString(_lat);
}
QString LocationPoint::lonAsString() const {
return AsString(_lon);
}
MTPGeoPoint LocationPoint::toMTP() const {
return MTP_geoPoint(
MTP_flags(0),
MTP_double(_lon),
MTP_double(_lat),
MTP_long(_access),
MTP_int(0)); // accuracy_radius
}
float64 LocationPoint::lat() const {
return _lat;
}
float64 LocationPoint::lon() const {
return _lon;
}
uint64 LocationPoint::accessHash() const {
return _access;
}
size_t LocationPoint::hash() const {
return QtPrivate::QHashCombine().operator()(
std::hash<float64>()(_lat),
_lon);
}
GeoPointLocation ComputeLocation(const LocationPoint &point) {
const auto scale = 1 + (cScale() * style::DevicePixelRatio()) / 200;
const auto zoom = 13 + (scale - 1);
const auto w = st::locationSize.width() / scale;
const auto h = st::locationSize.height() / scale;
auto result = GeoPointLocation();
result.lat = point.lat();
result.lon = point.lon();
result.access = point.accessHash();
result.width = w;
result.height = h;
result.zoom = zoom;
result.scale = scale;
return result;
}
} // namespace Data