Skip to content

Commit

Permalink
Merge pull request malcommac#20 from Coledunsby/master
Browse files Browse the repository at this point in the history
Support for Swift 5.3
  • Loading branch information
malcommac authored Oct 5, 2020
2 parents a03bcb6 + b6a39ba commit 16df51e
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 59 deletions.
102 changes: 84 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
# Created by https://www.toptal.com/developers/gitignore/api/xcode,swift,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,swift,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/

## Various settings
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -15,15 +53,11 @@ DerivedData/
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM
Expand All @@ -33,35 +67,67 @@ timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build
Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### Xcode ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore




## Gcc Patch
/*.gcno

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/xcode,swift,macos
27 changes: 9 additions & 18 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "SwiftSimplify",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftSimplify",
targets: ["SwiftSimplify"]),
platforms: [
.iOS(.v8),
.watchOS(.v2),
.tvOS(.v9)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
products: [
.library(name: "SwiftSimplify", targets: ["SwiftSimplify"])
],
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 which this package depends on.
.target(
name: "SwiftSimplify",
dependencies: []),
.testTarget(
name: "SwiftSimplifyTests",
dependencies: ["SwiftSimplify"]),
.target(name: "SwiftSimplify"),
.testTarget(name: "SwiftSimplifyTests", dependencies: ["SwiftSimplify"], resources: [.process("SimplifyTestPoints.json")])
]
)
26 changes: 13 additions & 13 deletions Sources/SwiftSimplify/Point2DRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public protocol Point2DRepresentable {
func equalsTo(_ compare: Self) -> Bool
}

extension Point2DRepresentable {
public extension Point2DRepresentable {

public func equalsTo(_ compare: Self) -> Bool {
return self.xValue == compare.xValue && self.yValue == compare.yValue
func equalsTo(_ compare: Self) -> Bool {
xValue == compare.xValue && yValue == compare.yValue
}

public func distanceFrom(_ otherPoint: Self) -> Float {
let dx = self.xValue - otherPoint.xValue
let dy = self.yValue - otherPoint.yValue
func distanceFrom(_ otherPoint: Self) -> Float {
let dx = xValue - otherPoint.xValue
let dy = yValue - otherPoint.yValue
return (dx * dx) + (dy * dy)
}

public func distanceToSegment(_ p1: Self, _ p2: Self) -> Float {
func distanceToSegment(_ p1: Self, _ p2: Self) -> Float {
var x = p1.xValue
var y = p1.yValue
var dx = p2.xValue - x
Expand All @@ -83,15 +83,15 @@ extension Point2DRepresentable {
}

extension CLLocationCoordinate2D: Point2DRepresentable {
public var xValue: Float { return Float(self.latitude) }
public var yValue: Float { return Float(self.longitude) }
public var xValue: Float { Float(latitude) }
public var yValue: Float { Float(longitude) }

public var cgPoint: CGPoint { return CGPoint(x: self.latitude, y: self.longitude) }
public var cgPoint: CGPoint { CGPoint(x: latitude, y: longitude) }
}

extension CGPoint: Point2DRepresentable {
public var xValue: Float { return Float(self.x) }
public var yValue: Float { return Float(self.y) }
public var xValue: Float { Float(x) }
public var yValue: Float { Float(y) }

public var cgPoint: CGPoint { return self }
public var cgPoint: CGPoint { self }
}
6 changes: 3 additions & 3 deletions Sources/SwiftSimplify/SwiftSimplify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import Foundation

// MARK: - SwiftSimplify

public struct SwiftSimplify {
public enum SwiftSimplify {

public static func simplify<P: Point2DRepresentable>(_ points: [P], tolerance: Float?, highestQuality: Bool = false) -> [P] {
guard points.count > 1 else {
return points
}

let sqTolerance = tolerance != nil ? (tolerance! * tolerance!): 1.0
let sqTolerance = tolerance != nil ? (tolerance! * tolerance!) : 1.0
var result = highestQuality ? points : simplifyRadialDistance(points, tolerance: sqTolerance)
result = simplifyDouglasPeucker(result, sqTolerance: sqTolerance)

Expand Down Expand Up @@ -120,7 +120,7 @@ public struct SwiftSimplify {
public extension Array where Element: Point2DRepresentable {

func simplify(tolerance: Float? = nil, highestQuality: Bool = true) -> [Element] {
return SwiftSimplify.simplify(self, tolerance: tolerance, highestQuality: highestQuality)
SwiftSimplify.simplify(self, tolerance: tolerance, highestQuality: highestQuality)
}

}
10 changes: 5 additions & 5 deletions Sources/SwiftSimplify/UIBezierPath+CGPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ public extension UIBezierPath {

// MARK: - CGPoint Extension

fileprivate extension CGPoint {
private extension CGPoint {

/// Get the mid point of the receiver with another passed point.
///
/// - Parameter p2: other point.
/// - Returns: mid point.
func midPointForPointsTo(_ p2: CGPoint) -> CGPoint {
return CGPoint(x: (x + p2.x) / 2, y: (y + p2.y) / 2)
CGPoint(x: (x + p2.x) / 2, y: (y + p2.y) / 2)
}

/// Control point to another point from receiver.
///
/// - Parameter p2: other point.
/// - Returns: control point for quad curve.
func controlPointToPoint(_ p2:CGPoint) -> CGPoint {
var controlPoint = self.midPointForPointsTo(p2)
var controlPoint = midPointForPointsTo(p2)
let diffY = abs(p2.y - controlPoint.y)
if self.y < p2.y {
if y < p2.y {
controlPoint.y = controlPoint.y + diffY
} else if ( self.y > p2.y ) {
} else if y > p2.y {
controlPoint.y = controlPoint.y - diffY
}
return controlPoint
Expand Down
2 changes: 1 addition & 1 deletion SwiftSimplify.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/malcommac/SwiftSimplify.git", :tag => s.version.to_s }
s.source_files = 'Sources/**/*.swift'
s.frameworks = "Foundation", "UIKit", "CoreLocation"
s.swift_version = "5.0"
s.swift_version = "5.3"
end
2 changes: 1 addition & 1 deletion iOSDemoApp/RenderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RenderView: UIView {

func renderPath(path: CGPath) {
self.path = path
self.setNeedsDisplay()
setNeedsDisplay()
}

override func draw(_ rect: CGRect) {
Expand Down

0 comments on commit 16df51e

Please sign in to comment.