|
27 | 27 | import Foundation |
28 | 28 | import CoreGraphics |
29 | 29 |
|
| 30 | +/** |
| 31 | + * Extensions for BinaryFloatingPoint to support type conversion in QR code processing. |
| 32 | + * |
| 33 | + * This extension provides convenient type conversion methods for floating-point numbers |
| 34 | + * that are used throughout the EFQRCode library for coordinate calculations, size conversions, |
| 35 | + * and other numerical operations. |
| 36 | + * |
| 37 | + * ## Features |
| 38 | + * |
| 39 | + * - Boolean conversion for conditional logic |
| 40 | + * - CGFloat conversion for Core Graphics operations |
| 41 | + * - Numeric type conversions for various precision requirements |
| 42 | + * - Integer type conversions for different bit widths |
| 43 | + * - Unsigned integer conversions for positive-only values |
| 44 | + * |
| 45 | + * ## Usage |
| 46 | + * |
| 47 | + * ```swift |
| 48 | + * let value: Double = 3.14 |
| 49 | + * |
| 50 | + * // Convert to different types |
| 51 | + * let cgFloat = value.cgFloat // CGFloat |
| 52 | + * let int = value.int // Int |
| 53 | + * let bool = value.bool // Bool (true if non-zero) |
| 54 | + * let uInt32 = value.uInt32 // UInt32 |
| 55 | + * ``` |
| 56 | + * |
| 57 | + * ## Supported Types |
| 58 | + * |
| 59 | + * The extension provides conversions to: |
| 60 | + * - **Boolean**: `bool` - true if non-zero, false if zero |
| 61 | + * - **Floating Point**: `cgFloat`, `double`, `float` |
| 62 | + * - **Signed Integers**: `int`, `int8`, `int16`, `int32`, `int64` |
| 63 | + * - **Unsigned Integers**: `uInt`, `uInt8`, `uInt16`, `uInt32`, `uInt64` |
| 64 | + */ |
30 | 65 | extension BinaryFloatingPoint { |
31 | 66 |
|
| 67 | + /** |
| 68 | + * Converts the floating-point value to a boolean. |
| 69 | + * |
| 70 | + * Returns true if the value is non-zero, false if the value is zero. |
| 71 | + * |
| 72 | + * - Returns: true if the value is non-zero, false otherwise. |
| 73 | + */ |
32 | 74 | var bool: Bool { |
33 | 75 | return 0 != self |
34 | 76 | } |
35 | 77 |
|
| 78 | + /** |
| 79 | + * Converts the floating-point value to CGFloat. |
| 80 | + * |
| 81 | + * This is commonly used for Core Graphics operations that require CGFloat. |
| 82 | + * |
| 83 | + * - Returns: A CGFloat representation of the value. |
| 84 | + */ |
36 | 85 | var cgFloat: CGFloat { |
37 | 86 | return CGFloat(self) |
38 | 87 | } |
39 | 88 |
|
| 89 | + /** |
| 90 | + * Converts the floating-point value to Double. |
| 91 | + * |
| 92 | + * - Returns: A Double representation of the value. |
| 93 | + */ |
40 | 94 | var double: Double { |
41 | 95 | return Double(self) |
42 | 96 | } |
43 | 97 |
|
| 98 | + /** |
| 99 | + * Converts the floating-point value to Float. |
| 100 | + * |
| 101 | + * - Returns: A Float representation of the value. |
| 102 | + */ |
44 | 103 | var float: Float { |
45 | 104 | return Float(self) |
46 | 105 | } |
47 | 106 |
|
| 107 | + /** |
| 108 | + * Converts the floating-point value to Int. |
| 109 | + * |
| 110 | + * The value is truncated to the nearest integer. |
| 111 | + * |
| 112 | + * - Returns: An Int representation of the value. |
| 113 | + */ |
48 | 114 | var int: Int { |
49 | 115 | return Int(self) |
50 | 116 | } |
51 | 117 |
|
| 118 | + /** |
| 119 | + * Converts the floating-point value to Int8. |
| 120 | + * |
| 121 | + * The value is truncated to the nearest integer and clamped to Int8 range. |
| 122 | + * |
| 123 | + * - Returns: An Int8 representation of the value. |
| 124 | + */ |
52 | 125 | var int8: Int8 { |
53 | 126 | return Int8(self) |
54 | 127 | } |
55 | 128 |
|
| 129 | + /** |
| 130 | + * Converts the floating-point value to Int16. |
| 131 | + * |
| 132 | + * The value is truncated to the nearest integer and clamped to Int16 range. |
| 133 | + * |
| 134 | + * - Returns: An Int16 representation of the value. |
| 135 | + */ |
56 | 136 | var int16: Int16 { |
57 | 137 | return Int16(self) |
58 | 138 | } |
59 | 139 |
|
| 140 | + /** |
| 141 | + * Converts the floating-point value to Int32. |
| 142 | + * |
| 143 | + * The value is truncated to the nearest integer and clamped to Int32 range. |
| 144 | + * |
| 145 | + * - Returns: An Int32 representation of the value. |
| 146 | + */ |
60 | 147 | var int32: Int32 { |
61 | 148 | return Int32(self) |
62 | 149 | } |
63 | 150 |
|
| 151 | + /** |
| 152 | + * Converts the floating-point value to Int64. |
| 153 | + * |
| 154 | + * The value is truncated to the nearest integer and clamped to Int64 range. |
| 155 | + * |
| 156 | + * - Returns: An Int64 representation of the value. |
| 157 | + */ |
64 | 158 | var int64: Int64 { |
65 | 159 | return Int64(self) |
66 | 160 | } |
67 | 161 |
|
| 162 | + /** |
| 163 | + * Converts the floating-point value to UInt. |
| 164 | + * |
| 165 | + * The value is truncated to the nearest integer and clamped to UInt range. |
| 166 | + * |
| 167 | + * - Returns: A UInt representation of the value. |
| 168 | + */ |
68 | 169 | var uInt: UInt { |
69 | 170 | return UInt(self) |
70 | 171 | } |
71 | 172 |
|
| 173 | + /** |
| 174 | + * Converts the floating-point value to UInt8. |
| 175 | + * |
| 176 | + * The value is truncated to the nearest integer and clamped to UInt8 range. |
| 177 | + * |
| 178 | + * - Returns: A UInt8 representation of the value. |
| 179 | + */ |
72 | 180 | var uInt8: UInt8 { |
73 | 181 | return UInt8(self) |
74 | 182 | } |
75 | 183 |
|
| 184 | + /** |
| 185 | + * Converts the floating-point value to UInt16. |
| 186 | + * |
| 187 | + * The value is truncated to the nearest integer and clamped to UInt16 range. |
| 188 | + * |
| 189 | + * - Returns: A UInt16 representation of the value. |
| 190 | + */ |
76 | 191 | var uInt16: UInt16 { |
77 | 192 | return UInt16(self) |
78 | 193 | } |
79 | 194 |
|
| 195 | + /** |
| 196 | + * Converts the floating-point value to UInt32. |
| 197 | + * |
| 198 | + * The value is truncated to the nearest integer and clamped to UInt32 range. |
| 199 | + * |
| 200 | + * - Returns: A UInt32 representation of the value. |
| 201 | + */ |
80 | 202 | var uInt32: UInt32 { |
81 | 203 | return UInt32(self) |
82 | 204 | } |
83 | 205 |
|
| 206 | + /** |
| 207 | + * Converts the floating-point value to UInt64. |
| 208 | + * |
| 209 | + * The value is truncated to the nearest integer and clamped to UInt64 range. |
| 210 | + * |
| 211 | + * - Returns: A UInt64 representation of the value. |
| 212 | + */ |
84 | 213 | var uInt64: UInt64 { |
85 | 214 | return UInt64(self) |
86 | 215 | } |
|
0 commit comments