Skip to content

Commit be016e4

Browse files
committed
refactor: keep geometry utilities local
1 parent b584583 commit be016e4

4 files changed

Lines changed: 63 additions & 25 deletions

File tree

‎Package.resolved‎

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ let package = Package(
2424
url: "https://github.com/apple/swift-argument-parser.git",
2525
from: "1.5.0"
2626
),
27-
.package(
28-
url: "https://github.com/GoodNotes/FoundationEssentialsExtras.git",
29-
revision: "dace29232ec271389cc1e4c4258c8162d1ac3f5f"
30-
),
3127
.package(
3228
url: "https://github.com/compnerd/xylem.git",
3329
revision: "9881c95ce3a139f4ccfa584676201516c2a5751d"
@@ -45,11 +41,6 @@ let package = Package(
4541
.target(
4642
name: "SVGView",
4743
dependencies: [
48-
.product(
49-
name: "FoundationEssentialsExtras",
50-
package: "FoundationEssentialsExtras",
51-
condition: .when(platforms: [.wasi, .linux, .android, .windows])
52-
),
5344
.product(
5445
name: "SAXParser",
5546
package: "xylem",

‎Source/CoreGraphicsPolyfill.swift‎

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Created by khoi on 10/5/25.
66
//
77

8-
#if canImport(FoundationEssentialsExtras)
9-
import FoundationEssentialsExtras
8+
#if canImport(FoundationEssentials)
9+
import FoundationEssentials
1010
#else
1111
import Foundation
1212
#endif
@@ -17,11 +17,66 @@ import WASILibc
1717
import Glibc
1818
#endif
1919

20-
#if canImport(FoundationEssentialsExtras)
21-
public typealias CGFloat = FoundationEssentialsExtras.CGFloat
22-
public typealias CGPoint = FoundationEssentialsExtras.CGPoint
23-
public typealias CGSize = FoundationEssentialsExtras.CGSize
24-
public typealias CGRect = FoundationEssentialsExtras.CGRect
20+
#if !canImport(CoreGraphics)
21+
public typealias CGFloat = Double
22+
23+
public struct CGPoint: Equatable {
24+
public static let zero = CGPoint()
25+
26+
public var x: CGFloat
27+
public var y: CGFloat
28+
29+
public init(x: CGFloat = 0, y: CGFloat = 0) {
30+
self.x = x
31+
self.y = y
32+
}
33+
}
34+
35+
public struct CGSize: Equatable {
36+
public static let zero = CGSize()
37+
38+
public var width: CGFloat
39+
public var height: CGFloat
40+
41+
public init(width: CGFloat = 0, height: CGFloat = 0) {
42+
self.width = width
43+
self.height = height
44+
}
45+
}
46+
47+
public struct CGRect: Equatable {
48+
public static let zero = CGRect()
49+
50+
public var origin: CGPoint
51+
public var size: CGSize
52+
53+
public init(origin: CGPoint = .zero, size: CGSize = CGSize()) {
54+
self.origin = origin
55+
self.size = size
56+
}
57+
58+
public init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) {
59+
self.init(
60+
origin: CGPoint(x: x, y: y),
61+
size: CGSize(width: width, height: height)
62+
)
63+
}
64+
65+
public var width: CGFloat { maxX - minX }
66+
public var height: CGFloat { maxY - minY }
67+
public var minX: CGFloat { Swift.min(origin.x, origin.x + size.width) }
68+
public var minY: CGFloat { Swift.min(origin.y, origin.y + size.height) }
69+
public var maxX: CGFloat { Swift.max(origin.x, origin.x + size.width) }
70+
public var maxY: CGFloat { Swift.max(origin.y, origin.y + size.height) }
71+
72+
public func union(_ other: CGRect) -> CGRect {
73+
let minX = Swift.min(self.minX, other.minX)
74+
let minY = Swift.min(self.minY, other.minY)
75+
let maxX = Swift.max(self.maxX, other.maxX)
76+
let maxY = Swift.max(self.maxY, other.maxY)
77+
return CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY)
78+
}
79+
}
2580
#endif
2681

2782
#if os(WASI) || os(Linux) || os(Android)

‎Source/Serialization/Serializations.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension CGFloat: SerializableAtom {
4949

5050
}
5151

52-
#if !canImport(FoundationEssentialsExtras)
52+
#if canImport(CoreGraphics)
5353
extension Double: SerializableAtom {
5454

5555
func serialize() -> String {

0 commit comments

Comments
 (0)