diff --git a/Package.swift b/Package.swift index c1a8a69..387a8ff 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Sources/Point2DRepresentable.swift b/Sources/SwiftSimplify/Point2DRepresentable.swift similarity index 86% rename from Sources/Point2DRepresentable.swift rename to Sources/SwiftSimplify/Point2DRepresentable.swift index 6031270..c1ea043 100644 --- a/Sources/Point2DRepresentable.swift +++ b/Sources/SwiftSimplify/Point2DRepresentable.swift @@ -39,25 +39,25 @@ public protocol Point2DRepresentable { var cgPoint: CGPoint { get } - func distanceFrom(_ otherPoint: Point2DRepresentable) -> Float - func distanceToSegment(_ p1: Point2DRepresentable, _ p2: Point2DRepresentable) -> Float + func distanceFrom(_ otherPoint: Self) -> Float + func distanceToSegment(_ p1: Self, _ p2: Self) -> Float - func equalsTo(_ compare: Point2DRepresentable) -> Bool + func equalsTo(_ compare: Self) -> Bool } extension Point2DRepresentable { - public func equalsTo(_ compare: Point2DRepresentable) -> Bool { + public func equalsTo(_ compare: Self) -> Bool { return self.xValue == compare.xValue && self.yValue == compare.yValue } - public func distanceFrom(_ otherPoint: Point2DRepresentable) -> Float { + public func distanceFrom(_ otherPoint: Self) -> Float { let dx = self.xValue - otherPoint.xValue let dy = self.yValue - otherPoint.yValue return (dx * dx) + (dy * dy) } - public func distanceToSegment(_ p1: Point2DRepresentable, _ p2: Point2DRepresentable) -> Float { + public func distanceToSegment(_ p1: Self, _ p2: Self) -> Float { var x = p1.xValue var y = p1.yValue var dx = p2.xValue - x diff --git a/Sources/SwiftSimplify.swift b/Sources/SwiftSimplify/SwiftSimplify.swift similarity index 85% rename from Sources/SwiftSimplify.swift rename to Sources/SwiftSimplify/SwiftSimplify.swift index 6a6bdf5..e29ba00 100644 --- a/Sources/SwiftSimplify.swift +++ b/Sources/SwiftSimplify/SwiftSimplify.swift @@ -37,7 +37,7 @@ import Foundation public struct SwiftSimplify { - public static func simplify(_ points: [Point2DRepresentable], tolerance: Float?, highestQuality: Bool = false) -> [Point2DRepresentable] { + public static func simplify(_ points: [P], tolerance: Float?, highestQuality: Bool = false) -> [P] { guard points.count > 1 else { return points } @@ -49,14 +49,14 @@ public struct SwiftSimplify { return result } - private static func simplifyRadialDistance(_ points: [Point2DRepresentable], tolerance: Float) -> [Point2DRepresentable] { + private static func simplifyRadialDistance(_ points: [P], tolerance: Float) -> [P] { guard points.count > 2 else { return points } var prevPoint = points.first! var newPoints = [prevPoint] - var currentPoint: Point2DRepresentable! + var currentPoint: P! for i in 1..(_ points: [P], first: Int, last: Int, sqTolerance: Float, simplified: inout [P]) { guard last > first else { return @@ -100,7 +100,7 @@ public struct SwiftSimplify { } } - private static func simplifyDouglasPeucker(_ points: [Point2DRepresentable], sqTolerance: Float) -> [Point2DRepresentable] { + private static func simplifyDouglasPeucker(_ points: [P], sqTolerance: Float) -> [P] { guard points.count > 1 else { return [] } @@ -117,7 +117,7 @@ public struct SwiftSimplify { // MARK: - Array Extension -public extension Array where Element == Point2DRepresentable { +public extension Array where Element: Point2DRepresentable { func simplify(tolerance: Float? = nil, highestQuality: Bool = true) -> [Element] { return SwiftSimplify.simplify(self, tolerance: tolerance, highestQuality: highestQuality) diff --git a/Sources/UIBezierPath+CGPoint.swift b/Sources/SwiftSimplify/UIBezierPath+CGPoint.swift similarity index 97% rename from Sources/UIBezierPath+CGPoint.swift rename to Sources/SwiftSimplify/UIBezierPath+CGPoint.swift index 262c926..a248a39 100644 --- a/Sources/UIBezierPath+CGPoint.swift +++ b/Sources/SwiftSimplify/UIBezierPath+CGPoint.swift @@ -40,7 +40,7 @@ public extension UIBezierPath { /// /// - Parameter points: points of the path. /// - Returns: smoothed UIBezierPath. - static func smoothFromPoints(_ points: [Point2DRepresentable]) -> UIBezierPath { + static func smoothFromPoints(_ points: [P]) -> UIBezierPath { let path = UIBezierPath() guard points.count > 1 else { return path diff --git a/SwiftSimplify.podspec b/SwiftSimplify.podspec index e4a821f..1614bc0 100644 --- a/SwiftSimplify.podspec +++ b/SwiftSimplify.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftSimplify" - s.version = "1.0.0" + s.version = "1.1.0" s.summary = "High-performance Swift polyline simplification library ported from Javascript's Simplify.js" s.description = <<-DESC SwiftSimplify is a tiny high-performance Swift polyline simplification library ported from Javascript's Simplify.js. Original work come from Leaflet, a JS interactive maps library by Vladimir Agafonkin. It uses a combination of Douglas-Peucker and Radial Distance algorithms. Works both on browser and server platforms. diff --git a/SwiftSimplify.xcodeproj/project.pbxproj b/SwiftSimplify.xcodeproj/project.pbxproj index e265f7e..abb2768 100644 --- a/SwiftSimplify.xcodeproj/project.pbxproj +++ b/SwiftSimplify.xcodeproj/project.pbxproj @@ -178,7 +178,8 @@ 644681B122C66C6B004D455B /* Point2DRepresentable.swift */, 644681BA22C67116004D455B /* UIBezierPath+CGPoint.swift */, ); - path = Sources; + name = Sources; + path = Sources/SwiftSimplify; sourceTree = ""; }; 8933C7831EB5B7EB000D00A4 /* Tests */ = {