Authored by Quazie

Round one of the removing of magic numbers. Please let me know if #defines are …

…what we want, if not I'll change them.  Also, take a peek at RMGlobalConstants.  Thanks
... ... @@ -27,6 +27,12 @@
#import "RMTileSource.h"
#pragma mark --- begin constants ---
#define kDefaultTileSize 256
#define kDefaultMinTileZoom 0
#define kDefaultMaxTileZoom 18
#pragma mark --- end constants ---
@protocol RMAbstractMercatorWebSource
-(NSString*) tileURL: (RMTile) tile;
... ...
... ... @@ -54,16 +54,16 @@
+(int)tileSideLength
{
return 256;
return kDefaultTileSize;
}
-(float) minZoom
{
return 0;
return kDefaultMinTileZoom;
}
-(float) maxZoom
{
return 18;
return kDefaultMaxTileZoom;
}
/// \bug magic string literals
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMCoreAnimationRenderer.h"
#import <QuartzCore/QuartzCore.h>
#import "RMTile.h"
... ... @@ -45,7 +45,7 @@
// strange data.
layer = [[CAScrollLayer layer] retain];
layer.anchorPoint = CGPointMake(0.0f, 0.0f);
layer.anchorPoint = kTheOrigin;
layer.masksToBounds = YES;
// If the frame is set incorrectly here, it will be fixed when setRenderer is called in RMMapContents
layer.frame = [content screenBounds];
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMGeoHash.h"
static NSString *BASE32 = @"0123456789bcdefghjkmnpqrstuvwxyz";
... ... @@ -49,8 +49,8 @@ static NSString *BORDERS[4][2] =
int bit=0, ch=0;
NSMutableString *geohash = [[[NSMutableString string] retain] autorelease];
CLLocationCoordinate2D loc1 = { -90.0, -180.0 };
CLLocationCoordinate2D loc2 = { 90.0, 180.0 };
CLLocationCoordinate2D loc1 = { -kMaxLat, -kMaxLong };
CLLocationCoordinate2D loc2 = { kMaxLat, kMaxLong };
CLLocationDegrees mid;
int hashLen = 0;
... ... @@ -86,10 +86,10 @@ static NSString *BORDERS[4][2] =
+ (void) convert: (NSString *)geohash toMin: (CLLocationCoordinate2D *)loc1 max: (CLLocationCoordinate2D *)loc2
{
BOOL is_even = TRUE;
loc1->latitude = -90.0;
loc1->longitude = -180.0;
loc2->latitude = 90.0;
loc2->longitude = 180.0;
loc1->latitude = -kMaxLat;
loc1->longitude = -kMaxLong;
loc2->latitude = kMaxLat;
loc2->longitude = kMaxLong;
NSRange range;
int cd, mask;
int geohashLen = [geohash length];
... ...
/*
* RMGlobalConstants.h
* MapView
*
* Created by My Home on 4/29/09.
* Copyright 2009 Brandon "Quazie" Kwaselow. All rights reserved.
*
*/
#define kTheOrigin CGPointMake(0,0)
#define kEmptyRect CGRectMake(0, 0, 0, 0)
#define kMaxLong 180
#define kMaxLat 90
\ No newline at end of file
... ...
... ... @@ -31,6 +31,7 @@
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <CoreLocation/CoreLocation.h>
#import "RMGlobalConstants.h"
/*! \struct RMSphericalTrapezium
... ... @@ -80,9 +81,9 @@ typedef struct {
typedef CLLocationCoordinate2D RMLatLong;
/// \bug magic numbers
static const double kRMMinLatitude = -90.0f;
static const double kRMMaxLatitude = 90.0f;
static const double kRMMinLongitude = -180.0f;
static const double kRMMaxLongitude = 180.0f;
static const double kRMMinLatitude = -kMaxLat;
static const double kRMMaxLatitude = kMaxLat;
static const double kRMMinLongitude = -kMaxLong;
static const double kRMMaxLongitude = kMaxLong;
#endif
\ No newline at end of file
... ...
... ... @@ -43,8 +43,8 @@ enum {
RMMapMinWidthBound = 2
};
#define kDefaultInitialLatitude -33.858771;
#define kDefaultInitialLongitude 151.201596;
#define kDefaultInitialLatitude -33.858771
#define kDefaultInitialLongitude 151.201596
#define kDefaultMinimumZoomLevel 0.0
#define kDefaultMaximumZoomLevel 25.0
... ...
... ... @@ -24,6 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMMapContents.h"
#import "RMMapView.h"
... ... @@ -47,6 +48,8 @@
#import "RMMarker.h"
@interface RMMapContents (PrivateMethods)
- (void)animatedZoomStep:(NSTimer *)timer;
@end
... ... @@ -62,6 +65,13 @@
@synthesize maxZoom;
@synthesize markerManager;
#pragma mark --- begin constants ----
#define kZoomAnimationStepTime 0.03f
#define kZoomAnimationAnimationTime 0.1f
#define kiPhoneMilimeteresPerPixel .1543
#define kZoomRectPixelBuffer 50
#pragma mark --- end constants ----
#pragma mark Initialisation
- (id)initWithView: (UIView*) view
... ... @@ -375,8 +385,8 @@
- (void)adjustMapPlacementWithScale:(float)aScale
{
CGSize adjustmentDelta = {0.0, 0.0};
RMLatLong rightEdgeLatLong = {0, 180};
RMLatLong leftEdgeLatLong = {0,- 180};
RMLatLong rightEdgeLatLong = {0, kMaxLong};
RMLatLong leftEdgeLatLong = {0,- kMaxLong};
CGPoint rightEdge = [self latLongToPixel:rightEdgeLatLong withMetersPerPixel:aScale];
CGPoint leftEdge = [self latLongToPixel:leftEdgeLatLong withMetersPerPixel:aScale];
... ... @@ -438,9 +448,8 @@
float targetZoom = zoomDelta + [self zoom];
// goal is to complete the animation in animTime seconds
/// \bug magic numbers
static const float stepTime = 0.03f;
static const float animTime = 0.1f;
static const float stepTime = kZoomAnimationStepTime;
static const float animTime = kZoomAnimationAnimationTime;
float nSteps = animTime / stepTime;
float zoomIncr = zoomDelta / nSteps;
... ... @@ -737,7 +746,7 @@
if (mercatorToScreenProjection != nil)
return [mercatorToScreenProjection screenBounds];
else
return CGRectMake(0, 0, 0, 0);
return kEmptyRect;
}
-(float) metersPerPixel
... ... @@ -748,7 +757,7 @@
-(void) setMetersPerPixel: (float) newMPP
{
float zoomFactor = newMPP / self.metersPerPixel;
CGPoint pivot = CGPointMake(0,0);
CGPoint pivot = kTheOrigin;
[mercatorToScreenProjection setMetersPerPixel:newMPP];
[imagesOnScreen zoomByFactor:zoomFactor near:pivot];
... ... @@ -859,8 +868,7 @@ static BOOL _performExpensiveOperations = YES;
- (double)scaleDenominator {
double routemeMetersPerPixel = [self metersPerPixel];
/// \bug magic number
double iphoneMillimetersPerPixel = .1543;
double iphoneMillimetersPerPixel = kiPhoneMilimeteresPerPixel;
double truescaleDenominator = routemeMetersPerPixel / (0.001 * iphoneMillimetersPerPixel) ;
return truescaleDenominator;
}
... ... @@ -883,7 +891,7 @@ static BOOL _performExpensiveOperations = YES;
else
{
//convert ne/sw into RMMercatorRect and call zoomWithBounds
float pixelBuffer = 50;
float pixelBuffer = kZoomRectPixelBuffer;
CLLocationCoordinate2D midpoint = {
.latitude = (ne.latitude + sw.latitude) / 2,
.longitude = (ne.longitude + sw.longitude) / 2
... ... @@ -974,12 +982,12 @@ static BOOL _performExpensiveOperations = YES;
// westerly computations:
// -179, -178 -> -179 (min)
// -179, 179 -> 179 (max)
if (fabs(northwestLL.longitude - southwestLL.longitude) <= 180.)
if (fabs(northwestLL.longitude - southwestLL.longitude) <= kMaxLong)
boundingBox.southwest.longitude = fmin(northwestLL.longitude, southwestLL.longitude);
else
boundingBox.southwest.longitude = fmax(northwestLL.longitude, southwestLL.longitude);
if (fabs(northeastLL.longitude - southeastLL.longitude) <= 180.)
if (fabs(northeastLL.longitude - southeastLL.longitude) <= kMaxLong)
boundingBox.northeast.longitude = fmax(northeastLL.longitude, southeastLL.longitude);
else
boundingBox.northeast.longitude = fmin(northeastLL.longitude, southeastLL.longitude);
... ...
... ... @@ -48,6 +48,11 @@
@synthesize deceleration;
@synthesize contents;
#pragma mark --- begin constants ----
#define kDefaultDeceleartionFactor .88f
#define kMinDecelerationDelta 0.01f
#pragma mark --- end constants ----
- (RMMarkerManager*)markerManager
{
return self.contents.markerManager;
... ... @@ -59,7 +64,7 @@
enableDragging = YES;
enableZoom = YES;
decelerationFactor = 0.88f;
decelerationFactor = kDefaultDeceleartionFactor;
deceleration = NO;
// [self recalculateImageSet];
... ... @@ -510,7 +515,7 @@
}
- (void)incrementDeceleration:(NSTimer *)timer {
if (ABS(_decelerationDelta.width) < 0.01f && ABS(_decelerationDelta.height) < 0.01f) {
if (ABS(_decelerationDelta.width) < kMinDecelerationDelta && ABS(_decelerationDelta.height) < kMinDecelerationDelta) {
[self stopDeceleration];
return;
}
... ...
... ... @@ -37,7 +37,6 @@
@synthesize textForegroundColor;
@synthesize textBackgroundColor;
/// \bug magic number
#define defaultMarkerAnchorPoint CGPointMake(0.5, 0.5)
+ (UIFont *)defaultFont
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMMercatorToScreenProjection.h"
#include "RMProjection.h"
... ... @@ -115,7 +115,7 @@
//RMLog(@"test: %f %f", test.x, test.y);
//RMLog(@"correct: %f %f", origin.easting, origin.y);
// CGPoint p = [self projectMercatorPoint:[self projectScreenPointToMercator:CGPointMake(0,0)]];
// CGPoint p = [self projectMercatorPoint:[self projectScreenPointToMercator:kTheOrigin]];
// RMLog(@"origin at %f %f", p.x, p.y);
// CGPoint q = [self projectMercatorPoint:[self projectScreenPointToMercator:CGPointMake(100,100)]];
// RMLog(@"100 100 at %f %f", q.x, q.y);
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMPath.h"
#import "RMMapView.h"
#import "RMMapContents.h"
... ... @@ -36,6 +36,8 @@
@synthesize origin;
#define kDefaultLineWidth 100
/// \bug default values for lineWidth, lineColor, fillColor are hardcoded
- (id) initWithContents: (RMMapContents*)aContents
{
... ... @@ -46,7 +48,7 @@
path = CGPathCreateMutable();
lineWidth = 100.0f;
lineWidth = kDefaultLineWidth;
drawingMode = kCGPathFillStroke;
lineColor = [UIColor blackColor];
fillColor = [UIColor redColor];
... ... @@ -89,7 +91,7 @@
boundsInMercators.size.width += 2*lineWidth;
boundsInMercators.size.height += 2*lineWidth;
CGRect pixelBounds = RMScaleCGRectAboutPoint(boundsInMercators, 1.0f / scale, CGPointMake(0,0));
CGRect pixelBounds = RMScaleCGRectAboutPoint(boundsInMercators, 1.0f / scale, kTheOrigin);
// RMLog(@"old bounds: %f %f %f %f", self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height);
self.bounds = pixelBounds;
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "proj_api.h"
#import "RMProjection.h"
... ... @@ -174,7 +174,7 @@ static RMProjection* _osgb = nil;
}
else
{
RMProjectedRect theBounds = RMMakeProjectedRect(-180, -90, 360, 180);
RMProjectedRect theBounds = RMMakeProjectedRect(-kMaxLong, -kMaxLat, 360, kMaxLong);
/// \bug magic numbers embedded in code, this one's probably ok
_latlong = [[RMProjection alloc] initWithString:@"+proj=latlong +ellps=WGS84" InBounds: theBounds];
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMTileImage.h"
#import "RMWebTileImage.h"
#import "RMTileLoader.h"
... ... @@ -52,7 +52,7 @@ NSString * const RMMapImageLoadingCancelledNotification = @"MapImageLoadingCance
loadingPriorityCount = 0;
lastUsedTime = nil;
dataPending = nil;
screenLocation = CGRectMake(0, 0, 0, 0);
screenLocation = kEmptyRect;
[self touch];
... ... @@ -228,7 +228,7 @@ NSString * const RMMapImageLoadingCancelledNotification = @"MapImageLoadingCance
{
layer = [[CALayer alloc] init];
layer.contents = nil;
layer.anchorPoint = CGPointMake(0.0f, 0.0f);
layer.anchorPoint = kTheOrigin;
layer.bounds = CGRectMake(0, 0, screenLocation.size.width, screenLocation.size.height);
layer.position = screenLocation.origin;
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"w
#import "RMTileLoader.h"
#import "RMTileImage.h"
... ... @@ -80,7 +80,7 @@ NSString* const RMTileRequested = @"RMTileRequested";
-(void) clearLoadedBounds
{
loadedBounds = CGRectMake(0, 0, 0, 0);
loadedBounds = kEmptyRect;
// loadedTiles.origin.tile = RMTileDummy();
}
-(BOOL) screenIsLoaded
... ...
... ... @@ -24,7 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMTiledLayerController.h"
#import "RMFractalTileProjection.h"
#import "RMTileSource.h"
... ... @@ -55,7 +55,7 @@
RMXYRect boundsRect = tileProjection.bounds;
layer.bounds = CGRectMake(boundsRect.origin.x, boundsRect.origin.y, boundsRect.size.width, boundsRect.size.height) ;
layer.position = CGPointMake(0, 0);
layer.position = kTheOrigin;
[self setScale:1];
[layer setNeedsDisplay];
... ...
... ... @@ -33,7 +33,7 @@
- (NSString*) tileURL: (RMTile) tile
{
NSInteger zoom = 18 - tile.zoom;
NSInteger zoom = kDefaultMaxTileZoom - tile.zoom;
NSInteger shift = tile.zoom -1;
NSInteger x = tile.x;
NSInteger y = pow(2,shift)-1-tile.y;
... ...
... ... @@ -96,6 +96,7 @@
2BEC61320F8ACC24008FB858 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E65680E80E830001663B6 /* QuartzCore.framework */; };
2BEC61330F8ACC25008FB858 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
3849889C0F6F758100496293 /* libProj4.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 38D818500F6F67B90034598B /* libProj4.a */; };
96492C400FA8AD3400EBA6D2 /* RMGlobalConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 96492C3F0FA8AD3400EBA6D2 /* RMGlobalConstants.h */; };
96FE8E360F72D01B00A11CF0 /* RMYahooMapSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 96FE8E340F72D01B00A11CF0 /* RMYahooMapSource.h */; };
96FE8E370F72D01B00A11CF0 /* RMYahooMapSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 96FE8E350F72D01B00A11CF0 /* RMYahooMapSource.m */; };
B8474B9A0EB40094006A0BC1 /* FMDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = B8474B8D0EB40094006A0BC1 /* FMDatabase.h */; };
... ... @@ -244,6 +245,7 @@
3866784C0F6B9B9200C56B17 /* MapView.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapView.framework; path = build/MapView.framework; sourceTree = "<group>"; };
38DAD5490F739BAD00D1DF51 /* Canonical.framework.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = Canonical.framework.tar; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96492C3F0FA8AD3400EBA6D2 /* RMGlobalConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMGlobalConstants.h; sourceTree = "<group>"; };
966504690F6869810036562A /* loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = loading.png; sourceTree = "<group>"; };
96FE8E340F72D01B00A11CF0 /* RMYahooMapSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMYahooMapSource.h; sourceTree = "<group>"; };
96FE8E350F72D01B00A11CF0 /* RMYahooMapSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMYahooMapSource.m; sourceTree = "<group>"; };
... ... @@ -642,6 +644,7 @@
B8C9740D0E8A196E007D16AD /* Map */ = {
isa = PBXGroup;
children = (
96492C3F0FA8AD3400EBA6D2 /* RMGlobalConstants.h */,
090FE3130ECD71A500035FBC /* RMTilesUpdateDelegate.h */,
B8C974690E8A1A50007D16AD /* RMMapView.h */,
B8C9746A0E8A1A50007D16AD /* RMMapView.m */,
... ... @@ -737,6 +740,7 @@
2B5682720F68E36000E8DF40 /* RMOpenAerialMapSource.h in Headers */,
96FE8E360F72D01B00A11CF0 /* RMYahooMapSource.h in Headers */,
F5C12D2A0F8A86CA00A894D2 /* RMGeoHash.h in Headers */,
96492C400FA8AD3400EBA6D2 /* RMGlobalConstants.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...