From a21cb7dd9203adb8363fa96a0749d32171349425 Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Tue, 17 Jun 2014 23:22:28 +0200 Subject: [PATCH] Fixes #37. --- CHANGELOG.md | 4 ++++ Demo/DemoTests/NAMapViewTests.m | 4 ++++ NAMapKit/NAMapView.m | 3 +++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 498dd12..0f9afe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Next + +* [#37](https://github.com/neilang/NAMapKit/issues/37) - Added assert inside NAMapView#zoomRelativePoint when returning `{NaN, NaN}` - [@ashfurrow](http://github.com/ashfurrow). + #### [3.1.1](https://github.com/neilang/NAMapKit/tree/v3.1.1) (5/12/2014) * [#31](https://github.com/neilang/NAMapKit/issues/31) - Fix: `NAPinAnnotation` and `NAPinAnnotationView` retain cycle - [@dblock](https://github.com/dblock). diff --git a/Demo/DemoTests/NAMapViewTests.m b/Demo/DemoTests/NAMapViewTests.m index d58fdae..37cbdc2 100644 --- a/Demo/DemoTests/NAMapViewTests.m +++ b/Demo/DemoTests/NAMapViewTests.m @@ -19,6 +19,10 @@ expect(mapView).toNot.beNil(); expect(mapView).to.beKindOf([NAMapView class]); }); + + it(@"asserts on zoomRelativePoint: with a zero content size", ^{ + expect(^{[mapView zoomRelativePoint:CGPointZero];}).to.raise(@"NSInternalInconsistencyException"); + }); }); SpecEnd diff --git a/NAMapKit/NAMapView.m b/NAMapKit/NAMapView.m index a31feed..3069eda 100644 --- a/NAMapKit/NAMapView.m +++ b/NAMapKit/NAMapView.m @@ -121,6 +121,9 @@ - (void)centerOnPoint:(CGPoint)point animated:(BOOL)animate - (CGPoint)zoomRelativePoint:(CGPoint)point { + BOOL hasContentSize = fabsf(self.originalSize.width) > 0 && fabsf(self.originalSize.height) > 0; + NSAssert(hasContentSize, @"originalSize dimension is zero, will result in NaN in returned value."); + CGFloat x = (self.contentSize.width / self.originalSize.width) * point.x; CGFloat y = (self.contentSize.height / self.originalSize.height) * point.y; return CGPointMake(round(x), round(y));