|
6 | 6 | // |
7 | 7 |
|
8 | 8 | import Foundation |
| 9 | + |
9 | 10 | @testable import OBCoder |
10 | 11 |
|
11 | 12 | public struct Quadrilateral: Encodable, Equatable { |
12 | 13 |
|
| 14 | + public enum Corner: Int { |
| 15 | + case topLeft = 0 |
| 16 | + case topRight |
| 17 | + case bottomLeft |
| 18 | + case bottomRight |
| 19 | + } |
13 | 20 |
|
14 | | - public enum Corner : Int { |
15 | | - case topLeft = 0 |
16 | | - case topRight |
17 | | - case bottomLeft |
18 | | - case bottomRight |
19 | | - } |
20 | | - |
21 | | - public enum Edge : Int { |
22 | | - case top = 0 |
23 | | - case bottom |
24 | | - case left |
25 | | - case right |
26 | | - } |
27 | | - |
28 | | - public static let zero = Quadrilateral(topLeft: .zero, topRight: .zero, bottomLeft: .zero, bottomRight: .zero) |
29 | | - |
30 | | - |
31 | | - public var topLeft: CGPoint |
32 | | - public var topRight: CGPoint |
33 | | - public var bottomLeft: CGPoint |
34 | | - public var bottomRight: CGPoint |
| 21 | + public enum Edge: Int { |
| 22 | + case top = 0 |
| 23 | + case bottom |
| 24 | + case left |
| 25 | + case right |
| 26 | + } |
35 | 27 |
|
| 28 | + public static let zero = Quadrilateral( |
| 29 | + topLeft: .zero, topRight: .zero, bottomLeft: .zero, bottomRight: .zero) |
36 | 30 |
|
| 31 | + public var topLeft: CGPoint |
| 32 | + public var topRight: CGPoint |
| 33 | + public var bottomLeft: CGPoint |
| 34 | + public var bottomRight: CGPoint |
37 | 35 |
|
38 | | - public init(topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint) { |
39 | | - self.topLeft = topLeft |
40 | | - self.topRight = topRight |
41 | | - self.bottomLeft = bottomLeft |
42 | | - self.bottomRight = bottomRight |
43 | | - } |
| 36 | + public init(topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint) { |
| 37 | + self.topLeft = topLeft |
| 38 | + self.topRight = topRight |
| 39 | + self.bottomLeft = bottomLeft |
| 40 | + self.bottomRight = bottomRight |
| 41 | + } |
44 | 42 |
|
45 | | - public init?(decoder: OBCoder.Decoder) { |
46 | | - guard let topLeft = decoder.point(forKey: "topLeft") else { |
47 | | - return nil |
48 | | - } |
49 | | - guard let topRight = decoder.point(forKey: "topRight") else { |
50 | | - return nil |
51 | | - } |
52 | | - guard let bottomLeft = decoder.point(forKey: "bottomLeft") else { |
53 | | - return nil |
54 | | - } |
55 | | - guard let bottomRight = decoder.point(forKey: "bottomRight") else { |
56 | | - return nil |
57 | | - } |
58 | | - self.topLeft = topLeft |
59 | | - self.topRight = topRight |
60 | | - self.bottomLeft = bottomLeft |
61 | | - self.bottomRight = bottomRight |
62 | | - } |
| 43 | + public init?(decoder: OBCoder.Decoder) { |
| 44 | + guard let topLeft = decoder.point(forKey: "topLeft") else { |
| 45 | + return nil |
| 46 | + } |
| 47 | + guard let topRight = decoder.point(forKey: "topRight") else { |
| 48 | + return nil |
| 49 | + } |
| 50 | + guard let bottomLeft = decoder.point(forKey: "bottomLeft") else { |
| 51 | + return nil |
| 52 | + } |
| 53 | + guard let bottomRight = decoder.point(forKey: "bottomRight") else { |
| 54 | + return nil |
| 55 | + } |
| 56 | + self.topLeft = topLeft |
| 57 | + self.topRight = topRight |
| 58 | + self.bottomLeft = bottomLeft |
| 59 | + self.bottomRight = bottomRight |
| 60 | + } |
63 | 61 |
|
64 | | - public func encode(with coder: Coder) { |
65 | | - coder.encode(topLeft, forKey: "topLeft") |
66 | | - coder.encode(topRight, forKey: "topRight") |
67 | | - coder.encode(bottomLeft, forKey: "bottomLeft") |
68 | | - coder.encode(bottomRight, forKey: "bottomRight") |
69 | | - } |
| 62 | + public func encode(with coder: Coder) { |
| 63 | + coder.encode(topLeft, forKey: "topLeft") |
| 64 | + coder.encode(topRight, forKey: "topRight") |
| 65 | + coder.encode(bottomLeft, forKey: "bottomLeft") |
| 66 | + coder.encode(bottomRight, forKey: "bottomRight") |
| 67 | + } |
70 | 68 |
|
71 | 69 | } |
0 commit comments