Skip to content

Commit

Permalink
added a unit test for reduce() on curves with extrema that are closeby
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutrell committed May 24, 2019
1 parent 3a78128 commit 880958b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions BezierKit/BezierKitTests/CubicBezierCurveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ class CubicBezierCurveTests: XCTestCase {
let result3 = c3.reduce()
XCTAssertTrue(BezierKitTestHelpers.isSatisfactoryReduceResult(result3, for: c3))
}

func testReduceExtremaCloseby() {
// the x coordinates are f(t) = (t-0.5)^2 = t^2 - t + 0.25, which has a minima at t=0.5
// the y coordinates are f(t) = 1/3t^3 - 1/2t^2 + 3/16t, which has an inflection at t=0.5
// adding `smallValue` to one of the y coordinates gives us two extrema very close to t=0.5
let smallValue: CGFloat = 1.0e-3
let c = BezierKitTestHelpers.cubicBezierCurveFromPolynomials([0,1,-1,0.25], [CGFloat(1.0 / 3.0), CGFloat(-1.0 / 2.0) + smallValue, CGFloat(3.0 / 16.0),0])
let result1 = c.reduce()
XCTAssertTrue(BezierKitTestHelpers.isSatisfactoryReduceResult(result1, for: c))
}
//
// // func testScaleDistanceFunc {
// //
Expand Down

0 comments on commit 880958b

Please sign in to comment.