Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Sep 14, 2019
2 parents b540335 + 13ab100 commit 95856a3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: Point2DRepresentable>(_ points: [P], tolerance: Float?, highestQuality: Bool = false) -> [P] {
guard points.count > 1 else {
return points
}
Expand All @@ -49,14 +49,14 @@ public struct SwiftSimplify {
return result
}

private static func simplifyRadialDistance(_ points: [Point2DRepresentable], tolerance: Float) -> [Point2DRepresentable] {
private static func simplifyRadialDistance<P: Point2DRepresentable>(_ 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.count {
currentPoint = points[i]
Expand All @@ -73,7 +73,7 @@ public struct SwiftSimplify {
return newPoints
}

private static func simplifyDPStep(_ points: [Point2DRepresentable], first: Int, last: Int, sqTolerance: Float, simplified: inout [Point2DRepresentable]) {
private static func simplifyDPStep<P: Point2DRepresentable>(_ points: [P], first: Int, last: Int, sqTolerance: Float, simplified: inout [P]) {

guard last > first else {
return
Expand All @@ -100,7 +100,7 @@ public struct SwiftSimplify {
}
}

private static func simplifyDouglasPeucker(_ points: [Point2DRepresentable], sqTolerance: Float) -> [Point2DRepresentable] {
private static func simplifyDouglasPeucker<P: Point2DRepresentable>(_ points: [P], sqTolerance: Float) -> [P] {
guard points.count > 1 else {
return []
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: Point2DRepresentable>(_ points: [P]) -> UIBezierPath {
let path = UIBezierPath()
guard points.count > 1 else {
return path
Expand Down
2 changes: 1 addition & 1 deletion SwiftSimplify.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion SwiftSimplify.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
644681B122C66C6B004D455B /* Point2DRepresentable.swift */,
644681BA22C67116004D455B /* UIBezierPath+CGPoint.swift */,
);
path = Sources;
name = Sources;
path = Sources/SwiftSimplify;
sourceTree = "<group>";
};
8933C7831EB5B7EB000D00A4 /* Tests */ = {
Expand Down

0 comments on commit 95856a3

Please sign in to comment.