Skip to content

Implemented some CGRect's missing APIs #1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 3, 2017
Merged

Conversation

bubski
Copy link
Contributor

@bubski bubski commented Aug 6, 2017

Calculated Geometric Properties

  • CGRect.height: CGFloat { get }
  • CGRect.width: CGFloat { get }
  • CGRect.minX: CGFloat { get }
  • CGRect.midX: CGFloat { get }
  • CGRect.maxX: CGFloat { get }
  • CGRect.minY: CGFloat { get }
  • CGRect.midY: CGFloat { get }
  • CGRect.maxY: CGFloat { get }

Creating Derived Rectangles

  • CGRect.standardized: CGRect { get }
  • CGRect.integral: CGRect { get }
  • CGRect.insetBy(dx: CGFloat, dy: CGFloat) -> CGRect
  • CGRect.offsetBy(dx: CGFloat, dy: CGFloat) -> CGRect
  • CGRect.union(_ r2: CGRect) -> CGRect
  • CGRect.intersection(_ r2: CGRect) -> CGRect
  • CGRect.divided(atDistance: CGFloat, from fromEdge: CGRectEdge) -> (slice: CGRect, remainder: CGRect)

Checking Characteristics

  • CGRect.intersects(_ rect2: CGRect) -> Bool
  • CGRect.contains(_ point: CGPoint) -> Bool
  • CGRect.contains(_ rect2: CGRect) -> Bool
  • CGRect.isEmpty: Bool { get }
  • CGRect.isInfinite: Bool { get }
  • CGRect.isNull: Bool { get }

📝 Also fixed 2 bugs in CGRect : Equatable

CGRect(x: 0, y: 0, width: -5, height: -5) == CGRect(x: -5, y: -5, width: 5, height: 5)
// used to return false
// should standardize before comparison first
let a = CGRect(x: CGFloat.infinity, y: 1, width: 2, height: 3)
let b = CGRect(x: 1, y: CGFloat.infinity, width: 2, height: 3)
a == b
// used to return false
// should return true if both `a` and `b` have any origin's value set to +∞

bubski added 2 commits August 6, 2017 14:50
Fix for 2 bugs:

1.
```swift
CGRect(x: 0, y: 0, width: -5, height: -5) == CGRect(x: -5, y: -5, width: 5, height: 5)
// used to return false
// should standardize before comparison first
```

2.
```swift
let a = CGRect(x: CGFloat.infinity, y: 1, width: 2, height: 3)
let b = CGRect(x: 1, y: CGFloat.infinity, width: 2, height: 3)
a == b
// used to return false
// should return true if both `a` and `b` have any origin's value set to +∞
```
@ianpartridge
Copy link
Contributor

@swift-ci please test

@dplanitzer
Copy link
Contributor

@parkera it looks like that this PR is still awaiting your review. We too ran into the issue of these missing CGRect APIs and ended up implementing them in our internal fork. However we'd really like to move off our internal fork ASAP as it's a pain to keep that up to date. So the sooner this PR could be merged into the official repo the better. Thanks.

@alblue alblue requested a review from phausler October 5, 2017 13:50
@alblue
Copy link
Contributor

alblue commented Oct 5, 2017

@bubski can you rebase these changes onto master so that we can re-run the tests?

@phausler the changes look superficially OK to me but would like confirmation that they are being done in the right place.

@bubski
Copy link
Contributor Author

bubski commented Oct 8, 2017

@alblue done 👌

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Nov 2, 2017

@phausler can you opine on the CGRect changes, please?

@phausler
Copy link
Contributor

phausler commented Nov 2, 2017

looks pretty reasonable to me, they fit all of the expected behaviors on Darwin.

@alblue
Copy link
Contributor

alblue commented Nov 3, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit f23d554 into swiftlang:master Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants