summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLGeometry.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLGeometry.mm')
-rw-r--r--platform/darwin/src/MGLGeometry.mm13
1 files changed, 13 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLGeometry.mm b/platform/darwin/src/MGLGeometry.mm
index 1540a3a741..43bf74c407 100644
--- a/platform/darwin/src/MGLGeometry.mm
+++ b/platform/darwin/src/MGLGeometry.mm
@@ -4,6 +4,10 @@
#import <mbgl/util/projection.hpp>
+#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
+#import <Cocoa/Cocoa.h>
+#endif
+
/** Vertical field of view, measured in degrees, for determining the altitude
of the viewpoint.
@@ -57,3 +61,12 @@ double MGLZoomLevelForAltitude(CLLocationDistance altitude, CGFloat pitch, CLLoc
CGFloat mapPixelWidthAtZoom = std::cos(MGLRadiansFromDegrees(latitude)) * mbgl::util::M2PI * mbgl::util::EARTH_RADIUS_M / metersPerPixel;
return ::log2(mapPixelWidthAtZoom / mbgl::util::tileSize);
}
+
+CGPoint MGLPointRounded(CGPoint point) {
+#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
+ CGFloat scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [UIScreen mainScreen].nativeScale : [UIScreen mainScreen].scale;
+#elif TARGET_OS_MAC
+ CGFloat scaleFactor = [NSScreen mainScreen].backingScaleFactor;
+#endif
+ return CGPointMake(round(point.x * scaleFactor) / scaleFactor, round(point.y * scaleFactor) / scaleFactor);
+}