Sight
A spatial search μlibrary powered by GameplayKit 👾
Install / Use
/learn @jasonnam/SightREADME
Welcome to Sight, a Swift spatial search μlibrary. Its primary goal is to extend Apple's GameplayKit framework.
Usage
Sight helps you quickly determine which object is closest to a given position.
This is done via a Region instance, which represents the space where all the objects are positioned in.
import Sight
// Define a region with bounds and search radius.
let region = Region<String>(
minBounds: SIMD2(x: 0, y: 0),
maxBounds: SIMD2(x: 1, y: 1),
searchRadius: 0.3
)
// Place objects in the region.
region.add("A", at: SIMD2(x: 0, y: 0.1))
region.add("B", at: SIMD2(x: 0.5, y: 0))
region.add("C", at: SIMD2(x: 0, y: 0.8))
// Find the closest object to any position.
region.closestValue(to: SIMD2(x: 0.5, y: 0.2)) // "B"
region.closestValue(to: SIMD2(x: 1, y: 0)) // nil
Region is optimized for spatial searches, this is why during its initialization both search radius and its bounds are required.
You can find many more examples in the Tests folder.
Installation
Sight is distributed using the Swift Package Manager. To install it into a project, follow this tutorial and use this repository URL: https://github.com/zntfdr/Sight.git.
Credits
Sight was built by Federico Zanetello as a component of Bangkok Metro.
If you'd like to know more on how this library works, please refer to GameplayKit's GKQuadtree overview.
Contributions and Support
All users are welcome and encouraged to become active participants in the project continued development — by fixing any bug that they encounter, or by improving the documentation wherever it’s found to be lacking.
If you'd like to make a change, please open a Pull Request, even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue.
Thank you and please enjoy using Sight!
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
