gpt4 book ai didi

iphone - 为什么苹果这样做: MKMapRectIntersection(boundingMapRect, worldRect)?

转载 作者:行者123 更新时间:2023-11-29 04:02:20 26 4
gpt4 key购买 nike

我只是重写 MKOverlay,所以我正在 Apple 开发人员示例代码中寻找良好的实践......当我看到这个时:

    // bite off up to 1/4 of the world to draw into.
MKMapPoint origin = points[0];
origin.x -= MKMapSizeWorld.width / 8.0;
origin.y -= MKMapSizeWorld.height / 8.0;
MKMapSize size = MKMapSizeWorld;
size.width /= 4.0;
size.height /= 4.0;
boundingMapRect = (MKMapRect) { origin, size };
MKMapRect worldRect = MKMapRectMake(0, 0, MKMapSizeWorld.width, MKMapSizeWorld.height);
boundingMapRect = MKMapRectIntersection(boundingMapRect, worldRect);

很多问题

  • 为什么Apple在计算好boundingMapRect后还要与worldRect相交?
  • 保安人员?
  • 世界矩形中的boundingMapRect并不总是boundingMapRect?
  • 如果我有两个 MKMapPoint 代表我的 CGRect,我就不必这样做,对吧?

问候,


编辑

所以我只能这样做?

// set the smallest rectangle which able to contain this overlay
MKMapPoint leftTopPoint = MKMapPointForCoordinate(leftTopCorner);
MKMapPoint rightBottomPoint = MKMapPointForCoordinate([self bottomRightCoord]);

boundingMapRect = MKMapRectMake(leftTopPoint.x, leftTopPoint.y,
fabs(leftTopPoint.x - rightBottomPoint.x),
fabs(leftTopPoint.y - rightBottomPoint.y));

最佳答案

该代码来自面包屑示例,与大多数覆盖层相比,它可能有点不寻常,因为它是动态更新的。他们实际上将边界区域设置为世界区域的四分之一,这本身就有点不寻常,通常您会期望它小得多。我认为交集只是为了确保生成的矩形绝对位于整个世界矩形内。我不确定是否会推荐此代码作为最佳实践,除非您正在做类似的事情(即创建动态覆盖)。如果您在不间断地环游世界,或者甚至只是跨越国际日期变更线时运行面包屑应用程序,那么大概甚至可以捕获此代码......

关于iphone - 为什么苹果这样做: MKMapRectIntersection(boundingMapRect, worldRect)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15705473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com