-
Notifications
You must be signed in to change notification settings - Fork 2
[CPF] Port SVGView to FoundationEssentials #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7b0791
cd452b2
ce82370
10555db
12e4af1
2fac276
be7dcbd
8405e34
c58cc42
381c57f
b9ee87a
6d1302e
e3b0f49
f4d55ae
ae3cce9
b584583
be016e4
c2eb72e
fb0da21
233fb0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,86 @@ | |
| // Created by khoi on 10/5/25. | ||
| // | ||
|
|
||
| #if os(Linux) | ||
| import Foundation | ||
| #elseif canImport(FoundationEssentials) | ||
| import FoundationEssentials | ||
| #else | ||
| import Foundation | ||
| #endif | ||
|
|
||
| #if os(WASI) | ||
| import WASILibc | ||
| #elseif os(Linux) || os(Android) | ||
| import Glibc | ||
| #endif | ||
|
|
||
| #if os(Linux) | ||
| public typealias CGFloat = Foundation.CGFloat | ||
| public typealias CGPoint = Foundation.CGPoint | ||
| public typealias CGSize = Foundation.CGSize | ||
| public typealias CGRect = Foundation.CGRect | ||
| #elseif !canImport(CoreGraphics) | ||
| public typealias CGFloat = Double | ||
|
|
||
| public struct CGPoint: Equatable { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially I wanted to separate these in another repo since it's reusable. But, this repo is public and I can't make this thing public without legal approval so this is the best I can do |
||
| public static let zero = CGPoint() | ||
|
|
||
| public var x: CGFloat | ||
| public var y: CGFloat | ||
|
|
||
| public init(x: CGFloat = 0, y: CGFloat = 0) { | ||
| self.x = x | ||
| self.y = y | ||
| } | ||
| } | ||
|
|
||
| public struct CGSize: Equatable { | ||
| public static let zero = CGSize() | ||
|
|
||
| public var width: CGFloat | ||
| public var height: CGFloat | ||
|
|
||
| public init(width: CGFloat = 0, height: CGFloat = 0) { | ||
| self.width = width | ||
| self.height = height | ||
| } | ||
| } | ||
|
|
||
| public struct CGRect: Equatable { | ||
| public static let zero = CGRect() | ||
|
|
||
| public var origin: CGPoint | ||
| public var size: CGSize | ||
|
|
||
| public init(origin: CGPoint = .zero, size: CGSize = CGSize()) { | ||
| self.origin = origin | ||
| self.size = size | ||
| } | ||
|
|
||
| public init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) { | ||
| self.init( | ||
| origin: CGPoint(x: x, y: y), | ||
| size: CGSize(width: width, height: height) | ||
| ) | ||
| } | ||
|
|
||
| public var width: CGFloat { maxX - minX } | ||
| public var height: CGFloat { maxY - minY } | ||
| public var minX: CGFloat { Swift.min(origin.x, origin.x + size.width) } | ||
| public var minY: CGFloat { Swift.min(origin.y, origin.y + size.height) } | ||
| public var maxX: CGFloat { Swift.max(origin.x, origin.x + size.width) } | ||
| public var maxY: CGFloat { Swift.max(origin.y, origin.y + size.height) } | ||
|
|
||
| public func union(_ other: CGRect) -> CGRect { | ||
| let minX = Swift.min(self.minX, other.minX) | ||
| let minY = Swift.min(self.minY, other.minY) | ||
| let maxX = Swift.max(self.maxX, other.maxX) | ||
| let maxY = Swift.max(self.maxY, other.maxY) | ||
| return CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY) | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| #if os(WASI) || os(Linux) || os(Android) | ||
| private let KAPPA: CGFloat = 0.5522847498 // 4 *(sqrt(2) -1)/3 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointing to a specific rev might be an issue with some internal tooling we have about the SPM registry, but since we are not actively using it ATM we can revisit this problem later, hopefully xylem cuts a version soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I already faced this now