[ios] Fix type narrowing issue with MGLOpenGLStyleLayer projection matrix (#11664)
`CATransform3D`'s matrix is internally typed as `CGFloat`, which we were implicitly casting to from `double`.... except that the `-Wc++11-narrowing` flag disallows implicit narrowing casts and we need `double` precision, anyway. * [ios, macos] Use MGLMatrix4 a 4x4 double matrix for MGLOpenGLStyleLayer projection matrix. * [ios, macos] Don't use union for MGLMatrix4
This commit is contained in:
@@ -24,6 +24,14 @@ typedef struct __attribute__((objc_boxable)) MGLMapPoint {
|
||||
CGFloat zoomLevel;
|
||||
} MGLMapPoint;
|
||||
|
||||
/* Defines a 4x4 matrix. */
|
||||
typedef struct MGLMatrix4 {
|
||||
double m00, m01, m02, m03;
|
||||
double m10, m11, m12, m13;
|
||||
double m20, m21, m22, m23;
|
||||
double m30, m31, m32, m33;
|
||||
} MGLMatrix4;
|
||||
|
||||
/**
|
||||
Creates a new `MGLCoordinateSpan` from the given latitudinal and longitudinal
|
||||
deltas.
|
||||
|
||||
@@ -111,3 +111,14 @@ MGLMapPoint MGLMapPointForCoordinate(CLLocationCoordinate2D coordinate, double z
|
||||
mbgl::Point<double> projectedCoordinate = mbgl::Projection::project(MGLLatLngFromLocationCoordinate2D(coordinate), std::pow(2.0, zoomLevel));
|
||||
return MGLMapPointMake(projectedCoordinate.x, projectedCoordinate.y, zoomLevel);
|
||||
}
|
||||
|
||||
MGLMatrix4 MGLMatrix4Make(std::array<double, 16> array) {
|
||||
MGLMatrix4 mat4 = {
|
||||
.m00 = array[0], .m01 = array[1], .m02 = array[2], .m03 = array[3],
|
||||
.m10 = array[4], .m11 = array[5], .m12 = array[6], .m13 = array[7],
|
||||
.m20 = array[8], .m21 = array[9], .m22 = array[10], .m23 = array[11],
|
||||
.m30 = array[12], .m31 = array[13], .m32 = array[14], .m33 = array[15]
|
||||
};
|
||||
return mat4;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,3 +128,5 @@ MGLRadianCoordinate2D MGLRadianCoordinateAtDistanceFacingDirection(MGLRadianCoor
|
||||
CLLocationDirection MGLDirectionBetweenCoordinates(CLLocationCoordinate2D firstCoordinate, CLLocationCoordinate2D secondCoordinate);
|
||||
|
||||
CGPoint MGLPointRounded(CGPoint point);
|
||||
|
||||
MGLMatrix4 MGLMatrix4Make(std::array<double, 16> mat);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#import "MGLFoundation.h"
|
||||
#import "MGLStyleValue.h"
|
||||
#import "MGLStyleLayer.h"
|
||||
#import "MGLGeometry.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -18,7 +19,7 @@ typedef struct MGLStyleLayerDrawingContext {
|
||||
CLLocationDirection direction;
|
||||
CGFloat pitch;
|
||||
CGFloat fieldOfView;
|
||||
CATransform3D projectionMatrix;
|
||||
MGLMatrix4 projectionMatrix;
|
||||
} MGLStyleLayerDrawingContext;
|
||||
|
||||
MGL_EXPORT
|
||||
|
||||
@@ -3,21 +3,11 @@
|
||||
#import "MGLMapView_Private.h"
|
||||
#import "MGLStyle_Private.h"
|
||||
#import "MGLStyleLayer_Private.h"
|
||||
#import "MGLGeometry_Private.h"
|
||||
|
||||
#include <mbgl/style/layers/custom_layer.hpp>
|
||||
#include <mbgl/math/wrap.hpp>
|
||||
|
||||
|
||||
CATransform3D CATransform3DMake(std::array<double, 16> array) {
|
||||
CATransform3D t = {
|
||||
.m11 = array[0], .m12 = array[1], .m13 = array[2], .m14 = array[3],
|
||||
.m21 = array[4], .m22 = array[5], .m23 = array[6], .m24 = array[7],
|
||||
.m31 = array[8], .m32 = array[9], .m33 = array[10], .m34 = array[11],
|
||||
.m41 = array[12], .m42 = array[13], .m43 = array[14], .m44 = array[15]
|
||||
};
|
||||
return t;
|
||||
}
|
||||
|
||||
class MGLOpenGLLayerHost : public mbgl::style::CustomLayerHost {
|
||||
public:
|
||||
MGLOpenGLLayerHost(MGLOpenGLStyleLayer *styleLayer) {
|
||||
@@ -42,7 +32,7 @@ public:
|
||||
.direction = mbgl::util::wrap(params.bearing, 0., 360.),
|
||||
.pitch = static_cast<CGFloat>(params.pitch),
|
||||
.fieldOfView = static_cast<CGFloat>(params.fieldOfView),
|
||||
.projectionMatrix = CATransform3DMake(params.projectionMatrix)
|
||||
.projectionMatrix = MGLMatrix4Make(params.projectionMatrix)
|
||||
};
|
||||
[layer drawInMapView:layer.style.mapView withContext:drawingContext];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user