Skip to content

Commit

Permalink
More Comments and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranb662 committed Apr 11, 2020
1 parent bd582b4 commit d1bdbe6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# bez

A description of this package.
[Bez Info](BezInfo.pdf)
Bez is a swift package aimed at making Bézier curves easy to work with and manipulate.

The various utilities included are:
* **Interpolation Functions**
* **Derivatives**
* **Arc Lengths**
* **Segmentation**
* **Subdivision**
* **Lookup Table Generation**
* **Path Description -> Normalized SwiftUI Shape Conversion**


[bez Info](BezInfo.pdf)
4 changes: 4 additions & 0 deletions Sources/bez/LookupTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import simd

/// Iterates through all path elements and samples interpolated points on that segment (1 + numberOfDivisions) times
/// using the parametric representation of the specific Bézier curve.
/// - parameters:
/// - path: The path to be sampled
/// - capacity: The maximum number of sampled points (**Default**: 500)
///
@available(iOS 13.0, macOS 10.15, watchOS 6.0 , tvOS 13.0, *)
public func generateLookupTable(path: Path, capacity: Int = 500) -> [CGPoint] {
let elements = path.elements
Expand Down
18 changes: 9 additions & 9 deletions Sources/bez/PolyBezier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct PolyBezierElement: Identifiable {
}
return .cubic
}

public enum CommandType {
case line, quad, cubic, moveTo, closeSubpath
}
Expand Down Expand Up @@ -145,18 +145,18 @@ public class PolyBezier: ObservableObject {
switch element.type {
case .line: path.addLine(to: element.currentPositions[0])
case .quad: path.addQuadCurve(to: element.currentPositions[0],
control: element.currentPositions[1])
control: element.currentPositions[1])
case .cubic: path.addCurve(to: element.currentPositions[0],
control1: element.currentPositions[1],
control2: element.currentPositions[2])
control1: element.currentPositions[1],
control2: element.currentPositions[2])
case .moveTo: path.move(to: element.currentPositions[0])
case .closeSubpath: path.closeSubpath()
}
}
}
}
/// String representation of the current path
public var string: String { path.description }
public var string: String { path.description }

public init(elements: [PolyBezierElement]) { self.elements = elements }

Expand Down Expand Up @@ -282,10 +282,10 @@ public class PolyBezier: ObservableObject {
if element!.element.type != .moveTo { elements.insert(.closedSubPath(), at: element!.offset+1) }
} else {
let selected = elements.enumerated()
.filter({ id.contains($0.element.id) })
.filter({$0.element.type != .moveTo})
.reversed()
.map({$0.offset})
.filter({ id.contains($0.element.id) })
.filter({$0.element.type != .moveTo})
.reversed()
.map({$0.offset})
selected.forEach({ self.elements.insert(.closedSubPath(), at: $0+1)})
}
cleanUp()
Expand Down
2 changes: 0 additions & 2 deletions Sources/bez/Subdivision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import CoreGraphics



/// # Line Subdivision
/// Divides a line into `n` equal segments
@available(iOS 13.0, macOS 10.15, watchOS 6.0 , tvOS 13.0, *)
Expand Down

0 comments on commit d1bdbe6

Please sign in to comment.