Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit be4bdcd

Browse files
committed
Fixed a bug where the opposite condition was used on gatherDataInRange, also fixed a couple of other minor bugs with color and details (waste two hours on that stupid opposite condition bug)
1 parent 7f18f55 commit be4bdcd

File tree

9 files changed

+19
-36
lines changed

9 files changed

+19
-36
lines changed

TBAnnotationClustering-Swift.xcodeproj/xcuserdata/Ran.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,4 @@
22
<Bucket
33
type = "1"
44
version = "2.0">
5-
<Breakpoints>
6-
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8-
<BreakpointContent
9-
shouldBeEnabled = "Yes"
10-
ignoreCount = "0"
11-
continueAfterRunningActions = "No"
12-
filePath = "TBAnnotationClustering-Swift/TBCoordinateQuadTree.swift"
13-
timestampString = "473381029.416535"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "50"
17-
endingLineNumber = "50"
18-
landmarkName = "clusteredAnnotationWithinMapRect(_:zoomScale:)"
19-
landmarkType = "5">
20-
</BreakpointContent>
21-
</BreakpointProxy>
22-
</Breakpoints>
235
</Bucket>

TBAnnotationClustering-Swift/Base.lproj/LaunchScreen.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
56
</dependencies>
67
<scenes>
78
<!--View Controller-->
@@ -15,7 +16,6 @@
1516
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
1617
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1718
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<animations/>
1919
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
2020
</view>
2121
</viewController>

TBAnnotationClustering-Swift/TBClusterAnnotationView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class TBClusterAnnotationView: MKAnnotationView {
2020
super.init(coder: aDecoder)
2121
}
2222

23+
override init(frame: CGRect) {
24+
super.init(frame: frame)
25+
}
26+
2327
override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
2428
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
2529

@@ -90,6 +94,6 @@ class TBClusterAnnotationView: MKAnnotationView {
9094
CGContextStrokeEllipseInRect(context, circleFrame)
9195

9296
innerCircleFillColor.setFill()
93-
CGContextStrokeEllipseInRect(context, circleFrame)
97+
CGContextFillEllipseInRect(context, circleFrame)
9498
}
9599
}

TBAnnotationClustering-Swift/TBCoordinateQuadTree.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ class TBCoordinateQuadTree : NSObject {
5050
totalX += data.x
5151
totalY += data.y
5252

53-
let hotelInfo = data.data
54-
names.append(hotelInfo.name)
55-
56-
if let phoneNum = hotelInfo.phoneNumber! {
57-
phoneNumbers.append(phoneNum)
53+
if let hotelInfo = data.data as? TBHotelInfo {
54+
names.append(hotelInfo.hotelName)
55+
phoneNumbers.append(hotelInfo.hotelPhoneNumber)
5856
}
5957
})
6058

@@ -66,7 +64,7 @@ class TBCoordinateQuadTree : NSObject {
6664
clusteredAnnotations.append(annotation)
6765
}
6866

69-
if count > 1 {
67+
if count == 1 {
7068
let coordinate = CLLocationCoordinate2D(latitude: totalX, longitude: totalY)
7169
let annotation = TBClusterAnnotation(coordinate: coordinate, count: count)
7270
annotation.title = names.last!
@@ -92,10 +90,10 @@ class TBCoordinateQuadTree : NSObject {
9290
return TBBoundingBox(x: minLat, y: minLong, xf: maxLat, yf: maxLong)
9391
}
9492

95-
func TBZoomScaleToZoomLevel(scale:MKZoomScale) -> Double {
96-
let totalTilesAtMaxZoom = MKMapSizeWorld.width / 256.0;
97-
let zoomLevelAtMaxZoom = log2(totalTilesAtMaxZoom);
98-
let zoomLevel = max(0, zoomLevelAtMaxZoom + floor(log2(Double(scale)) + 0.5));
93+
func TBZoomScaleToZoomLevel(scale:MKZoomScale) -> Int {
94+
let totalTilesAtMaxZoom = MKMapSizeWorld.width / 256.0
95+
let zoomLevelAtMaxZoom = Int(log2(totalTilesAtMaxZoom))
96+
let zoomLevel = Int(max(0, Double(zoomLevelAtMaxZoom) + floor(log2(Double(scale)) + 0.5)));
9997

10098
return zoomLevel;
10199
}

TBAnnotationClustering-Swift/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ViewController: UIViewController, MKMapViewDelegate {
4343
let toRemove = NSMutableSet(set: before)
4444
toRemove.minusSet(after as Set<NSObject>)
4545

46-
NSOperationQueue().addOperationWithBlock() {
46+
NSOperationQueue.mainQueue().addOperationWithBlock() {
4747
self.mapView.addAnnotations(toAdd.allObjects as! [MKAnnotation])
4848
self.mapView.removeAnnotations(toRemove.allObjects as! [MKAnnotation])
4949
}

TBBoundingBox.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct TBBoundingBox {
2727
}
2828

2929
func intersectWith(other:TBBoundingBox) -> Bool {
30-
return (x0 <= other.xf && xf >= other.x0) &&
31-
(y0 <= other.yf && yf >= other.y0)
30+
return x0 <= other.xf && xf >= other.x0 && y0 <= other.yf && yf >= other.y0
3231
}
3332
}

TBQuadTreeNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TBQuadTreeNode {
7777

7878
func gatherDataInRange(range: TBBoundingBox, action: (TBQuadTreeNodeData) -> Void) {
7979
// If range is not contained in the node's boundingBox then bail
80-
if boundingBox.intersectWith(range) {
80+
if !boundingBox.intersectWith(range) {
8181
return
8282
}
8383

0 commit comments

Comments
 (0)