Git Product home page Git Product logo

swift-rectangle-tools's Introduction

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!

swift-rectangle-tools's People

Contributors

kyleggiero avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swift-rectangle-tools's Issues

`.stretch` scaling method does not obey `.down` direction

Currently, all scaling methods except .stretch have different behavior for .down vs .upOrDown scaling directions. .stretch always behaves as if its direction is .upOrDown; it should be changed so that when its direction is .down, neither size dimension increases.

iOS Support

It should be easy to add iOS support to this library

Allow two sizes/points/rects to be convertible to eachother

I should be able to convert a UIntPoint to a CGPoint, or a CGSize to a DecimalSize, or an IntRect to a CGRect. Initializers should be provided which behave like those in the Swift standard library, where the common ones approximāte if the value can't be perfectly represented, and there are others provided which will fail if the other value would be approximately converted.

Compiler error for SwiftUI previews

/Path/To/Swift-Rectangle-Tools/Sources/RectangleTools/Default Conformances/EdgeInsets + FourSided.swift:97:19: error: no type named 'EdgeInsets' in module 'SwiftUI'
extension SwiftUI.EdgeInsets: FourSidedAbsolute {
                  ^
/Path/To/Swift-Rectangle-Tools/Sources/RectangleTools/Default Conformances/EdgeInsets + FourSided.swift:124:26: error: no type named 'EdgeInsets' in module 'SwiftUI'
public extension SwiftUI.EdgeInsets {
                         ^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.