Skip to content

Commit acf39e0

Browse files
committed
Add Hashable conformance
1 parent e33ce7c commit acf39e0

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

Sources/OpenCoreGraphics/CGPath.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@
88
public import Foundation
99

1010
/// A graphics path is a mathematical description of a series of shapes or lines.
11-
public final class CGPath {
12-
11+
public class CGPath: Hashable {
1312
public typealias Element = PathElement
1413

1514
public var elements: [Element]
1615

1716
public init(elements: [Element] = []) {
18-
1917
self.elements = elements
2018
}
19+
20+
public static func == (lhs: CGPath, rhs: CGPath) -> Bool {
21+
lhs.elements == rhs.elements
22+
}
23+
24+
public func hash(into hasher: inout Hasher) {
25+
hasher.combine(elements)
26+
}
2127
}
2228

29+
/// For compatibility with CoreGraphics API.
30+
public class CGMutablePath: CGPath {}
31+
2332
public final class CGPathRef {
2433
public var path: CGPath
2534

@@ -31,7 +40,7 @@ public final class CGPathRef {
3140
// MARK: - Supporting Types
3241

3342
/// A path element.
34-
public enum PathElement {
43+
public enum PathElement: Hashable {
3544

3645
/// The path element that starts a new subpath. The element holds a single point for the destination.
3746
case moveToPoint(CGPoint)

Sources/OpenCoreGraphics/CGPoint+Extension.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ public import Foundation
99
extension CGPoint {
1010
public static let zero = CGPoint(x: .zero, y: .zero)
1111
}
12+
13+
extension CGPoint: Hashable {
14+
public func hash(into hasher: inout Hasher) {
15+
hasher.combine(x)
16+
hasher.combine(y)
17+
}
18+
19+
public static func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
20+
lhs.x == rhs.x && lhs.y == rhs.y
21+
}
22+
}
1223
#endif
1324

1425
extension CGPoint: Swift.CustomDebugStringConvertible {

Sources/OpenCoreGraphics/CGRect+Extension.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ extension CGRect {
3636

3737
public static let zero = CGRect(origin: .zero, size: .zero)
3838
}
39+
40+
extension CGRect: Swift.Hashable {
41+
public func hash(into hasher: inout Hasher) {
42+
hasher.combine(origin)
43+
hasher.combine(size)
44+
}
45+
46+
public static func == (lhs: CGRect, rhs: CGRect) -> Bool {
47+
return lhs.origin == rhs.origin && lhs.size == rhs.size
48+
}
49+
}
3950
#endif
4051

4152
extension CGRect: Swift.CustomDebugStringConvertible {

Sources/OpenCoreGraphics/CGSize+Extension.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ public import Foundation
88
extension CGSize {
99
public static let zero = CGSize(width: .zero, height: .zero)
1010
}
11+
12+
extension CGSize: Swift.Hashable {
13+
public func hash(into hasher: inout Hasher) {
14+
hasher.combine(width)
15+
hasher.combine(height)
16+
}
17+
18+
public static func == (lhs: CGSize, rhs: CGSize) -> Bool {
19+
lhs.width == rhs.width && lhs.height == rhs.height
20+
}
21+
}
1122
#endif
1223

1324
extension CGSize: Swift.CustomDebugStringConvertible {

0 commit comments

Comments
 (0)