Skip to content

Commit

Permalink
added bounding box based early return for windingCount, adjusting uni…
Browse files Browse the repository at this point in the history
…t test so that test data still fell inside the bounding box and therefore could not pass test trivially.
  • Loading branch information
hfutrell committed Feb 15, 2019
1 parent 257de50 commit 22c5ec7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BezierKit/BezierKitTests/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class PathTests: XCTestCase {
cgPath.move(to: CGPoint(x: 0.0, y: 1.0))
cgPath.addQuadCurve(to: CGPoint(x: 1.0, y: 0.0), control: CGPoint(x: 0, y: 0)) // quad curve has derivative exactly horizontal at t=1
cgPath.addLine(to: CGPoint(x: 2.0, y: -1.0e-5))
cgPath.addLine(to: CGPoint(x: 2.0, y: 1))
cgPath.addLine(to: CGPoint(x: 4.0, y: 1))
cgPath.closeSubpath()
let path = Path(cgPath: cgPath)
XCTAssertTrue(path.contains(CGPoint(x: 0.5, y: 0.5)))
Expand Down
3 changes: 3 additions & 0 deletions BezierKit/Library/PathComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public final class PathComponent: NSObject, NSCoding {
}

internal func windingCount(at point: CGPoint) -> Int {
guard self.boundingBox.contains(point) else {
return 0
}
// TODO: assumes element.normal() is always defined, which unfortunately it's not (eg degenerate curves as points, cusps, zero derivatives at the end of curves)
let line = LineSegment(p0: point, p1: CGPoint(x: self.boundingBox.min.x - self.boundingBox.size.x, y: point.y)) // horizontal line from point out of bounding box
let delta = line.p0 - line.p1
Expand Down

0 comments on commit 22c5ec7

Please sign in to comment.