From 71669134fa2607c5402ed3d7dba33ba6b53ab89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bardon?= Date: Sun, 27 Nov 2022 23:04:47 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20Create=20binary=20size?= =?UTF-8?q?=20benchmarks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwiftGeoBinarySizeBenchmark/.gitignore | 9 ++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../Package.resolved | 31 +++++++++++++++++++ .../SwiftGeoBinarySizeBenchmark/Package.swift | 24 ++++++++++++++ .../SwiftGeoBinarySizeBenchmark/README.md | 1 + .../SwiftGeoBinarySizeBenchmark1/main.swift | 8 +++++ .../SwiftGeoBinarySizeBenchmark1/.gitignore | 9 ++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../Package.swift | 28 +++++++++++++++++ .../SwiftGeoBinarySizeBenchmark1/README.md | 3 ++ .../SwiftGeoBinarySizeBenchmark1.swift | 6 ++++ .../SwiftGeoBinarySizeBenchmark1Tests.swift | 11 +++++++ 12 files changed, 146 insertions(+) create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/README.md create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift create mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore b/Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved b/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved new file mode 100644 index 0000000..c93e60a --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved @@ -0,0 +1,31 @@ +{ + "pins" : [ + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms", + "state" : { + "revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-nonempty", + "kind" : "remoteSourceControl", + "location" : "https://github.com/RemiBardon/swift-nonempty", + "state" : { + "revision" : "f951b7bcd4f13586307f53b0de5d1b20976aceab" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + } + ], + "version" : 2 +} diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift new file mode 100644 index 0000000..9b59a84 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift @@ -0,0 +1,24 @@ +// swift-tools-version: 5.7 + +import PackageDescription + +let package = Package( + name: "SwiftGeoBinarySizeBenchmark", + platforms: [ + .macOS(.v10_15), + ], + products: [ + .executable( + name: "SwiftGeoBinarySizeBenchmark1", + targets: ["SwiftGeoBinarySizeBenchmark1"] + ), + ], + dependencies: [ + .package(name: "swift-geo", path: "../.."), + ], + targets: [ + .executableTarget(name: "SwiftGeoBinarySizeBenchmark1", dependencies: [ + .product(name: "WGS84", package: "swift-geo"), + ]), + ] +) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md b/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md new file mode 100644 index 0000000..11dacd2 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md @@ -0,0 +1 @@ +# SwiftGeo binary size benchmark diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift new file mode 100644 index 0000000..f625381 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift @@ -0,0 +1,8 @@ +import WGS84 + +let point = Point2D(latitude: 10.2, longitude: 20.3) +print(point) +let coordinates = point.coordinates.transformed(toCRS: WGS84Geographic3DCRS.self) +print(coordinates) +print(coordinates.dmsNotation) +print(point.bbox) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift new file mode 100644 index 0000000..3c057ac --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version: 5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SwiftGeoBinarySizeBenchmark1", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "SwiftGeoBinarySizeBenchmark1", + targets: ["SwiftGeoBinarySizeBenchmark1"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "SwiftGeoBinarySizeBenchmark1", + dependencies: []), + .testTarget( + name: "SwiftGeoBinarySizeBenchmark1Tests", + dependencies: ["SwiftGeoBinarySizeBenchmark1"]), + ] +) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md b/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md new file mode 100644 index 0000000..e1b8960 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md @@ -0,0 +1,3 @@ +# SwiftGeoBinarySizeBenchmark1 + +A description of this package. diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift new file mode 100644 index 0000000..b1ea254 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift @@ -0,0 +1,6 @@ +public struct SwiftGeoBinarySizeBenchmark1 { + public private(set) var text = "Hello, World!" + + public init() { + } +} diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift new file mode 100644 index 0000000..7a99225 --- /dev/null +++ b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import SwiftGeoBinarySizeBenchmark1 + +final class SwiftGeoBinarySizeBenchmark1Tests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(SwiftGeoBinarySizeBenchmark1().text, "Hello, World!") + } +} From e39e760d8a7ef684b6104c17c9eaa3ddd8ae2dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bardon?= Date: Thu, 2 Feb 2023 10:03:56 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20Add=20banchmarks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.gitignore | 2 - ...3B817AB4-82BB-4C8E-BADA-A8577468EACF.plist | 22 +++++ .../Info.plist | 33 +++++++ .../xcschemes/BinarySizeBenchmarks.xcscheme | 52 ++++++++++ .../xcschemes/binary-size-1.xcscheme | 79 +++++++++++++++ .../Package.resolved | 0 Benchmarks/Package.swift | 27 ++++++ Benchmarks/README.md | 1 + .../Sources/BinarySizeBenchmark1/main.swift | 14 +++ .../Sources/BinarySizeReference1/main.swift | 4 + .../SwiftGeoBinarySizeBenchmark/Package.swift | 24 ----- .../SwiftGeoBinarySizeBenchmark/README.md | 1 - .../SwiftGeoBinarySizeBenchmark1/main.swift | 8 -- .../SwiftGeoBinarySizeBenchmark1/.gitignore | 9 -- .../xcshareddata/IDEWorkspaceChecks.plist | 8 -- .../Package.swift | 28 ------ .../SwiftGeoBinarySizeBenchmark1/README.md | 3 - .../SwiftGeoBinarySizeBenchmark1.swift | 6 -- .../SwiftGeoBinarySizeBenchmark1Tests.swift | 11 --- .../BinarySizeBenchmark1.swift | 97 +++++++++++++++++++ .../PerformanceBenchmark1.swift | 25 +++++ Sources/Geodesy/CoordinateComponent.swift | 13 +-- Sources/Geodesy/Geodesy.swift | 24 ++--- Sources/GeodeticConversions/Conversions.swift | 16 +-- .../GeodeticDisplay/Coordinate+Display.swift | 45 +++------ .../{Toolbox => }/Exports.swift | 0 .../GeodeticDisplay/GeographicNotation.swift | 16 +-- .../Toolbox/FloatingPoint+Fraction.swift | 15 --- .../Toolbox/Locale+Common.swift | 13 --- .../DecimalNumberFormatter.swift | 31 ++++++ .../FloatingPoint+Fraction.swift | 12 +++ Sources/WGS84Core/WGS84+Display.swift | 12 +-- SwiftGeo.xcworkspace/contents.xcworkspacedata | 10 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/swiftpm/Package.resolved | 4 +- .../GeodeticDisplayTests.swift | 12 +-- .../CubicBezierSplineTests.swift | 8 +- 37 files changed, 471 insertions(+), 214 deletions(-) rename Benchmarks/{SwiftGeoBinarySizeBenchmark => }/.gitignore (76%) create mode 100644 Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/3B817AB4-82BB-4C8E-BADA-A8577468EACF.plist create mode 100644 Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/Info.plist create mode 100644 Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/BinarySizeBenchmarks.xcscheme create mode 100644 Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/binary-size-1.xcscheme rename Benchmarks/{SwiftGeoBinarySizeBenchmark => }/Package.resolved (100%) create mode 100644 Benchmarks/Package.swift create mode 100644 Benchmarks/README.md create mode 100644 Benchmarks/Sources/BinarySizeBenchmark1/main.swift create mode 100644 Benchmarks/Sources/BinarySizeReference1/main.swift delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/README.md delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift delete mode 100644 Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift create mode 100644 Benchmarks/Tests/BinarySizeBenchmarks/BinarySizeBenchmark1.swift create mode 100644 Benchmarks/Tests/PerformanceBenchmarks/PerformanceBenchmark1.swift rename Sources/GeodeticDisplay/{Toolbox => }/Exports.swift (100%) delete mode 100644 Sources/GeodeticDisplay/Toolbox/FloatingPoint+Fraction.swift delete mode 100644 Sources/GeodeticDisplay/Toolbox/Locale+Common.swift create mode 100644 Sources/SwiftGeoToolbox/DecimalNumberFormatter.swift create mode 100644 Sources/SwiftGeoToolbox/FloatingPoint+Fraction.swift create mode 100644 SwiftGeo.xcworkspace/contents.xcworkspacedata rename {Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace => SwiftGeo.xcworkspace}/xcshareddata/IDEWorkspaceChecks.plist (100%) rename Package.resolved => SwiftGeo.xcworkspace/xcshareddata/swiftpm/Package.resolved (91%) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore b/Benchmarks/.gitignore similarity index 76% rename from Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore rename to Benchmarks/.gitignore index 3b29812..bb460e7 100644 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark/.gitignore +++ b/Benchmarks/.gitignore @@ -4,6 +4,4 @@ /*.xcodeproj xcuserdata/ DerivedData/ -.swiftpm/config/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/3B817AB4-82BB-4C8E-BADA-A8577468EACF.plist b/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/3B817AB4-82BB-4C8E-BADA-A8577468EACF.plist new file mode 100644 index 0000000..8b731ff --- /dev/null +++ b/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/3B817AB4-82BB-4C8E-BADA-A8577468EACF.plist @@ -0,0 +1,22 @@ + + + + + classNames + + BinarySizeBenchmark1 + + testPerformance() + + com.apple.dt.XCTMetric_Memory.physical + + baselineAverage + 2.457600 + baselineIntegrationDisplayName + Local Baseline + + + + + + diff --git a/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/Info.plist b/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/Info.plist new file mode 100644 index 0000000..5e05f57 --- /dev/null +++ b/Benchmarks/.swiftpm/xcode/xcshareddata/xcbaselines/PerformanceBenchmarks.xcbaseline/Info.plist @@ -0,0 +1,33 @@ + + + + + runDestinationsByUUID + + 3B817AB4-82BB-4C8E-BADA-A8577468EACF + + localComputer + + busSpeedInMHz + 400 + cpuCount + 1 + cpuKind + 6-Core Intel Core i7 + cpuSpeedInMHz + 2600 + logicalCPUCoresPerPackage + 12 + modelCode + MacBookPro16,1 + physicalCPUCoresPerPackage + 6 + platformIdentifier + com.apple.platform.macosx + + targetArchitecture + x86_64 + + + + diff --git a/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/BinarySizeBenchmarks.xcscheme b/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/BinarySizeBenchmarks.xcscheme new file mode 100644 index 0000000..8a54522 --- /dev/null +++ b/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/BinarySizeBenchmarks.xcscheme @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/binary-size-1.xcscheme b/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/binary-size-1.xcscheme new file mode 100644 index 0000000..03d2140 --- /dev/null +++ b/Benchmarks/.swiftpm/xcode/xcshareddata/xcschemes/binary-size-1.xcscheme @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved b/Benchmarks/Package.resolved similarity index 100% rename from Benchmarks/SwiftGeoBinarySizeBenchmark/Package.resolved rename to Benchmarks/Package.resolved diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift new file mode 100644 index 0000000..7e396ae --- /dev/null +++ b/Benchmarks/Package.swift @@ -0,0 +1,27 @@ +// swift-tools-version: 5.7 + +import PackageDescription + +let package = Package( + name: "swift-geo-benchmarks", + platforms: [ + .macOS(.v13), + ], + products: [ + .executable(name: "binary-size-ref-1", targets: ["BinarySizeReference1"]), + .executable(name: "binary-size-1", targets: ["BinarySizeBenchmark1"]), + ], + dependencies: [ + .package(name: "swift-geo", path: ".."), + ], + targets: [ + .executableTarget(name: "BinarySizeReference1"), + .executableTarget(name: "BinarySizeBenchmark1", dependencies: [ + .product(name: "WGS84", package: "swift-geo"), + ]), + .testTarget(name: "BinarySizeBenchmarks"), + .testTarget(name: "PerformanceBenchmarks", dependencies: [ + .product(name: "Turf", package: "swift-geo"), + ]), + ] +) diff --git a/Benchmarks/README.md b/Benchmarks/README.md new file mode 100644 index 0000000..de016d1 --- /dev/null +++ b/Benchmarks/README.md @@ -0,0 +1 @@ +# SwiftGeo benchmarks diff --git a/Benchmarks/Sources/BinarySizeBenchmark1/main.swift b/Benchmarks/Sources/BinarySizeBenchmark1/main.swift new file mode 100644 index 0000000..013c31d --- /dev/null +++ b/Benchmarks/Sources/BinarySizeBenchmark1/main.swift @@ -0,0 +1,14 @@ +//import WGS84 +//import GeodeticConversions +//import TurfCore +// +//let point = Point2D(coordinates: .init(latitude: 10.2, longitude: 20.3)) +//print(point) +//let coordinates = point.coordinates.to(WGS84Geographic3DCRS.self) +//print(coordinates) +//print(coordinates.dmsNotation) +//print(point.bbox) +import Foundation + +print("Hello, World!") +print(cos(Double(1))) diff --git a/Benchmarks/Sources/BinarySizeReference1/main.swift b/Benchmarks/Sources/BinarySizeReference1/main.swift new file mode 100644 index 0000000..7eec5e4 --- /dev/null +++ b/Benchmarks/Sources/BinarySizeReference1/main.swift @@ -0,0 +1,4 @@ +import Foundation + +print("Hello, World!") +print(cos(Double(1))) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift deleted file mode 100644 index 9b59a84..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark/Package.swift +++ /dev/null @@ -1,24 +0,0 @@ -// swift-tools-version: 5.7 - -import PackageDescription - -let package = Package( - name: "SwiftGeoBinarySizeBenchmark", - platforms: [ - .macOS(.v10_15), - ], - products: [ - .executable( - name: "SwiftGeoBinarySizeBenchmark1", - targets: ["SwiftGeoBinarySizeBenchmark1"] - ), - ], - dependencies: [ - .package(name: "swift-geo", path: "../.."), - ], - targets: [ - .executableTarget(name: "SwiftGeoBinarySizeBenchmark1", dependencies: [ - .product(name: "WGS84", package: "swift-geo"), - ]), - ] -) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md b/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md deleted file mode 100644 index 11dacd2..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark/README.md +++ /dev/null @@ -1 +0,0 @@ -# SwiftGeo binary size benchmark diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift deleted file mode 100644 index f625381..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark/Sources/SwiftGeoBinarySizeBenchmark1/main.swift +++ /dev/null @@ -1,8 +0,0 @@ -import WGS84 - -let point = Point2D(latitude: 10.2, longitude: 20.3) -print(point) -let coordinates = point.coordinates.transformed(toCRS: WGS84Geographic3DCRS.self) -print(coordinates) -print(coordinates.dmsNotation) -print(point.bbox) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore deleted file mode 100644 index 3b29812..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.DS_Store -/.build -/Packages -/*.xcodeproj -xcuserdata/ -DerivedData/ -.swiftpm/config/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift deleted file mode 100644 index 3c057ac..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Package.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version: 5.7 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "SwiftGeoBinarySizeBenchmark1", - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "SwiftGeoBinarySizeBenchmark1", - targets: ["SwiftGeoBinarySizeBenchmark1"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. - .target( - name: "SwiftGeoBinarySizeBenchmark1", - dependencies: []), - .testTarget( - name: "SwiftGeoBinarySizeBenchmark1Tests", - dependencies: ["SwiftGeoBinarySizeBenchmark1"]), - ] -) diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md b/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md deleted file mode 100644 index e1b8960..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# SwiftGeoBinarySizeBenchmark1 - -A description of this package. diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift deleted file mode 100644 index b1ea254..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Sources/SwiftGeoBinarySizeBenchmark1/SwiftGeoBinarySizeBenchmark1.swift +++ /dev/null @@ -1,6 +0,0 @@ -public struct SwiftGeoBinarySizeBenchmark1 { - public private(set) var text = "Hello, World!" - - public init() { - } -} diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift b/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift deleted file mode 100644 index 7a99225..0000000 --- a/Benchmarks/SwiftGeoBinarySizeBenchmark1/Tests/SwiftGeoBinarySizeBenchmark1Tests/SwiftGeoBinarySizeBenchmark1Tests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest -@testable import SwiftGeoBinarySizeBenchmark1 - -final class SwiftGeoBinarySizeBenchmark1Tests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(SwiftGeoBinarySizeBenchmark1().text, "Hello, World!") - } -} diff --git a/Benchmarks/Tests/BinarySizeBenchmarks/BinarySizeBenchmark1.swift b/Benchmarks/Tests/BinarySizeBenchmarks/BinarySizeBenchmark1.swift new file mode 100644 index 0000000..daa2e87 --- /dev/null +++ b/Benchmarks/Tests/BinarySizeBenchmarks/BinarySizeBenchmark1.swift @@ -0,0 +1,97 @@ +// +// BinarySizeBenchmark1.swift +// SwiftGeo +// +// Created by Rémi Bardon on 10/01/2023. +// + +import XCTest + +/// 1 kB +let kB: UInt64 = 1_000 +/// 1 MB +let MB: UInt64 = 1_000_000 + +final class BinarySizeBenchmark1: XCTestCase { + + static var refSize: UInt64 = 0 + + override class func setUp() { + let binaryName = "binary-size-ref-1" + do { + Self.swiftBuild(binaryName) + let binary = try FileAttributes(for: Self.binary(binaryName)) + refSize = binary.fileSize + print("\(binaryName) binary has size \(binary.fileSizeString)") + } catch { + print("\(binaryName) binary could not be built: \(String(describing: error))") + } + } + + func testBinarySize() throws { + let binaryName = "binary-size-1" + Self.swiftBuild(binaryName) + let binary = try FileAttributes(for: Self.binary(binaryName)) + XCTAssertLessThan(binary.fileSize, 3500 * kB, binary.fileSizeString) + print("\(binaryName) binary has size \(binary.fileSizeString)") + } + + // MARK: Helpers + + private static let configuration: String = "release" + + private static let fileURL: URL = URL(string: #file)! + private static let packageFolder: URL = fileURL + .deletingLastPathComponent() + .deletingLastPathComponent() + .deletingLastPathComponent() + private static func binary(_ name: String) -> URL { + return Self.packageFolder.appending( + components: ".build", Self.configuration, name, + directoryHint: .notDirectory + ) + } + + /// - Copyright: + @discardableResult + private static func swift(_ args: [String]) -> Int32 { + let task = Process() + task.executableURL = URL(fileURLWithPath: "/usr/bin/swift") + task.arguments = args + print("Running `swift \(args.joined(separator: " "))`…") + try? task.run() + task.waitUntilExit() + return task.terminationStatus + } + + /// - Copyright: + @discardableResult + private static func swift(_ args: String...) -> Int32 { + return swift(args) + } + + @discardableResult + private static func swiftBuild(_ binaryName: String) -> Int32 { + let args = [ + "build", + "--package-path", Self.packageFolder.absoluteString, + "--product", binaryName, + "-c", Self.configuration, + "-Xswiftc", "-cross-module-optimization", + "-Xswiftc", "-Osize", + ] + return swift(args) + } + +} + +/// - Copyright: Inspired by . +fileprivate struct FileAttributes { + let fileSize: UInt64 + let fileSizeString: String + init(for url: URL) throws { + let attributes = try FileManager.default.attributesOfItem(atPath: url.path) + self.fileSize = attributes[.size] as? UInt64 ?? UInt64(0) + self.fileSizeString = ByteCountFormatter.string(fromByteCount: Int64(self.fileSize), countStyle: .file) + } +} diff --git a/Benchmarks/Tests/PerformanceBenchmarks/PerformanceBenchmark1.swift b/Benchmarks/Tests/PerformanceBenchmarks/PerformanceBenchmark1.swift new file mode 100644 index 0000000..5dd52d9 --- /dev/null +++ b/Benchmarks/Tests/PerformanceBenchmarks/PerformanceBenchmark1.swift @@ -0,0 +1,25 @@ +// +// BinarySizeBenchmark1.swift +// SwiftGeo +// +// Created by Rémi Bardon on 31/01/2023. +// + +import GeodeticGeometry +import NonEmpty +import TurfCore +import WGS84 +import XCTest + +final class BinarySizeBenchmark1: XCTestCase { + + func testPerformance() throws { + let generator = { Coordinate2D(x: .random(), y: .random()) } + let coordinates = Array(repeating: generator, count: 1_000).map { $0() } + let points = MultiPoint(coordinates: try! .init(coordinates)) + measure(metrics: [XCTMemoryMetric(), XCTClockMetric()]) { + print(String(describing: points.center)) + } + } + +} diff --git a/Sources/Geodesy/CoordinateComponent.swift b/Sources/Geodesy/CoordinateComponent.swift index 65af2f4..0008e9b 100644 --- a/Sources/Geodesy/CoordinateComponent.swift +++ b/Sources/Geodesy/CoordinateComponent.swift @@ -6,7 +6,6 @@ // Copyright © 2022 Rémi Bardon. All rights reserved. // -import Foundation import ValueWithUnit import SwiftGeoToolbox @@ -18,18 +17,10 @@ public typealias CoordinateComponent = ValueWithUnit.Value public extension CoordinateComponent { var description: String { - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.maximumFractionDigits = 9 - formatter.locale = .en - return formatter.string(for: Double(self.rawValue)) ?? String(describing: self.rawValue) + DecimalNumberFormatter().string(for: self.rawValue, maxDigits: 6) } var debugDescription: String { - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.locale = .en - formatter.maximumFractionDigits = 99 - return formatter.string(for: Double(self.rawValue)) ?? String(reflecting: self.rawValue) + DecimalNumberFormatter().string(for: self.rawValue, maxDigits: 8) } } diff --git a/Sources/Geodesy/Geodesy.swift b/Sources/Geodesy/Geodesy.swift index 5887a8d..8aeb762 100644 --- a/Sources/Geodesy/Geodesy.swift +++ b/Sources/Geodesy/Geodesy.swift @@ -65,26 +65,26 @@ public protocol DynamicGeodeticDatum: DatumEnsembleMember {} // MARK: Reference Ellipsoid public protocol ReferenceEllipsoid: EPSGItem { - static var semiMajorAxis: Double { get } - static var semiMinorAxis: Double { get } - static var inverseFlattening: Double { get } - static var flattening: Double { get } + @inlinable static var semiMajorAxis: Double { get } + @inlinable static var semiMinorAxis: Double { get } + @inlinable static var inverseFlattening: Double { get } + @inlinable static var flattening: Double { get } /// Eccentricity of the ellipsoid. - static var eccentricity: Double { get } + @inlinable static var eccentricity: Double { get } /// Eccentricity of the ellipsoid, squared. /// `e^2 = (a^2 -b^2)/a^2 = 2f -f^2` - static var e2: Double { get } + @inlinable static var e2: Double { get } /// `ε = e^2 / (1 - e^2)` - static var ε: Double { get } + @inlinable static var ε: Double { get } } public extension ReferenceEllipsoid { - static var flattening: Double { 1 / inverseFlattening } + @inlinable static var flattening: Double { 1 / inverseFlattening } /// Source: - static var semiMinorAxis: Double { semiMajorAxis * (1 - flattening) } - static var eccentricity: Double { sqrt(e2) } - static var e2: Double { (2 * flattening) - pow(flattening, 2) } - static var ε: Double { e2 / (1 - e2) } + @inlinable static var semiMinorAxis: Double { semiMajorAxis * (1 - flattening) } + @inlinable static var eccentricity: Double { sqrt(e2) } + @inlinable static var e2: Double { (2 * flattening) - pow(flattening, 2) } + @inlinable static var ε: Double { e2 / (1 - e2) } } // MARK: Meridian diff --git a/Sources/GeodeticConversions/Conversions.swift b/Sources/GeodeticConversions/Conversions.swift index e920d8d..f1736b8 100644 --- a/Sources/GeodeticConversions/Conversions.swift +++ b/Sources/GeodeticConversions/Conversions.swift @@ -11,7 +11,7 @@ import WGS84Core public extension ThreeDimensionalCoordinates { /// Transforms a geographic 3D coordinate into a geographic 2D one. - func to2D(_: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to2D(_: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeographicCRS, NewCRS: GeographicCRS & TwoDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -19,7 +19,7 @@ public extension ThreeDimensionalCoordinates { EPSG9659.apply(on: self) } /// Override of ``Coordinates/to`` using the `to2D` transitive definition. - func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeographicCRS, NewCRS: GeographicCRS & TwoDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -28,7 +28,7 @@ public extension ThreeDimensionalCoordinates { } /// Transforms a geographic 3D coordinate into a geocentric 3D one. - func toGeocentric(_: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func toGeocentric(_: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeographicCRS, NewCRS: GeocentricCRS & ThreeDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -36,7 +36,7 @@ public extension ThreeDimensionalCoordinates { EPSG9602.apply(on: self) } /// Override of ``Coordinates/to`` using the `toGeocentric` transitive definition. - func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeographicCRS, NewCRS: GeocentricCRS & ThreeDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -45,7 +45,7 @@ public extension ThreeDimensionalCoordinates { } /// Transforms a geocentric 3D coordinate into a geographic 3D one. - func toGeographic(_: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func toGeographic(_: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeocentricCRS, NewCRS: GeographicCRS & ThreeDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -53,7 +53,7 @@ public extension ThreeDimensionalCoordinates { EPSG9602.unapply(from: self) } /// Override of ``Coordinates/to`` using the `toGeographic` transitive definition. - func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates where Self.CRS: GeocentricCRS, NewCRS: GeographicCRS & ThreeDimensionalCRS, NewCRS.Datum.PrimeMeridian == Self.CRS.Datum.PrimeMeridian @@ -64,7 +64,7 @@ public extension ThreeDimensionalCoordinates { public extension TwoDimensionalCoordinates { /// Transforms a geographic 2D coordinate into a geographic 3D one. - func to3D(_: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to3D(_: NewCRS.Type) -> NewCRS.Coordinates where NewCRS: GeographicCRS & ThreeDimensionalCRS, Self.CRS: GeographicCRS, Self.CRS.Datum.PrimeMeridian == NewCRS.Datum.PrimeMeridian @@ -72,7 +72,7 @@ public extension TwoDimensionalCoordinates { EPSG9659.unapply(from: self) } /// Override of ``Coordinates/to`` using the `to3D` transitive definition. - func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates + @inlinable func to(_ newCRS: NewCRS.Type) -> NewCRS.Coordinates where NewCRS: GeographicCRS & ThreeDimensionalCRS, Self.CRS: GeographicCRS, Self.CRS.Datum.PrimeMeridian == NewCRS.Datum.PrimeMeridian diff --git a/Sources/GeodeticDisplay/Coordinate+Display.swift b/Sources/GeodeticDisplay/Coordinate+Display.swift index 42e4f3a..163026d 100644 --- a/Sources/GeodeticDisplay/Coordinate+Display.swift +++ b/Sources/GeodeticDisplay/Coordinate+Display.swift @@ -6,18 +6,13 @@ // Copyright © 2021 Rémi Bardon. All rights reserved. // -import class Foundation.NumberFormatter -import class Foundation.NSNumber import Geodesy +import SwiftGeoToolbox extension CoordinateComponent { public func decimalNotation(maxDigits: UInt8 = 6) -> String { - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.maximumFractionDigits = Int(maxDigits) - formatter.locale = .en - return formatter.string(for: Double(self.rawValue)) ?? String(describing: self.rawValue) + DecimalNumberFormatter().string(for: self.rawValue, maxDigits: maxDigits) } } @@ -30,12 +25,12 @@ extension AngularCoordinateComponent { /// `(dd - deg) * 60` public var minutes: Double { - return decimalDegrees.fraction * 60 + return decimalDegrees.swiftgeo_fraction * 60 } /// `(|(dd - deg) * 60| - min) * 60` public var seconds: Double { - return minutes.fraction * 60 + return minutes.swiftgeo_fraction * 60 } public init(degrees: Int, minutes: Double) { @@ -53,49 +48,41 @@ extension AngularCoordinateComponent { extension AngularCoordinateComponent { public func ddNotation(maxDigits: UInt8 = 6) -> String { - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.maximumFractionDigits = Int(maxDigits) - formatter.locale = .en - return formatter.string(for: decimalDegrees) ?? String(decimalDegrees) + DecimalNumberFormatter().string(for: self.decimalDegrees, maxDigits: maxDigits) } public func dmNotation(full: Bool = false, maxDigits: UInt8 = 3) -> String { // Degree - var parts = ["\(Int(abs(decimalDegrees.whole)))°"] + var parts = ["\(Int(abs(decimalDegrees.swiftgeo_whole)))°"] // Minute - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.maximumFractionDigits = Int(maxDigits) - formatter.locale = .en - if full || minutes > 0, let string = formatter.string(for: minutes) { + if full || self.minutes > 0 { + let formatter = DecimalNumberFormatter() + let string = formatter.string(for: self.minutes, maxDigits: maxDigits) parts.append("\(string)'") } // Letter - parts.append(String(directionChar)) + parts.append(String(self.directionChar)) return parts.joined(separator: " ") } public func dmsNotation(full: Bool = false, maxDigits: UInt8 = 1) -> String { // Degree - var parts = ["\(Int(abs(decimalDegrees.whole)))°"] + var parts = ["\(Int(abs(decimalDegrees.swiftgeo_whole)))°"] // Minute - if full || minutes > 0 { parts.append("\(Int(minutes.whole))'") } + if full || self.minutes > 0 { parts.append("\(Int(self.minutes.swiftgeo_whole))'") } // Second - let formatter = NumberFormatter() - formatter.numberStyle = .decimal - formatter.maximumFractionDigits = Int(maxDigits) - formatter.locale = .en - if full || seconds > 0, let string = formatter.string(for: seconds) { + if full || self.seconds > 0 { + let formatter = DecimalNumberFormatter() + let string = formatter.string(for: self.seconds, maxDigits: maxDigits) parts.append("\(string)\"") } // Letter - parts.append(String(directionChar)) + parts.append(String(self.directionChar)) return parts.joined(separator: " ") } diff --git a/Sources/GeodeticDisplay/Toolbox/Exports.swift b/Sources/GeodeticDisplay/Exports.swift similarity index 100% rename from Sources/GeodeticDisplay/Toolbox/Exports.swift rename to Sources/GeodeticDisplay/Exports.swift diff --git a/Sources/GeodeticDisplay/GeographicNotation.swift b/Sources/GeodeticDisplay/GeographicNotation.swift index 5647967..983a668 100644 --- a/Sources/GeodeticDisplay/GeographicNotation.swift +++ b/Sources/GeodeticDisplay/GeographicNotation.swift @@ -11,40 +11,40 @@ import Foundation public protocol GeographicNotation { /// Decimal Degree notation. - func ddNotation(maxDigits: UInt8) -> String + @inlinable func ddNotation(maxDigits: UInt8) -> String /// Degree Minute notation (with or without `0` values). - func dmNotation(full: Bool, maxDigits: UInt8) -> String + @inlinable func dmNotation(full: Bool, maxDigits: UInt8) -> String /// Degree Minute Second notation (with or without `0` values). - func dmsNotation(full: Bool, maxDigits: UInt8) -> String + @inlinable func dmsNotation(full: Bool, maxDigits: UInt8) -> String } extension GeographicNotation { /// Decimal Degree notation. - public var ddNotation: String { + @inlinable public var ddNotation: String { self.ddNotation(maxDigits: 6) } /// Degree Minute notation. - public var dmNotation: String { + @inlinable public var dmNotation: String { self.dmNotation(maxDigits: 3) } /// Degree Minute Second notation. - public var dmsNotation: String { + @inlinable public var dmsNotation: String { self.dmsNotation(maxDigits: 4) } /// Degree Minute notation. - public func dmNotation(maxDigits: UInt8) -> String { + @inlinable public func dmNotation(maxDigits: UInt8) -> String { self.dmNotation(full: false, maxDigits: maxDigits) } /// Degree Minute Second notation. - public func dmsNotation(maxDigits: UInt8) -> String { + @inlinable public func dmsNotation(maxDigits: UInt8) -> String { self.dmsNotation(full: false, maxDigits: maxDigits) } diff --git a/Sources/GeodeticDisplay/Toolbox/FloatingPoint+Fraction.swift b/Sources/GeodeticDisplay/Toolbox/FloatingPoint+Fraction.swift deleted file mode 100644 index b5a079c..0000000 --- a/Sources/GeodeticDisplay/Toolbox/FloatingPoint+Fraction.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// FloatingPoint+Fraction.swift -// SwiftGeo -// -// Created by Rémi Bardon on 24/08/2021. -// Copyright © 2021 Rémi Bardon. All rights reserved. -// - -import Foundation - -/// Comes from [Getting the decimal part of a double in Swift](https://stackoverflow.com/a/55010456/10967642) -extension FloatingPoint { - var whole: Self { modf(self).0 } - var fraction: Self { modf(abs(self)).1 } -} diff --git a/Sources/GeodeticDisplay/Toolbox/Locale+Common.swift b/Sources/GeodeticDisplay/Toolbox/Locale+Common.swift deleted file mode 100644 index 59622ca..0000000 --- a/Sources/GeodeticDisplay/Toolbox/Locale+Common.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Locale+Common.swift -// SwiftGeo -// -// Created by Rémi Bardon on 03/02/2022. -// Copyright © 2022 Rémi Bardon. All rights reserved. -// - -import struct Foundation.Locale - -extension Locale { - static var en: Locale { Locale(identifier: "en_US") } -} diff --git a/Sources/SwiftGeoToolbox/DecimalNumberFormatter.swift b/Sources/SwiftGeoToolbox/DecimalNumberFormatter.swift new file mode 100644 index 0000000..711bcf4 --- /dev/null +++ b/Sources/SwiftGeoToolbox/DecimalNumberFormatter.swift @@ -0,0 +1,31 @@ +// +// DecimalNumberFormatter.swift +// SwiftGeo +// +// Created by Rémi Bardon on 12/01/2023. +// Copyright © 2023 Rémi Bardon. All rights reserved. +// + +import Foundation + +public struct DecimalNumberFormatter { + + public init() {} + + /// - Note: [Rémi BARDON] This is a bad implementation, but I couldn't find + /// a better/simpler one without using `Foundation`. + @inlinable public func string(for n: N, maxDigits: UInt8 = 6) -> String { + let sign: String = n.sign == .minus ? "-" : "" + let val: N = abs(n) + let whole: String = String(format: "%d", Int(val.swiftgeo_whole)) + let fraction: String = String(String( + format: "%.*g", + arguments: [ + maxDigits, + Double(val.swiftgeo_fraction), + ] + ).dropFirst()) + return sign + whole + fraction + } + +} diff --git a/Sources/SwiftGeoToolbox/FloatingPoint+Fraction.swift b/Sources/SwiftGeoToolbox/FloatingPoint+Fraction.swift new file mode 100644 index 0000000..7a08a67 --- /dev/null +++ b/Sources/SwiftGeoToolbox/FloatingPoint+Fraction.swift @@ -0,0 +1,12 @@ +// +// FloatingPoint+Fraction.swift +// SwiftGeo +// +// Created by Rémi Bardon on 24/08/2021. +// Copyright © 2021 Rémi Bardon. All rights reserved. +// + +public extension FloatingPoint { + var swiftgeo_whole: Self { self.rounded(.towardZero) } + var swiftgeo_fraction: Self { self - self.swiftgeo_whole } +} diff --git a/Sources/WGS84Core/WGS84+Display.swift b/Sources/WGS84Core/WGS84+Display.swift index a3b512a..f1de437 100644 --- a/Sources/WGS84Core/WGS84+Display.swift +++ b/Sources/WGS84Core/WGS84+Display.swift @@ -10,19 +10,19 @@ import GeodeticDisplay extension Coordinate2D: GeographicNotation { - public func ddNotation(maxDigits: UInt8) -> String { + @inlinable public func ddNotation(maxDigits: UInt8) -> String { let lat = self.latitude.ddNotation(maxDigits: maxDigits) let long = self.longitude.ddNotation(maxDigits: maxDigits) return "\(lat), \(long)" } - public func dmNotation(full: Bool = false, maxDigits: UInt8) -> String { + @inlinable public func dmNotation(full: Bool = false, maxDigits: UInt8) -> String { let lat = self.latitude.dmNotation(full: full, maxDigits: maxDigits) let long = self.longitude.dmNotation(full: full, maxDigits: maxDigits) return "\(lat), \(long)" } - public func dmsNotation(full: Bool = false, maxDigits: UInt8) -> String { + @inlinable public func dmsNotation(full: Bool = false, maxDigits: UInt8) -> String { let lat = self.latitude.dmsNotation(full: full, maxDigits: maxDigits) let long = self.longitude.dmsNotation(full: full, maxDigits: maxDigits) return "\(lat), \(long)" @@ -32,21 +32,21 @@ extension Coordinate2D: GeographicNotation { extension Coordinate3D: GeographicNotation { - public func ddNotation(maxDigits: UInt8) -> String { + @inlinable public func ddNotation(maxDigits: UInt8) -> String { let lat = self.latitude.ddNotation(maxDigits: maxDigits) let long = self.longitude.ddNotation(maxDigits: maxDigits) let alt = self.altitude.decimalNotation(maxDigits: maxDigits) return "\(lat), \(long), \(alt)" } - public func dmNotation(full: Bool = false, maxDigits: UInt8) -> String { + @inlinable public func dmNotation(full: Bool = false, maxDigits: UInt8) -> String { let lat = self.latitude.dmNotation(full: full, maxDigits: maxDigits) let long = self.longitude.dmNotation(full: full, maxDigits: maxDigits) let alt = self.altitude.decimalNotation(maxDigits: maxDigits) return "\(lat), \(long), \(alt)" } - public func dmsNotation(full: Bool = false, maxDigits: UInt8) -> String { + @inlinable public func dmsNotation(full: Bool = false, maxDigits: UInt8) -> String { let lat = self.latitude.dmsNotation(full: full, maxDigits: maxDigits) let long = self.longitude.dmsNotation(full: full, maxDigits: maxDigits) let alt = self.altitude.decimalNotation(maxDigits: maxDigits) diff --git a/SwiftGeo.xcworkspace/contents.xcworkspacedata b/SwiftGeo.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..aca3dc3 --- /dev/null +++ b/SwiftGeo.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftGeo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from Benchmarks/SwiftGeoBinarySizeBenchmark/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to SwiftGeo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Package.resolved b/SwiftGeo.xcworkspace/xcshareddata/swiftpm/Package.resolved similarity index 91% rename from Package.resolved rename to SwiftGeo.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4ccdcfd..056abba 100644 --- a/Package.resolved +++ b/SwiftGeo.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -31,8 +31,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { - "revision" : "f8a9c997c3c1dab4e216a8ec9014e23144cbab37", - "version" : "1.9.0" + "revision" : "f29e2014f6230cf7d5138fc899da51c7f513d467", + "version" : "1.10.0" } } ], diff --git a/Tests/GeodeticDisplayTests/GeodeticDisplayTests.swift b/Tests/GeodeticDisplayTests/GeodeticDisplayTests.swift index 28a0042..cb73f6c 100644 --- a/Tests/GeodeticDisplayTests/GeodeticDisplayTests.swift +++ b/Tests/GeodeticDisplayTests/GeodeticDisplayTests.swift @@ -12,15 +12,15 @@ import XCTest final class GeodeticDisplayTests: XCTestCase { func testDescriptions() { - let coord = Coordinate2D(x: 1.1232456789, y: -1.1232456789) - XCTAssertEqual(String(describing: coord), "(1.1232456789, -1.1232456789)") + let coord = Coordinate2D(x: 1.1232456789, y: -10.1232456789) + XCTAssertEqual(String(describing: coord), "(1.12324568, -10.12324568)") XCTAssertEqual( String(reflecting: coord), - "(1.1232456789, -1.1232456789)" + "(1.12324568, -10.12324568)" ) - XCTAssertEqual(coord.ddNotation, "1.123246, -1.123246") - XCTAssertEqual(coord.dmNotation, "1° 7.395' N, 1° 7.395' W") - XCTAssertEqual(coord.dmsNotation, #"1° 7' 23.6844" N, 1° 7' 23.6844" W"#) + XCTAssertEqual(coord.ddNotation, "1.123246, -10.123246") + XCTAssertEqual(coord.dmNotation, "1° 7.395' N, 10° 7.395' W") + XCTAssertEqual(coord.dmsNotation, #"1° 7' 23.6844" N, 10° 7' 23.6844" W"#) } } diff --git a/Tests/TurfCoreTests/CubicBezierSplineTests.swift b/Tests/TurfCoreTests/CubicBezierSplineTests.swift index 049e696..5a2676c 100644 --- a/Tests/TurfCoreTests/CubicBezierSplineTests.swift +++ b/Tests/TurfCoreTests/CubicBezierSplineTests.swift @@ -52,10 +52,10 @@ final class CubicBezierSplineTests: XCTestCase { ) -> String { """ (\ - \(String(describing: controls.0)),\ - \(String(describing: controls.1)),\ - \(String(describing: controls.2)),\ - \(String(describing: controls.3))\ + (\(controls.0.ddNotation)),\ + (\(controls.1.ddNotation)),\ + (\(controls.2.ddNotation)),\ + (\(controls.3.ddNotation))\ ) """ }