1
1
// Copyright © 2019 Saleem Abdulrasool <
[email protected] >
2
2
// SPDX-License-Identifier: BSD-3-Clause
3
3
4
+ /// A structure that contains width and height values.
4
5
public struct Size {
5
- public static let zero : Size = Size ( width : 0 , height : 0 )
6
+ // MARK - Geometric Properties
6
7
7
- public var height : Double
8
+ /// A width value.
8
9
public var width : Double
9
10
10
- public init ( width: Float , height: Float ) {
11
- self . init ( width: Double ( width) , height: Double ( height) )
11
+ /// A height value.
12
+ public var height : Double
13
+
14
+ // MARK - Special Values
15
+
16
+ /// The size whose width and height are both zero.
17
+ public static var zero : Size {
18
+ Size ( width: 0 , height: 0 )
12
19
}
13
20
21
+ /// Creates a size with zero width and height.
22
+ public init ( ) {
23
+ self = . zero
24
+ }
25
+
26
+ // MARK - Transforming Sizes
27
+
28
+ /// Returns the height and width resulting from a transformation of an
29
+ /// existing height and width.
30
+ func applying( _ transform: AffineTransform ) -> Size {
31
+ return Size ( width: transform. a * self . width + transform. c * self . height,
32
+ height: transform. b * self . width + transform. d * self . height)
33
+ }
34
+
35
+ // MARK - Initializers
36
+
37
+ /// Creates a size with dimensions specified as floating-point values.
14
38
public init ( width: Double , height: Double ) {
15
39
self . height = height
16
40
self . width = width
@@ -19,11 +43,6 @@ public struct Size {
19
43
public init ( width: Int , height: Int ) {
20
44
self . init ( width: Double ( width) , height: Double ( height) )
21
45
}
22
-
23
- func applying( _ transform: AffineTransform ) -> Size {
24
- return Size ( width: transform. a * self . width + transform. c * self . height,
25
- height: transform. b * self . width + transform. d * self . height)
26
- }
27
46
}
28
47
29
48
extension Size : Equatable {
0 commit comments