A set of Swift utilities for dealing with rectangles, including a way to generically build your own!
This package includes:
IntRect
and UIntPoint
Who knew there was so much to be done with rectangles?
This library aims to never get in your way. Minimal arbitrary decisions, maximum flexibility.
For example, other frameworks might say that they help you find the distance from any CGPoint
to another, but don't provide that functionality to any other type.
This one doesn't care what types the two are, as long as thier x
and y
coordinates use the same type. That means if you want to measure the distance from some CGPoint
to some custom 2D point-like structure which also uses CGFloat
s, this will happily let you do that with no fuss.
For example, let's say you made this for your specific requirements:
struct AnnotatedPoint {
var x: CGFloat
var y: CGFloat
var annotation: String
}
You can quickly and easily find the distance between that and a CGPoint
like this:
import RectangleTools
extension AnnotatedPoint: Point2D {
// Nothing to do! 🦆
}
func isCloseEnoughToSnap(cursorPosition: AnnotatedPoint, to anchor: CGPoint) -> Bool {
cursorPosition.distance(to: anchor) < snapDistnce
}
Over 2,000 test assertions prove that this library works as it says it does
This library was created for enterprise-scale applications, and is being used by multiple corporations in production today.
If you're using this with SwiftUI, you can also import RectangleTools_SwiftUI
to gain SwiftUI-specific rectangle tools!
link |
Stars: 0 |
Last commit: 3 hours ago |
And We did it without breaking existing code! Woo!
This change makes that protocol more generic, so it can be applied to sizes, rectangles, anything which conforms. By default now, all integer sizes and rectangles gain this behavior which was once available only to sizes.
Part of this was removing the requirement for conforming types to also conform to Size2D
, and creating a new conformance requirement: CartesianMeasurable
. We then changed Size2D
to require CartesianMeasurable
, and that enabled this broadening.
2.12.0
Size2DCollection
to Collection2D
2.12.1
distance
2.12.2
Full Changelog: https://github.com/RougeWare/Swift-Rectangle-Tools/compare/2.11.0...2.12.2
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics