Skip to content

Commit

Permalink
Merge pull request square#99 from square/entin/consistent-rounding-names
Browse files Browse the repository at this point in the history
Update pixel rounding method names to be consistent
  • Loading branch information
NickEntin authored May 22, 2023
2 parents 9dac3be + 4168b50 commit 7df37fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Paralayout/PixelRounding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ extension CGRect {
/// - parameter scaleFactor: The pixel scale to use, e.g. a UIScreen, UIView, or explicit value (pass `0` to *not*
/// snap to pixel).
/// - returns: A new rect with pixel-aligned boundaries, enclosing the original rect.
public func expandedToPixel(_ scaleFactor: ScaleFactorProviding) -> CGRect {
public func expandedToPixel(in scaleFactor: ScaleFactorProviding) -> CGRect {
return CGRect(
left: minX.flooredToPixel(in: scaleFactor),
top: minY.flooredToPixel(in: scaleFactor),
Expand All @@ -185,7 +185,7 @@ extension CGRect {
/// - parameter scaleFactor: The pixel scale to use, e.g. a UIScreen, UIView, or explicit value (pass `0` to *not*
/// snap to pixel).
/// - returns: A new rect with pixel-aligned boundaries, enclosed by the original rect.
public func contractedToPixel(_ scaleFactor: ScaleFactorProviding) -> CGRect {
public func contractedToPixel(in scaleFactor: ScaleFactorProviding) -> CGRect {
return CGRect(
left: minX.ceiledToPixel(in: scaleFactor),
top: minY.ceiledToPixel(in: scaleFactor),
Expand Down
2 changes: 1 addition & 1 deletion ParalayoutTests/AspectRatioTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ final class AspectRatioTests: XCTestCase {
layoutDirections
) { ratio, rectangle, scale, position, layoutDirection in
// Make sure the source rectangle matches the scale factor we're testing.
let rect = rectangle.expandedToPixel(scale)
let rect = rectangle.expandedToPixel(in: scale)

// An AspectRatio's size that fits a rect of the same aspect ratio should also be the same as the size of
// that rect.
Expand Down
8 changes: 4 additions & 4 deletions ParalayoutTests/PixelRoundingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ final class PixelRoundingTests: XCTestCase {

func testRectPixelRounding() {
XCTAssertEqual(
CGRect(left: 10.6, top: 10.4, right: 50.6, bottom: 50.6).expandedToPixel(TestScreen.at2x),
CGRect(left: 10.6, top: 10.4, right: 50.6, bottom: 50.6).expandedToPixel(in: TestScreen.at2x),
CGRect(left: 10.5, top: 10.0, right: 51, bottom: 51)
)
XCTAssertEqual(
CGRect(left: 10.7, top: 10.4, right: 50.5, bottom: 50.7).expandedToPixel(TestScreen.at3x),
CGRect(left: 10.7, top: 10.4, right: 50.5, bottom: 50.7).expandedToPixel(in: TestScreen.at3x),
CGRect(left: CGFloat(10) + 2 / 3, top: CGFloat(10) + 1 / 3, right: CGFloat(50) + 2 / 3, bottom: 51)
)

XCTAssertEqual(
CGRect(left: 10.6, top: 10.4, right: 50.6, bottom: 50.6).contractedToPixel(TestScreen.at2x),
CGRect(left: 10.6, top: 10.4, right: 50.6, bottom: 50.6).contractedToPixel(in: TestScreen.at2x),
CGRect(left: 11, top: 10.5, right: 50.5, bottom: 50.5)
)
XCTAssertEqual(
CGRect(left: 10.7, top: 10.4, right: 50.5, bottom: 50.7).contractedToPixel(TestScreen.at3x),
CGRect(left: 10.7, top: 10.4, right: 50.5, bottom: 50.7).contractedToPixel(in: TestScreen.at3x),
CGRect(left: 11, top: CGFloat(10) + 2 / 3, right: CGFloat(50) + 1 / 3, bottom: CGFloat(50) + 2 / 3)
)
}
Expand Down

0 comments on commit 7df37fa

Please sign in to comment.