Skip to content

A simple Quad Tree data structure implimentation

License

Notifications You must be signed in to change notification settings

hershalle/QuadTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuadTree

Compatibility

QuadTree is written in Swift 4 and requires Xcode 9+

Installation

CocoaPods

Make sure you have CocoaPods installed on your system:

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. You can install it with the following command:

$ sudo gem install cocoapods

Add a podfile:

platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
    pod 'QuadTree', :git => 'https://github.com/hershalle/QuadTree.git'
end

Then, run the following command:

$ pod install

Usage

Construct an empty tree

QuadTree holds a point and an asosiate object of some type T. Some use cases for T are:

  • Color: The color of the pixel at that point
  • View: A node at that point
  • Data: A quadTree can represent a sparse matrix

here I chose to use String:

import QuadTree

let quadTree = QuadTree<String>(bounds: bounds)

The points of the tree must be contained inside the bounds.

Add a point

quadTree.add(point: point, object: "This is an associated value")

point is CGPoint

Tree traversal

quadTree.traverse { (leaf, bounds) in
	guard let leaf = leaf else {
   		print("Empty quad in bounds \(bounds)")
		return
	}
            
	print("found object \(leaf.object) at point: \(leaf.point) inside quad \(bounds)")
}

Contributing

If you have any ideas, just open an issue and tell me what you think. You can also contact me via Twitter @hershalle

If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

Licensing

This project is licensed under MIT license.

About

A simple Quad Tree data structure implimentation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published