Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnsundell/cgoperators
Easily manipulate CGPoints, CGSizes and CGVectors using math operators
https://github.com/johnsundell/cgoperators
coregraphics operators swift xcode
Last synced: 3 months ago
JSON representation
Easily manipulate CGPoints, CGSizes and CGVectors using math operators
- Host: GitHub
- URL: https://github.com/johnsundell/cgoperators
- Owner: JohnSundell
- License: mit
- Created: 2017-07-14T17:44:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-05T22:51:43.000Z (about 7 years ago)
- Last Synced: 2024-10-14T01:23:55.366Z (3 months ago)
- Topics: coregraphics, operators, swift, xcode
- Language: Swift
- Size: 26.4 KB
- Stars: 148
- Watchers: 4
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Welcome to `CGOperators`, a small Swift framework that enables you to easily manipulate Core Graphics' vector types (`CGPoint`, `CGSize` and `CGVector`) using math operators. It can help you write compact, yet highly readable code when dealing with things like image sizes and frame-based layouts.
## Examples
**Add two vectors**
```swift
let point = view.frame.origin + CGPoint(x: 10, y: 20)
let size = image.size + view.frame.size
let vector = physicsWorld.gravity + player.size
```**Subtract two vectors**
```swift
let point = view.frame.origin - CGPoint(x: 10, y: 20)
let size = image.size - view.frame.size
let vector = physicsWorld.gravity - player.size
```**Multiply a vector with a constant**
```swift
view.frame.size = image.size * 4
button.frame.origin = superview.bounds.size * 2
physicsWorld.gravity = player.position * 10
```**Divide a vector by a constant**
```swift
view.frame.size = image.size / 4
button.frame.origin = superview.bounds.size / 2
physicsWorld.gravity = player.position / 10
```## Installation
**Using [CocoaPods](https://cocoapods.org)**
Add `pod CGOperators` to your `Podfile`
**Using [Carthage](https://github.com/Carthage/Carthage)**
Add `git "JohnSundell/CGOperators"` to your `Cartfile`
**Using the [Swift Package Manager](https://github.com/apple/swift-package-manager)**
Add `Package(url: "https://github.com/JohnSundell/CGOperators.git", majorVersion: 1)` to your `Package.swift` file.
**Using [Marathon](https://github.com/JohnSundell/Marathon)**
Run `marathon add https://github.com/JohnSundell/CGOperators.git` on the command line.
## Help, feedback or suggestions?
- [Open an issue](https://github.com/JohnSundell/CGOperators/issues/new) if you need help, if you found a bug, or if you want to discuss a feature request.
- [Open a PR](https://github.com/JohnSundell/CGOperators/pull/new/master) if you want to make some change to `CGOperators`.
- Contact [@johnsundell on Twitter](https://twitter.com/johnsundell) for discussions, news & announcements about `CGOperators` and other open source projects.