From b5fa1682522d8c0d55f54b8a4f4a52fc8f0a45a3 Mon Sep 17 00:00:00 2001 From: YourMJK Date: Mon, 20 Feb 2023 06:35:00 +0100 Subject: [PATCH] Moved module to new separate Swift Package dependency --- Package.resolved | 9 ++ Package.swift | 2 + QRGen/GridSVG/GridSVG.Element.swift | 1 + QRGen/GridSVG/GridSVG.ElementCluster.swift | 1 + QRGen/GridSVG/GridSVG.swift | 1 + QRGen/IntGeometry/IntPoint.swift | 28 ---- QRGen/IntGeometry/IntRect.swift | 157 --------------------- QRGen/IntGeometry/IntSize.swift | 34 ----- QRGen/QRCode/QRCodeProtocol.swift | 1 + QRGen/QRGen.swift | 1 + 10 files changed, 16 insertions(+), 219 deletions(-) delete mode 100644 QRGen/IntGeometry/IntPoint.swift delete mode 100644 QRGen/IntGeometry/IntRect.swift delete mode 100644 QRGen/IntGeometry/IntSize.swift diff --git a/Package.resolved b/Package.resolved index 1674c34..99ce355 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "IntGeometry", + "repositoryURL": "https://github.com/YourMJK/IntGeometry", + "state": { + "branch": "main", + "revision": "0686c14ae7d1f7d05526d105f3a308f0ecd33fb5", + "version": null + } + }, { "package": "QRCodeGenerator", "repositoryURL": "https://github.com/YourMJK/QRCodeGenerator", diff --git a/Package.swift b/Package.swift index 5c02eab..c7fe5ff 100644 --- a/Package.swift +++ b/Package.swift @@ -10,12 +10,14 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/YourMJK/QRCodeGenerator", branch: "master"), + .package(url: "https://github.com/YourMJK/IntGeometry", branch: "main"), ], targets: [ .target( name: "QRGen", dependencies: [ "QRCodeGenerator", + "IntGeometry", ], path: "QRGen" ), diff --git a/QRGen/GridSVG/GridSVG.Element.swift b/QRGen/GridSVG/GridSVG.Element.swift index 3faff5c..ef51fad 100644 --- a/QRGen/GridSVG/GridSVG.Element.swift +++ b/QRGen/GridSVG/GridSVG.Element.swift @@ -6,6 +6,7 @@ // import Foundation +import IntGeometry extension GridSVG { diff --git a/QRGen/GridSVG/GridSVG.ElementCluster.swift b/QRGen/GridSVG/GridSVG.ElementCluster.swift index bbe62b0..17ac54a 100644 --- a/QRGen/GridSVG/GridSVG.ElementCluster.swift +++ b/QRGen/GridSVG/GridSVG.ElementCluster.swift @@ -6,6 +6,7 @@ // import Foundation +import IntGeometry extension GridSVG { diff --git a/QRGen/GridSVG/GridSVG.swift b/QRGen/GridSVG/GridSVG.swift index 4f9d24d..cef7fd8 100644 --- a/QRGen/GridSVG/GridSVG.swift +++ b/QRGen/GridSVG/GridSVG.swift @@ -6,6 +6,7 @@ // import Foundation +import IntGeometry class GridSVG { diff --git a/QRGen/IntGeometry/IntPoint.swift b/QRGen/IntGeometry/IntPoint.swift deleted file mode 100644 index 324b55a..0000000 --- a/QRGen/IntGeometry/IntPoint.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// IntPoint.swift -// QRGen -// -// Created by Max-Joseph on 15.08.22. -// - -import Foundation - - -public struct IntPoint: Equatable, Hashable { - public var x: Int - public var y: Int - public init(x: Int, y: Int) { - self.x = x - self.y = y - } -} - -public extension IntPoint { - static let zero = Self(x: 0, y: 0) -} - -public extension IntPoint { - func offsetBy(dx: Int, dy: Int) -> IntPoint { - IntPoint(x: x+dx, y: y+dy) - } -} diff --git a/QRGen/IntGeometry/IntRect.swift b/QRGen/IntGeometry/IntRect.swift deleted file mode 100644 index 7991402..0000000 --- a/QRGen/IntGeometry/IntRect.swift +++ /dev/null @@ -1,157 +0,0 @@ -// -// IntRect.swift -// QRGen -// -// Created by Max-Joseph on 15.08.22. -// - -import Foundation - - -public struct IntRect: Equatable { - public var origin: IntPoint - public var size: IntSize - public init(origin: IntPoint, size: IntSize) { - self.origin = origin - self.size = size - } -} - -public extension IntRect { - static let zero = Self(origin: .zero, size: .zero) - - init(x: Int, y: Int, width: Int, height: Int) { - self.origin = IntPoint(x: x, y: y) - self.size = IntSize(width: width, height: height) - } - - init(point1: IntPoint, point2: IntPoint) { - let minX = Swift.min(point1.x, point2.x) - let minY = Swift.min(point1.y, point2.y) - let maxX = Swift.max(point1.x, point2.x) - let maxY = Swift.max(point1.y, point2.y) - self.origin = IntPoint(x: minX, y: minY) - self.size = IntSize(width: maxX-minX, height: maxY-minY) - } -} - -public extension IntRect { - var minX: Int { - origin.x - } - var minY: Int { - origin.y - } - var minPoint: IntPoint { - origin - } - var maxX: Int { - origin.x + size.width - } - var maxY: Int { - origin.y + size.height - } - var maxPoint: IntPoint { - IntPoint(x: maxX, y: maxY) - } - - var width: Int { - size.width - } - var height: Int { - size.height - } - var isEmpty: Bool { - size.isEmpty - } -} - -public extension IntRect { - func offsetBy(dx: Int, dy: Int) -> IntRect { - IntRect(origin: origin.offsetBy(dx: dx, dy: dy), size: size) - } - func insetBy(dx: Int, dy: Int) -> IntRect { - IntRect(x: origin.x-dx, y: origin.y-dy, width: size.width-dx*2, height: size.height-dy*2) - } - - func union(_ r2: IntRect) -> IntRect { - let minX = Swift.min(self.minX, r2.minX) - let minY = Swift.min(self.minY, r2.minY) - let maxX = Swift.max(self.maxX, r2.maxX) - let maxY = Swift.max(self.maxY, r2.maxY) - return IntRect(origin: IntPoint(x: minX, y: minY), size: IntSize(width: maxX-minX, height: maxY-minY)) - } - func intersection(_ r2: IntRect) -> IntRect { - let minX = Swift.max(self.minX, r2.minX) - let minY = Swift.max(self.minY, r2.minY) - let maxX = Swift.min(self.maxX, r2.maxX) - let maxY = Swift.min(self.maxY, r2.maxY) - let width = maxX-minX - let height = maxY-minY - if width < 0 || height < 0 { return .zero } - return IntRect(origin: IntPoint(x: minX, y: minY), size: IntSize(width: width, height: height)) - } - - func contains(_ point: IntPoint) -> Bool { - minX <= point.x && minY <= point.y && point.x < maxX && point.y < maxY - } - func contains(_ rect2: IntRect) -> Bool { - union(rect2) == self - } - func intersects(_ rect2: IntRect) -> Bool { - !intersection(rect2).isEmpty - } -} - -extension IntRect: RandomAccessCollection { - public typealias Element = IntPoint - public typealias Index = Int - - public var startIndex: Int { - 0 - } - public var endIndex: Int { - width * height - } - - public subscript(index: Int) -> IntPoint { - get { - precondition(startIndex <= index && index < endIndex, "Index out of range") - let (j, i) = index.quotientAndRemainder(dividingBy: width) - return IntPoint(x: origin.x + i, y: origin.y + j) - } - } -} - -public extension IntRect { - struct Iterator: IteratorProtocol { - public typealias Element = IntRect.Element - - private let rangeX: Range - private let rangeY: Range - private var x: Int - private var y: Int - - init(_ rect: IntRect) { - self.rangeX = (rect.minX.. Element? { - if x >= rangeX.upperBound { - x = rangeX.lowerBound - y += 1 - } - guard x < rangeX.upperBound, y < rangeY.upperBound else { return nil } - let point = IntPoint(x: x, y: y) - x += 1 - return point - } - } - - func makeIterator() -> Iterator { - Iterator(self) - } -} diff --git a/QRGen/IntGeometry/IntSize.swift b/QRGen/IntGeometry/IntSize.swift deleted file mode 100644 index 84c8687..0000000 --- a/QRGen/IntGeometry/IntSize.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// IntSize.swift -// QRGen -// -// Created by Max-Joseph on 15.08.22. -// - -import Foundation - - -public struct IntSize: Equatable { - public var width: Int { - willSet { precondition(newValue >= 0, "Width of IntSize must be positive") } - } - public var height: Int { - willSet { precondition(newValue >= 0, "Height of IntSize must be positive") } - } - - public init(width: Int, height: Int) { - precondition(width >= 0 && height >= 0, "Width and height of IntSize must be positive") - self.width = width - self.height = height - } -} - -public extension IntSize { - static let zero = Self(width: 0, height: 0) -} - -public extension IntSize { - var isEmpty: Bool { - width == 0 || height == 0 - } -} diff --git a/QRGen/QRCode/QRCodeProtocol.swift b/QRGen/QRCode/QRCodeProtocol.swift index a2d3b53..e41438b 100644 --- a/QRGen/QRCode/QRCodeProtocol.swift +++ b/QRGen/QRCode/QRCodeProtocol.swift @@ -6,6 +6,7 @@ // import Foundation +import IntGeometry #if canImport(AppKit) import CoreGraphics #endif diff --git a/QRGen/QRGen.swift b/QRGen/QRGen.swift index 611901b..12526c6 100644 --- a/QRGen/QRGen.swift +++ b/QRGen/QRGen.swift @@ -6,6 +6,7 @@ // import Foundation +import IntGeometry #if canImport(AppKit) import CoreImage #endif