Skip to content

Commit

Permalink
added a unit test for multicomponent paths that do not use move(to:) …
Browse files Browse the repository at this point in the history
…to start the next path component.
  • Loading branch information
hfutrell committed May 3, 2019
1 parent 1ba728a commit 8a31c5c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion BezierKit/BezierKitTests/Path+DataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fileprivate extension CGPath {
class PathDataTests: XCTestCase {

private func pathHasEqualElementsToCGPath(_ path1: Path, _ path2: CGPath) -> Bool {
return cgPathsHaveEqualCGPathElements(Path(data: path1.data)!.cgPath, path2)
return cgPathsHaveEqualCGPathElements(path1.cgPath, path2)
}

private func cgPathsHaveEqualCGPathElements(_ path1: CGPath, _ path2: CGPath) -> Bool {
Expand Down Expand Up @@ -152,6 +152,24 @@ class PathDataTests: XCTestCase {
XCTAssertTrue(pathHasEqualElementsToCGPath(Path(cgPath: cgPath), cgPath))
}

func testMultipleComponentsNoMoveto() {
// ensure that if the cgPath starts a new component without a move(to:) command that we still work properly
let cgPath = CGMutablePath()
let firstComponentPoints = [CGPoint(x: 0, y: 0),
CGPoint(x: 1, y: 0),
CGPoint(x: 1, y: 1),
CGPoint(x: 0, y: 1),
CGPoint(x: 0, y: 0)]
let secondComponentPoint = CGPoint(x: -1, y: 0)
cgPath.addLines(between: firstComponentPoints)
cgPath.closeSubpath()
cgPath.addLine(to: secondComponentPoint)

let path = Path(data: Path(cgPath: cgPath).data)!
XCTAssertEqual(path.components[0].points, firstComponentPoints)
XCTAssertEqual(path.components[1].points, [firstComponentPoints.last!, secondComponentPoint])
}

func testMultipleClosedPaths() {
let cgPath = CGMutablePath()
cgPath.addRect(CGRect(x: 1, y: 1, width: 2, height: 3))
Expand Down

0 comments on commit 8a31c5c

Please sign in to comment.