Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
adjust linter settings + complete doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzagg16 committed Oct 3, 2019
1 parent 2ba694e commit dca1ba2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions .swiftformat
Expand Up @@ -10,3 +10,4 @@

# rules
--disable redundantReturn
--disable specifiers
6 changes: 3 additions & 3 deletions .swiftlint.yml
Expand Up @@ -41,7 +41,7 @@ opt_in_rules: # all opt-in rules up to version 0.35.0
- fatal_error_message
- file_header
# - file_name
- file_types_order
# - file_types_order
- first_where
- force_unwrapping
- function_default_parameter_at_end
Expand All @@ -62,7 +62,7 @@ opt_in_rules: # all opt-in rules up to version 0.35.0
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
# - multiline_parameters_brackets
- nimble_operator
- no_extension_access_modifier
- no_grouping_extension
Expand All @@ -85,7 +85,7 @@ opt_in_rules: # all opt-in rules up to version 0.35.0
- reduce_into
- redundant_nil_coalescing
- redundant_type_annotation
- required_deinit
# - required_deinit
- required_enum_case
- single_test_class
- sorted_first_last
Expand Down
6 changes: 3 additions & 3 deletions Sources/ControlPointUtilities.swift
Expand Up @@ -3,13 +3,13 @@ import Foundation

final class ControlPointUtilities {
/// Calculates the controlPoint
/// - Parameter radiusFactor: Default value: 1.0.
/// - Parameter radiusMultiplier: Defines the curve shape. Default value: 1.0.
/// - Returns: CGPoint: The control point
func controlPoint(_ origin: CGPoint,
_ destination: CGPoint,
radiusFactor: CGFloat = 1) -> CGPoint {
radiusMultiplier: CGFloat = 1) -> CGPoint {
let centerPoint = center(origin, destination)
let radius = (distance(origin, destination) / 2) * radiusFactor
let radius = (distance(origin, destination) / 2) * radiusMultiplier
let inclination = lineInclination(origin: origin, destination: destination)
return pointOnCircle(center: centerPoint, radius: radius, angle: rad(inclination - 90))
}
Expand Down
11 changes: 6 additions & 5 deletions Sources/LineOverlay.swift
Expand Up @@ -16,8 +16,9 @@ public struct LineOverlayStyle {
public protocol LineOverlaying {
var coordinates: [CLLocationCoordinate2D] { get }
var style: LineOverlayStyle { get }
func path(_ origin: CGPoint, _ destination: CGPoint) -> CGMutablePath
var boundsMapRect: MKMapRect { get set }

func path(_ origin: CGPoint, _ destination: CGPoint) -> CGMutablePath
}

public class LineOverlay: MKPolyline, LineOverlaying {
Expand All @@ -26,7 +27,7 @@ public class LineOverlay: MKPolyline, LineOverlaying {
lineWidth: 3,
alpha: 0.15)
public var boundsMapRect: MKMapRect = .world
public override var boundingMapRect: MKMapRect {
override public var boundingMapRect: MKMapRect {
return boundsMapRect
}

Expand All @@ -49,13 +50,13 @@ public class LineOverlay: MKPolyline, LineOverlaying {
}

public class ArcOverlay: LineOverlay {
public var radiusFactor: CGFloat = 1.0
public var radiusMultiplier: CGFloat = 1.0

public override func path(_ origin: CGPoint, _ destination: CGPoint) -> CGMutablePath {
override public func path(_ origin: CGPoint, _ destination: CGPoint) -> CGMutablePath {
let path = CGMutablePath()
path.move(to: origin)
let utils = ControlPointUtilities()
let controlPoint = utils.controlPoint(origin, destination, radiusFactor: radiusFactor)
let controlPoint = utils.controlPoint(origin, destination, radiusMultiplier: radiusMultiplier)
path.addQuadCurve(to: destination, control: controlPoint)
return path
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapLineOverlayRenderer.swift
Expand Up @@ -13,7 +13,7 @@ public class MapLineOverlayRenderer: MKOverlayPathRenderer {
invalidatePath()
}

public override func createPath() {
override public func createPath() {
guard let originCoordinate = lineOverlay.coordinates.first,
let destinationCoordinate = lineOverlay.coordinates.last else { return }
let origin = point(for: MKMapPoint(originCoordinate))
Expand Down
8 changes: 4 additions & 4 deletions Tests/curvyRouteTests/ControlPointUtilitiesTest.swift
Expand Up @@ -22,17 +22,17 @@ class ControlUtilitiesTest: XCTestCase {
XCTAssertEqual(controlPoint, CGPoint(x: 5, y: 5))
}

func testThatControlPointIsCorrectWithCustomRadiusFactor() {
func testThatControlPointIsCorrectWithCustomradiusMultiplier() {
let pointA = CGPoint(x: 0, y: 5)
let pointB = CGPoint(x: 10, y: 10)
let controlPoint = sut.controlPoint(pointA, pointB, radiusFactor: 0.7)
let controlPoint = sut.controlPoint(pointA, pointB, radiusMultiplier: 0.7)
XCTAssertEqual(controlPoint, CGPoint(x: 6.75, y: 4))
}

func testThatControlPointIsCorrectWithDoubleRadiusFactor() {
func testThatControlPointIsCorrectWithDoubleradiusMultiplier() {
let pointA = CGPoint(x: 0, y: 10)
let pointB = CGPoint(x: 10, y: 10)
let controlPoint = sut.controlPoint(pointA, pointB, radiusFactor: 2)
let controlPoint = sut.controlPoint(pointA, pointB, radiusMultiplier: 2)
XCTAssertEqual(controlPoint, CGPoint(x: 5.000000000000001, y: 0))
}
}
2 changes: 1 addition & 1 deletion curvyRouteSample/ViewController.swift
Expand Up @@ -30,7 +30,7 @@ class ViewController: UIViewController, MKMapViewDelegate {
mapView.addOverlay(LineOverlay(origin: pointA, destination: pointB))
let arc = ArcOverlay(origin: pointA, destination: pointB,
style: LineOverlayStyle(strokeColor: .systemTeal, lineWidth: 4, alpha: 1))
arc.radiusFactor = 0.5
arc.radiusMultiplier = 1.0
mapView.addOverlay(arc)
}
}

0 comments on commit dca1ba2

Please sign in to comment.