Skip to content

Commit b68e1fd

Browse files
committed
Fix a few typos in QuadTree/README.md
Quadrees -> Quadtrees containts -> contains Wiki -> Wikipedia Also my editor automatically removed trailing spaces from empty lines
1 parent 0c2aa34 commit b68e1fd

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

QuadTree/README.md

+16-17
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ A quadtree is a [tree](https://github.com/raywenderlich/swift-algorithm-club/tre
66

77
### Problem
88

9-
Consider the following problem: your need to store a number of points (each point is a pair of `X` and `Y` coordinates) and then you need to answer which points lie in a certain rectangular region. A naive solution would be to store the points inside an array and then iterate over the points and check each one individually. This solution runs in O(n) though.
9+
Consider the following problem: your need to store a number of points (each point is a pair of `X` and `Y` coordinates) and then you need to answer which points lie in a certain rectangular region. A naive solution would be to store the points inside an array and then iterate over the points and check each one individually. This solution runs in O(n) though.
1010

1111
### A Better Approach
1212

13-
Quadrees are most commonly used to partition a two-dimensional space by recursively subdividing it into four regions(quadrants). Let's see how we can use a Quadtree to store the points.
13+
Quadtrees are most commonly used to partition a two-dimensional space by recursively subdividing it into four regions(quadrants). Let's see how we can use a Quadtree to store the points.
1414

1515
Each node in the tree represents a rectangular region and stores a limited number(`maxPointCapacity`) of points that all lie in its region.
1616

@@ -40,7 +40,7 @@ class QuadTreeNode {
4040
init(rect: Rect) {
4141
self.rect = rect
4242
}
43-
43+
4444
...
4545
}
4646

@@ -52,11 +52,11 @@ extension QuadTreeNode {
5252

5353
@discardableResult
5454
func add(point: Point) -> Bool {
55-
56-
if !rect.containts(point: point) {
55+
56+
if !rect.contains(point: point) {
5757
return false
5858
}
59-
59+
6060
switch type {
6161
case .internal(let children):
6262
// pass the point to one of the children
@@ -75,7 +75,7 @@ extension QuadTreeNode {
7575
}
7676
return true
7777
}
78-
78+
7979
private func subdivide() {
8080
switch type {
8181
case .leaf:
@@ -105,33 +105,33 @@ To find the points that lie in a given region we can now traverse the tree from
105105
class QuadTree {
106106

107107
...
108-
108+
109109
let root: QuadTreeNode
110-
110+
111111
public func points(inRect rect: Rect) -> [Point] {
112112
return root.points(inRect: rect)
113113
}
114114
}
115115

116116
extension QuadTreeNode {
117117
func points(inRect rect: Rect) -> [Point] {
118-
118+
119119
// if the node's rect and the given rect don't intersect, return an empty array,
120120
// because there can't be any points that lie the node's (or its children's) rect and
121121
// in the given rect
122122
if !self.rect.intersects(rect: rect) {
123123
return []
124124
}
125-
125+
126126
var result: [Point] = []
127-
127+
128128
// collect the node's points that lie in the rect
129129
for point in points {
130-
if rect.containts(point: point) {
130+
if rect.contains(point: point) {
131131
result.append(point)
132132
}
133133
}
134-
134+
135135
switch type {
136136
case .leaf:
137137
break
@@ -141,7 +141,7 @@ extension QuadTreeNode {
141141
result.append(contentsOf: childNode.points(inRect: rect))
142142
}
143143
}
144-
144+
145145
return result
146146
}
147147
}
@@ -154,7 +154,6 @@ Both adding a point and searching can still take up to O(n) in the worst case, s
154154

155155
Displaying a large amount of objects in a MapView - a great use case for a Quadtree ([Thoughtbot Article](https://robots.thoughtbot.com/how-to-handle-large-amounts-of-data-on-maps))
156156

157-
More info on [Wiki](https://en.wikipedia.org/wiki/Quadtree)
157+
More info on [Wikipedia](https://en.wikipedia.org/wiki/Quadtree)
158158

159159
*Written for Swift Algorithm Club by Timur Galimov*
160-

0 commit comments

Comments
 (0)