Authored by Quazie

Version one of issue 103 fix. I need someone to code review it for me. This do…

…es not break any existing functionality, though I'm not sure if there is a faster way to do my calculations, i KNOW that the results can't be cached though, as the origin changes frequently, as do the x,y positions.  Another set of eyes on this would be great.  The fix is as follows:  If the position is closer to the current origin, use it, else use an origin shifted one projection width to the left/right whichever is closest
... ... @@ -127,33 +127,36 @@
scale *= factor;
}
/*! \bug returns wrong values if +/- 180 degree longitude is on screen
This bug is certainly one (the?) cause of Issue 103 and Issue 20, and probably also Issue 43 and Issue 54.
*/
- (CGPoint) projectXYPoint:(RMXYPoint)aPoint withScale:(float)aScale
{
/// \bug TODO: This should return the closest, even if thats on the other side of the world...
CGPoint aPixelPoint;
CGFloat originX = origin.x;
CGFloat boundsWidth = [projection bounds].size.width;
CGFloat pointX = aPoint.x - boundsWidth/2;
CGFloat left = sqrt((pointX - (originX - boundsWidth))*(pointX - (originX - boundsWidth)));
CGFloat middle = sqrt((pointX - originX)*(pointX - originX));
CGFloat right = sqrt((pointX - (originX + boundsWidth))*(pointX - (originX + boundsWidth)));
if(middle <= left && middle <= right){
aPixelPoint.x = (aPoint.x - originX) / aScale;
} else if(left <= middle && left <= right){
aPixelPoint.x = (aPoint.x - (originX-boundsWidth)) / aScale;
} else{ //right
aPixelPoint.x = (aPoint.x - (originX+boundsWidth)) / aScale;
}
aPixelPoint.x = (aPoint.x - origin.x) / aScale;
aPixelPoint.y = screenBounds.size.height - (aPoint.y - origin.y) / aScale;
return aPixelPoint;
return aPixelPoint;
}
/// \bug returns wrong values if +/- 180 degree longitude is on screen
- (CGPoint) projectXYPoint: (RMXYPoint)aPoint
{
/// \bug TODO: This should return the closest, even if thats on the other side of the world.
return [self projectXYPoint:aPoint withScale:scale];
}
/// \warning probably returns wrong values if +/- 180 degree longitude is on screen
- (CGRect) projectXYRect: (RMXYRect) aRect
{
/// \bug TODO: This should return the closest, even if thats on the other side of the world.
CGRect aPixelRect;
aPixelRect.origin = [self projectXYPoint: aRect.origin];
aPixelRect.size.width = aRect.size.width / scale;
... ...