diff --git a/Sources/Units/Units.swift b/Sources/Units/Units.swift index ecaddaf..c0fd3fc 100644 --- a/Sources/Units/Units.swift +++ b/Sources/Units/Units.swift @@ -1,6 +1,37 @@ -import CoreGraphics // For CGFloat, often used in UI import Foundation +#if canImport(CoreGraphics) + import CoreGraphics // For CGFloat, often used in UI +#else + public typealias CGFloat = Double + public struct CGPoint: Sendable { + public var x: CGFloat + public var y: CGFloat + public init(x: CGFloat, y: CGFloat) { + self.x = x + self.y = y + } + } + + public struct CGSize: Sendable { + public var width: CGFloat + public var height: CGFloat + public init(width: CGFloat, height: CGFloat) { + self.width = width + self.height = height + } + } + + public struct CGRect: Sendable { + public var origin: CGPoint + public var size: CGSize + public init(origin: CGPoint, size: CGSize) { + self.origin = origin + self.size = size + } + } +#endif + public protocol ConvertibleToDouble: Numeric { var doubleValue: Double { get } } @@ -19,9 +50,11 @@ extension Float: ConvertibleToDouble { extension Double: ConvertibleToDouble { public var doubleValue: Double { self } } -extension CGFloat: ConvertibleToDouble { - public var doubleValue: Double { Double(self) } -} +#if canImport(CoreGraphics) + extension CGFloat: ConvertibleToDouble { + public var doubleValue: Double { Double(self) } + } +#endif // MARK: - 1. UnitCategory Enum public enum UnitCategory: String, CaseIterable, CustomStringConvertible,