-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into kve/api-ergo-improvements
- Loading branch information
Showing
22 changed files
with
902 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import CoreGraphics | ||
|
||
extension CGRect { | ||
init(minX: CGFloat, minY: CGFloat, maxX: CGFloat, maxY: CGFloat) { | ||
self.init( | ||
x: minX, | ||
y: minY, | ||
width: maxX - minX, | ||
height: maxY - minY) | ||
} | ||
|
||
/// Creates a new rectangle by rounding each of the min and max X and Y values of this rect individually. | ||
/// - Parameters: | ||
/// - rule: The rounding rule. | ||
/// - scale: The rounding scale. | ||
/// - Returns: A rectangle with the rounded values. | ||
func rounded(_ rule: FloatingPointRoundingRule, by scale: CGFloat) -> CGRect { | ||
return CGRect( | ||
minX: minX.rounded(rule, by: scale), | ||
minY: minY.rounded(rule, by: scale), | ||
maxX: maxX.rounded(rule, by: scale), | ||
maxY: maxY.rounded(rule, by: scale)) | ||
} | ||
|
||
func offset(by point: CGPoint) -> CGRect { | ||
return self.offsetBy(dx: point.x, dy: point.y) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
BlueprintUI/Sources/Layout/FloatingPoint+ScaleRounding.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
|
||
public extension FloatingPoint { | ||
/// Rounds this value to the specified scale, where the scale is the number of rounding stops per integer. | ||
/// - Parameters: | ||
/// - rule: the rounding rule | ||
/// - scale: the rounding scale | ||
/// | ||
/// A rounding scale of 1.0 is standard integer rounding. | ||
/// A rounding scale of 2.0 rounds to halves (0, 0.5, 1.0, 1.5, 2.0, 2.5., ...). | ||
/// A rounding scale of 3.0 rounds to thirds (0, 1/3, 2/3, 1.0, 4/3, 5/3, 2.0, ...). | ||
mutating func round(_ rule: FloatingPointRoundingRule, by scale: Self) { | ||
self = self.rounded(rule, by: scale) | ||
} | ||
|
||
/// Returns this value rounded to the specified scale, where the scale is the number of rounding stops per integer. | ||
/// - Parameters: | ||
/// - rule: the rounding rule | ||
/// - scale: the rounding scale | ||
/// - Returns: The rounded value. | ||
/// | ||
/// A rounding scale of 1.0 is standard integer rounding. | ||
/// A rounding scale of 2.0 rounds to halves (0, 0.5, 1.0, 1.5, 2.0, 2.5., ...). | ||
/// A rounding scale of 3.0 rounds to thirds (0, 1/3, 2/3, 1.0, 4/3, 5/3, 2.0, ...). | ||
func rounded(_ rule: FloatingPointRoundingRule, by scale: Self) -> Self { | ||
return (self * scale).rounded(rule) / scale | ||
} | ||
} |
Oops, something went wrong.