RectangleTools

2.12.2

A set of Swift utilities for dealing with rectangles, including a way to generically build your own!
RougeWare/Swift-Rectangle-Tools

What's New

2.12 –  Changed `Size2DCollection` to `Collection2D`

2023-11-16T22:07:10Z

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.

What's Changed

  • 2.12.0
    • #66 Changed Size2DCollection to Collection2D
  • 2.12.1
    • #67 Added distance
  • 2.12.2
    • #68 Made (min/max)X(min/max)Y more useful

Full Changelog: 2.11.0...2.12.2

Swift Rectangle Tools

A set of Swift utilities for dealing with rectangles, including a way to generically build your own!

This package includes:

  • new types such as IntRect and UIntPoint
  • conveniences for doing math with various points in rectangles
  • centering and scaling
  • generic protocols to unify math across all Cartesian types
  • conveniences for measuring and placing rectangles/points/sizes
  • and much more...

Who knew there was so much to be done with rectangles?

Easy To Adopt

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 CGFloats, 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
}

Thoroughly Tested

Over 2,000 test assertions prove that this library works as it says it does

Battle Hardened

This library was created for enterprise-scale applications, and is being used by multiple corporations in production today.

SwiftUI

If you're using this with SwiftUI, you can also import RectangleTools_SwiftUI to gain SwiftUI-specific rectangle tools!

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

Last updated: Sat Oct 19 2024 02:33:57 GMT-0900 (Hawaii-Aleutian Daylight Time)