Skip to content

Commit

Permalink
Revert "marked boolean operations with "try!""
Browse files Browse the repository at this point in the history
This reverts commit 165a975.
  • Loading branch information
hfutrell committed Dec 8, 2018
1 parent f6a05e1 commit ee9e89a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions BezierKit/BezierKitTests/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class PathTests: XCTestCase {
)])
let square1 = createSquare1()
let square2 = createSquare2()
let subtracted = try! square1.subtracting(square2)
let subtracted = square1.subtracting(square2)
XCTAssertEqual(subtracted.subpaths.count, 1)
XCTAssert(
componentsEqualAsideFromElementOrdering(subtracted.subpaths[0], expectedResult.subpaths[0])
Expand All @@ -364,7 +364,7 @@ class PathTests: XCTestCase {
)])
let square1 = createSquare1()
let square2 = createSquare2()
let unioned = try! square1.union(square2)
let unioned = square1.union(square2)
XCTAssertEqual(unioned.subpaths.count, 1)
XCTAssert(
componentsEqualAsideFromElementOrdering(unioned.subpaths[0], expectedResult.subpaths[0])
Expand All @@ -382,7 +382,7 @@ class PathTests: XCTestCase {
)])
let square1 = createSquare1()
let square2 = createSquare2()
let intersected = try! square1.intersecting(square2)
let intersected = square1.intersecting(square2)
XCTAssertEqual(intersected.subpaths.count, 1)
XCTAssert(
componentsEqualAsideFromElementOrdering(intersected.subpaths[0], expectedResult.subpaths[0])
Expand All @@ -394,7 +394,7 @@ class PathTests: XCTestCase {
// the order of the hole is reversed so that it is not contained in the shape when using .winding fill rule
let circle = Path(cgPath: CGPath(ellipseIn: CGRect(x: 0, y: 0, width: 3, height: 3), transform: nil))
let hole = Path(cgPath: CGPath(ellipseIn: CGRect(x: 1, y: 1, width: 1, height: 1), transform: nil))
let donut = try! circle.subtracting(hole)
let donut = circle.subtracting(hole)
XCTAssertTrue(donut.contains(CGPoint(x: 0.5, y: 0.5), using: .winding)) // inside the donut (but not the hole)
XCTAssertFalse(donut.contains(CGPoint(x: 1.5, y: 1.5), using: .winding)) // center of donut hole
}
Expand All @@ -403,7 +403,7 @@ class PathTests: XCTestCase {
// this is a specific test of `subtracting` to ensure that if a path component is entirely contained in the subtracting path that it gets removed
let circle = Path(cgPath: CGPath(ellipseIn: CGRect(x: -1, y: -1, width: 2, height: 2), transform: nil))
let biggerCircle = Path(cgPath: CGPath(ellipseIn: CGRect(x: -2, y: -2, width: 4, height: 4), transform: nil))
XCTAssertEqual(try! circle.subtracting(biggerCircle).subpaths.count, 0)
XCTAssertEqual(circle.subtracting(biggerCircle).subpaths.count, 0)
}

func testSubtractingEdgeCase1() {
Expand All @@ -415,7 +415,7 @@ class PathTests: XCTestCase {
let circle = Path(cgPath: CGPath(ellipseIn: CGRect(x: 0, y: 0, width: 4, height: 4), transform: nil))

// the circle intersects the rect at (0,2) and (3, 0.26792) ... the last number being exactly 2 - sqrt(3)
let difference = try! rectangle.subtracting(circle)
let difference = rectangle.subtracting(circle)
XCTAssertEqual(difference.subpaths.count, 1)
XCTAssertFalse(difference.contains(CGPoint(x: 2.0, y: 2.0)))
}
Expand All @@ -434,7 +434,7 @@ class PathTests: XCTestCase {
square2CGPath.closeSubpath()

let square2 = Path(cgPath: square2CGPath)
let result = try! square1.subtracting(square2)
let result = square1.subtracting(square2)

let expectedResultCGPath = CGMutablePath()
expectedResultCGPath.move(to: CGPoint.zero)
Expand Down Expand Up @@ -474,7 +474,7 @@ class PathTests: XCTestCase {
XCTAssertTrue(path.contains(CGPoint(x: 1.5, y: 1.25), using: .winding))
XCTAssertFalse(path.contains(CGPoint(x: 1.5, y: 1.25), using: .evenOdd))

let result = try! path.crossingsRemoved()
let result = path.crossingsRemoved()
XCTAssertEqual(result.subpaths.count, 1)
XCTAssertTrue(componentsEqualAsideFromElementOrdering(result.subpaths[0], expectedResult.subpaths[0]))

Expand All @@ -483,15 +483,15 @@ class PathTests: XCTestCase {
cgPathAlt.addLines(between: Array(points[3..<points.count]) + Array(points[1...3]))
let pathAlt = Path(cgPath: cgPathAlt)

let resultAlt = try! pathAlt.crossingsRemoved()
let resultAlt = pathAlt.crossingsRemoved()
XCTAssertEqual(resultAlt.subpaths.count, 1)
XCTAssertTrue(componentsEqualAsideFromElementOrdering(resultAlt.subpaths[0], expectedResult.subpaths[0]))
}

func testCrossingsRemovedNoCrossings() {
// a test which ensures that if a path has no crossings then crossingsRemoved does not modify it
let square = Path(cgPath: CGPath(ellipseIn: CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0), transform: nil))
let result = try! square.crossingsRemoved()
let result = square.crossingsRemoved()
XCTAssertEqual(result.subpaths.count, 1)
XCTAssertTrue(componentsEqualAsideFromElementOrdering(result.subpaths[0], square.subpaths[0]))
}
Expand All @@ -518,7 +518,7 @@ class PathTests: XCTestCase {
XCTAssertEqual(contour.windingCount(CGPoint(x: 0.5, y: 0.5)), -1) // winding count at center of one square region
XCTAssertEqual( contour.windingCount(CGPoint(x: 1.5, y: 1.5)), 1) // winding count at center of other square region

let crossingsRemoved = try! contour.crossingsRemoved()
let crossingsRemoved = contour.crossingsRemoved()

XCTAssertEqual(crossingsRemoved.subpaths.count, 1)
XCTAssertTrue(componentsEqualAsideFromElementOrdering(crossingsRemoved.subpaths[0], contour.subpaths[0]))
Expand Down Expand Up @@ -559,7 +559,7 @@ class PathTests: XCTestCase {
}.filter { $0.length() > 0.0 }
let cleanPath = Path(subpaths: [PathComponent(curves: curves2)])

let result = try! cleanPath.crossingsRemoved(threshold: 1.0e-4)
let result = cleanPath.crossingsRemoved(threshold: 1.0e-4)

// check that the inner loop was eliminated by checking the winding count in the middle
XCTAssertEqual(result.windingCount(CGPoint(x: 0.5, y: 1)), 1)
Expand Down

0 comments on commit ee9e89a

Please sign in to comment.