Skip to content

Commit 624f757

Browse files
committed
CoreGraphics: add some additional Rect methods
This adds a default constructor and the special value of `infinite` to `Rect`.
1 parent a940112 commit 624f757

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/SwiftWin32/CG/Rect.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public struct Rect {
3030

3131
// MARK - Special Values
3232

33+
/// A rectangle that has infinite extent.
34+
public static var infinite: Rect {
35+
Rect(x: -.leastNormalMagnitude, y: -.leastNormalMagnitude,
36+
width: .greatestFiniteMagnitude, height:.greatestFiniteMagnitude)
37+
}
38+
3339
/// The null rectangle, representing an invalid value.
3440
public static var null: Rect {
3541
Rect(x: .greatestFiniteMagnitude, y: .greatestFiniteMagnitude,
@@ -41,6 +47,11 @@ public struct Rect {
4147
Rect(x: 0, y: 0, width: 0, height: 0)
4248
}
4349

50+
/// Creates a rectangle with origin (0,0) and size (0,0).
51+
public init() {
52+
self = .zero
53+
}
54+
4455
// MARK - Basic Geometric Properties
4556

4657
/// A point that specifies the coordinates of the rectangle’s origin.
@@ -171,6 +182,11 @@ public struct Rect {
171182
return self.size.height == 0 || self.size.width == 0 || self.isNull
172183
}
173184

185+
/// Returns whether a rectangle is infinite.
186+
public var isInfinite: Bool {
187+
return self == .infinite
188+
}
189+
174190
/// Returns whether the rectangle is equal to the null rectangle.
175191
public var isNull: Bool {
176192
return self == .null

0 commit comments

Comments
 (0)