Skip to content

Commit

Permalink
Merge pull request #85 from hfutrell/public-bernstein
Browse files Browse the repository at this point in the history
Public bernstein
  • Loading branch information
hfutrell committed Jan 26, 2021
2 parents 00b7870 + ddb6ef5 commit 70b38d1
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 241 deletions.
12 changes: 12 additions & 0 deletions BezierKit/BezierKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
FD84360622B0091500AA90EF /* PathComponent+WindingCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD84360422B0091500AA90EF /* PathComponent+WindingCount.swift */; };
FDA727591ED5035300011871 /* CubicCurveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDA727581ED5035300011871 /* CubicCurveTests.swift */; };
FDA7275A1ED5035300011871 /* CubicCurveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDA727581ED5035300011871 /* CubicCurveTests.swift */; };
FDB6011B25BB9B3700BAB067 /* BezierCurve+Polynomial.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6011A25BB9B3700BAB067 /* BezierCurve+Polynomial.swift */; };
FDB6011C25BB9B3700BAB067 /* BezierCurve+Polynomial.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6011A25BB9B3700BAB067 /* BezierCurve+Polynomial.swift */; };
FDB6012225BBA06600BAB067 /* BezierCurve+PolynomialTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6012125BBA06600BAB067 /* BezierCurve+PolynomialTests.swift */; };
FDB6012325BBA06600BAB067 /* BezierCurve+PolynomialTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6012125BBA06600BAB067 /* BezierCurve+PolynomialTests.swift */; };
FDB6B4021EAFD6DF00001C61 /* BezierCurve.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6B3F71EAFD6DF00001C61 /* BezierCurve.swift */; };
FDB6B4031EAFD6DF00001C61 /* BezierCurve.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6B3F71EAFD6DF00001C61 /* BezierCurve.swift */; };
FDB6B4041EAFD6DF00001C61 /* CubicCurve.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB6B3F81EAFD6DF00001C61 /* CubicCurve.swift */; };
Expand Down Expand Up @@ -170,6 +174,8 @@
FD80FF8922B1CEE00018C592 /* LockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockTests.swift; sourceTree = "<group>"; };
FD84360422B0091500AA90EF /* PathComponent+WindingCount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PathComponent+WindingCount.swift"; sourceTree = "<group>"; };
FDA727581ED5035300011871 /* CubicCurveTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CubicCurveTests.swift; sourceTree = "<group>"; };
FDB6011A25BB9B3700BAB067 /* BezierCurve+Polynomial.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BezierCurve+Polynomial.swift"; sourceTree = "<group>"; };
FDB6012125BBA06600BAB067 /* BezierCurve+PolynomialTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BezierCurve+PolynomialTests.swift"; sourceTree = "<group>"; };
FDB6B3F71EAFD6DF00001C61 /* BezierCurve.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BezierCurve.swift; sourceTree = "<group>"; };
FDB6B3F81EAFD6DF00001C61 /* CubicCurve.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CubicCurve.swift; sourceTree = "<group>"; };
FDB6B3F91EAFD6DF00001C61 /* Draw.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Draw.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,6 +285,7 @@
FD0F550A1DC43FFB0084CDCD /* Info.plist */,
FD0F55081DC43FFB0084CDCD /* BezierKitTestHelpers.swift */,
FDF0664D1FFA0C9900123308 /* BezierCurveTests.swift */,
FDB6012125BBA06600BAB067 /* BezierCurve+PolynomialTests.swift */,
FDE6CD8E1EC8F9BD00FAB479 /* LineSegmentTests.swift */,
FDA727581ED5035300011871 /* CubicCurveTests.swift */,
FD40244F2110CF5100FA723C /* QuadraticCurveTests.swift */,
Expand Down Expand Up @@ -326,6 +333,7 @@
FD149EB92135CBFF009E791D /* AugmentedGraph.swift */,
FDC859622119274A00AF7642 /* BoundingBoxHierarchy.swift */,
FDB6B3F71EAFD6DF00001C61 /* BezierCurve.swift */,
FDB6011A25BB9B3700BAB067 /* BezierCurve+Polynomial.swift */,
FD5CF14B22400FCA00FE15A6 /* BezierCurve+Intersection.swift */,
FDB6B3F81EAFD6DF00001C61 /* CubicCurve.swift */,
FDB6B3FC1EAFD6DF00001C61 /* CGPoint+Overloads.swift */,
Expand Down Expand Up @@ -657,6 +665,7 @@
FDB6B40F1EAFD6DF00001C61 /* PathComponent.swift in Sources */,
FDB6B4151EAFD6DF00001C61 /* Utils.swift in Sources */,
FDCE99A6223C404E00597989 /* Path+Data.swift in Sources */,
FDB6011C25BB9B3700BAB067 /* BezierCurve+Polynomial.swift in Sources */,
FDC2EB4B2298735C007768FC /* Lock.swift in Sources */,
FDB6B4071EAFD6DF00001C61 /* Draw.swift in Sources */,
FDB6B4131EAFD6DF00001C61 /* Types.swift in Sources */,
Expand All @@ -683,6 +692,7 @@
FDB6B40E1EAFD6DF00001C61 /* PathComponent.swift in Sources */,
FDB6B4141EAFD6DF00001C61 /* Utils.swift in Sources */,
FDCE99A5223C404E00597989 /* Path+Data.swift in Sources */,
FDB6011B25BB9B3700BAB067 /* BezierCurve+Polynomial.swift in Sources */,
FDC2EB4A2298735C007768FC /* Lock.swift in Sources */,
FDB6B4061EAFD6DF00001C61 /* Draw.swift in Sources */,
FDB6B4121EAFD6DF00001C61 /* Types.swift in Sources */,
Expand All @@ -708,6 +718,7 @@
FD12F1E22288CF6900404CE1 /* UtilsTests.swift in Sources */,
FDA727591ED5035300011871 /* CubicCurveTests.swift in Sources */,
FDB9D7331EB28CEB00413F0E /* BezierKit_iOSTests.swift in Sources */,
FDB6012225BBA06600BAB067 /* BezierCurve+PolynomialTests.swift in Sources */,
FD80FF8A22B1CEE00018C592 /* LockTests.swift in Sources */,
FDE6CD8F1EC8F9BD00FAB479 /* LineSegmentTests.swift in Sources */,
FD4024502110CF5100FA723C /* QuadraticCurveTests.swift in Sources */,
Expand Down Expand Up @@ -737,6 +748,7 @@
FD12F1E32288CF6900404CE1 /* UtilsTests.swift in Sources */,
FDA7275A1ED5035300011871 /* CubicCurveTests.swift in Sources */,
FDB9D7421EB28D1900413F0E /* BezierKit_MacTests.swift in Sources */,
FDB6012325BBA06600BAB067 /* BezierCurve+PolynomialTests.swift in Sources */,
FD80FF8B22B1CEE00018C592 /* LockTests.swift in Sources */,
FDE6CD901EC8F9BD00FAB479 /* LineSegmentTests.swift in Sources */,
FD4024512110CF5100FA723C /* QuadraticCurveTests.swift in Sources */,
Expand Down
78 changes: 78 additions & 0 deletions BezierKit/BezierKitTests/BezierCurve+PolynomialTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// BezierCurve+PolynomialTests.swift
// BezierKit
//
// Created by Holmes Futrell on 1/22/21.
// Copyright © 2021 Holmes Futrell. All rights reserved.
//

import BezierKit
import XCTest

class BezierCurve_PolynomialTests: XCTestCase {

func testPolynomialLineSegment() {
let lineSegment = LineSegment(p0: CGPoint(x: 3, y: 4), p1: CGPoint(x: 5, y: 6))
XCTAssertEqual(lineSegment.xPolynomial, BernsteinPolynomial1(b0: 3, b1: 5))
XCTAssertEqual(lineSegment.yPolynomial, BernsteinPolynomial1(b0: 4, b1: 6))
}

func testPolynomialQuadratic() {
let quadratic = QuadraticCurve(p0: CGPoint(x: 1, y: 0),
p1: CGPoint(x: 2, y: -2),
p2: CGPoint(x: 3, y: -1))
XCTAssertEqual(quadratic.xPolynomial, BernsteinPolynomial2(b0: 1, b1: 2, b2: 3))
XCTAssertEqual(quadratic.yPolynomial, BernsteinPolynomial2(b0: 0, b1: -2, b2: -1))
}

func testPolynomialCubic() {
let cubic = CubicCurve(p0: CGPoint(x: 1, y: 0),
p1: CGPoint(x: 2, y: 2),
p2: CGPoint(x: 3, y: 1),
p3: CGPoint(x: 4, y: -1))
XCTAssertEqual(cubic.xPolynomial, BernsteinPolynomial3(b0: 1, b1: 2, b2: 3, b3: 4))
XCTAssertEqual(cubic.yPolynomial, BernsteinPolynomial3(b0: 0, b1: 2, b2: 1, b3: -1))
}

func testExtremaLine() {
let l1 = LineSegment(p0: CGPoint(x: 1.0, y: 2.0), p1: CGPoint(x: 4.0, y: 6.0))
let (x1, y1, all1) = l1.extrema()
XCTAssertTrue(x1.isEmpty)
XCTAssertTrue(y1.isEmpty)
XCTAssertTrue(all1.isEmpty)

let l2 = LineSegment(p0: CGPoint(x: 1.0, y: 2.0), p1: CGPoint(x: 4.0, y: 2.0))
let (x2, y2, all2) = l2.extrema()
XCTAssertTrue(x2.isEmpty)
XCTAssertTrue(y2.isEmpty)
XCTAssertTrue(all2.isEmpty)
}

func testExtremaQuadratic() {
let f: [CGFloat] = [4, -2, 1] // f(t) = 4t^2 - 2t + 1, which has a local minimum at t = 0.25
let g: [CGFloat] = [1, -4, 4] // g(t) = t^2 -4t + 4, which has a local minimum at t = 2 (outside parameter range)
let q = BezierKitTestHelpers.quadraticCurveFromPolynomials(f, g)
let (x, y, all) = q.extrema()
XCTAssertEqual(all.count, 1)
XCTAssertEqual(all[0], 0.25)
XCTAssertEqual(x.count, 1)
XCTAssertEqual(x[0], 0.25)
XCTAssertTrue(y.isEmpty)
}

func testExtremaCubic() {
let f: [CGFloat] = [1, -1, 0, 0] // f(t) = t^3 - t^2, which has two local minimum at t=0, t=2/3 and an inflection point t=1/3
let g: [CGFloat] = [0, 3, -2, 0] // g(t) = 3t^2 - 2t, which has a local minimum at t=1/3
let c = BezierKitTestHelpers.cubicCurveFromPolynomials(f, g)
let (x, y, all) = c.extrema()
XCTAssertEqual(all.count, 3)
XCTAssertEqual(all[0], 0.0)
XCTAssertEqual(all[1], 1.0 / 3.0)
XCTAssertEqual(all[2], 2.0 / 3.0)
XCTAssertEqual(x[0], 0.0)
XCTAssertEqual(x[1], 1.0 / 3.0)
XCTAssertEqual(x[2], 2.0 / 3.0)
XCTAssertEqual(y.count, 1)
XCTAssertEqual(y[0], 1.0 / 3.0)
}
}
15 changes: 9 additions & 6 deletions BezierKit/BezierKitTests/BezierKitTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class BezierKitTestHelpers {
return sum
}

static func quadraticCurveFromPolynomials(_ f: [CGFloat], _ g: [CGFloat]) -> QuadraticCurve {
precondition(f.count == 3 && g.count == 3)
let curve = QuadraticCurve(p0: CGPoint(x: f[2], y: g[2]),
p1: CGPoint(x: 0.5 * f[1] + f[2], y: 0.5 * g[1] + g[2]),
p2: CGPoint(x: f[0] + f[1] + f[2], y: g[0] + g[1] + g[2]))
return curve
}

static func cubicCurveFromPolynomials(_ f: [CGFloat], _ g: [CGFloat]) -> CubicCurve {
precondition(f.count == 4 && g.count == 4)
// create a cubic bezier curve from two polynomials
Expand All @@ -89,12 +97,7 @@ class BezierKitTestHelpers {
let b = r / 3.0 + a
let c = q / 3.0 + 2.0 * b - a
let d = p + a - 3.0 * b + 3.0 * c
// check that it worked
let curve = CubicCurve(p0: a, p1: b, p2: c, p3: d)
for t: CGFloat in stride(from: 0, through: 1, by: 0.1) {
assert(distance(curve.point(at: t), CGPoint(x: evaluatePolynomial(f, at: t), y: evaluatePolynomial(g, at: t))) < 0.001, "internal error! failed to fit polynomial!")
}
return curve
return CubicCurve(p0: a, p1: b, p2: c, p3: d)
}

static func isSatisfactoryReduceResult<A>(_ result: [Subcurve<A>], for curve: A) -> Bool {
Expand Down
16 changes: 0 additions & 16 deletions BezierKit/BezierKitTests/CubicCurveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,6 @@ class CubicCurveTests: XCTestCase {
XCTAssertEqual(c1.length(), 5.0, accuracy: epsilon)
}

func testExtrema() {
let f: [CGFloat] = [1, -1, 0, 0] // f(t) = t^3 - t^2, which has two local minimum at t=0, t=2/3 and an inflection point t=1/3
let g: [CGFloat] = [0, 3, -2, 0] // g(t) = 3t^2 - 2t, which has a local minimum at t=1/3
let c = BezierKitTestHelpers.cubicCurveFromPolynomials(f, g)
let (x, y, all) = c.extrema()
XCTAssertEqual(all.count, 3)
XCTAssertEqual(all[0], 0.0)
XCTAssertEqual(all[1], 1.0 / 3.0)
XCTAssertEqual(all[2], 2.0 / 3.0)
XCTAssertEqual(x[0], 0.0)
XCTAssertEqual(x[1], 1.0 / 3.0)
XCTAssertEqual(x[2], 2.0 / 3.0)
XCTAssertEqual(y.count, 1)
XCTAssertEqual(y[0], 1.0 / 3.0)
}

func testProject() {
let epsilon: CGFloat = 1.0e-5
// test a cubic
Expand Down
8 changes: 0 additions & 8 deletions BezierKit/BezierKitTests/LineSegmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ class LineSegmentTests: XCTestCase {
XCTAssertEqual(l.length(), 5.0)
}

func testExtrema() {
let l = LineSegment(p0: CGPoint(x: 1.0, y: 2.0), p1: CGPoint(x: 4.0, y: 6.0))
let (x, y, all) = l.extrema()
XCTAssertTrue(x.isEmpty)
XCTAssertTrue(y.isEmpty)
XCTAssertTrue(all.isEmpty)
}

func testProject() {
let l = LineSegment(p0: CGPoint(x: 1.0, y: 2.0), p1: CGPoint(x: 5.0, y: 6.0))
let p1 = l.project(CGPoint(x: 0.0, y: 0.0)) // should project to p0
Expand Down
63 changes: 36 additions & 27 deletions BezierKit/BezierKitTests/PolynomialTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,83 @@ import XCTest

class PolynomialTests: XCTestCase {

let accuracy = 1.0e-5
let accuracy: CGFloat = 1.0e-5

func testEvaluation() {
let point = BernsteinPolynomial0(b0: 3.0)
XCTAssertEqual(point.reduce(a1: 1, a2: 2), 0)
XCTAssertEqual(point.f(0), 3)
XCTAssertEqual(point.f(0.5), 3)
XCTAssertEqual(point.f(1), 3)
XCTAssertEqual(point.value(at: 0), 3)
XCTAssertEqual(point.value(at: 0.5), 3)
XCTAssertEqual(point.value(at: 1), 3)
XCTAssertEqual(point.derivative, BernsteinPolynomial0(b0: 0.0))
XCTAssertEqual(point.analyticalRoots(between: 0, and: 1), [])
XCTAssertEqual(point.distinctAnalyticalRoots(between: 0, and: 1), [])
XCTAssertEqual(point.coefficients, [3.0])

let line = BernsteinPolynomial1(b0: 2.0, b1: 4.0)
XCTAssertEqual(line.f(0), 2)
XCTAssertEqual(line.f(0.5), 3)
XCTAssertEqual(line.f(1), 4)
XCTAssertEqual(line.value(at: 0), 2)
XCTAssertEqual(line.value(at: 0.5), 3)
XCTAssertEqual(line.value(at: 1), 4)
XCTAssertEqual(line.derivative, BernsteinPolynomial0(b0: 2))
XCTAssertEqual(line.analyticalRoots(between: -2, and: 1), [-1])
XCTAssertEqual(line.analyticalRoots(between: 0, and: 1), [])
XCTAssertEqual(line.distinctAnalyticalRoots(between: -2, and: 1), [-1])
XCTAssertEqual(line.distinctAnalyticalRoots(between: 0, and: 1), [])
XCTAssertEqual(line.coefficients, [2, 4])

let quad = BernsteinPolynomial2(b0: -1, b1: 1.0, b2: 0.0)
XCTAssertEqual(quad.f(0), -1)
XCTAssertEqual(quad.f(0.5), 0.25)
XCTAssertEqual(quad.f(1), 0)
XCTAssertEqual(quad.value(at: 0), -1)
XCTAssertEqual(quad.value(at: 0.5), 0.25)
XCTAssertEqual(quad.value(at: 1), 0)
XCTAssertEqual(quad.derivative, BernsteinPolynomial1(b0: 4, b1: -2))
XCTAssertEqual(quad.coefficients, [-1, 1, 0])
}

func testDegree1() {
let polynomial = BernsteinPolynomial1(b0: -3, b1: 2)
let roots = findRoots(of: polynomial, between: -1, and: 1)
let roots = findDistinctRoots(of: polynomial, between: -1, and: 1)
XCTAssertEqual(roots.count, 1)
XCTAssertEqual(roots[0], 0.6, accuracy: accuracy)
XCTAssertEqual(roots[0], CGFloat(0.6), accuracy: accuracy)
}

func testDegree2() {
let polynomial = BernsteinPolynomial2(b0: -5, b1: -6, b2: -4)
let roots = findRoots(of: polynomial, between: -10, and: 10)
let roots = findDistinctRoots(of: polynomial, between: -10, and: 10)
XCTAssertEqual(roots[0], -1, accuracy: accuracy)
XCTAssertEqual(roots[1], 1.0 + 2.0 / 3.0, accuracy: accuracy)
}

func testDegree3() {
// x^3 - 6x^2 + 11x - 6
let polynomial = BernsteinPolynomial3(b0: -6, b1: -7.0 / 3.0, b2: -2.0 / 3.0, b3: 0)
XCTAssertEqual(polynomial.coefficients, [-6, -7.0 / 3.0, -2.0 / 3.0, 0.0])
let roots = findRoots(of: polynomial, between: 0, and: 4)
XCTAssertEqual(polynomial.coefficients, [-6, CGFloat(-7.0 / 3.0), CGFloat(-2.0 / 3.0), 0.0])
let roots = findDistinctRoots(of: polynomial, between: 0, and: 4)
XCTAssertEqual(roots[0], 1, accuracy: accuracy)
XCTAssertEqual(roots[1], 2, accuracy: accuracy)
XCTAssertEqual(roots[2], 3, accuracy: accuracy)
}

func testDegree3RepeatedRoot() {
func testDegree3RepeatedRoot1() {
// x^3 - 4x^2 + 5x - 2
// repeated root at x = 1
let polynomial = BernsteinPolynomial3(b0: -2, b1: -1.0 / 3.0, b2: 0, b3: 0)
let roots = findRoots(of: polynomial, between: -1, and: 3)
let roots = findDistinctRoots(of: polynomial, between: -1, and: 3)
XCTAssertEqual(roots[0], 1, accuracy: accuracy)
XCTAssertEqual(roots[1], 2, accuracy: accuracy)
}

// func testDegree3RootExactlyZero() {
// // root is exactly t = 0 (at the start of unit interval),
// // so may be accidentally discarded due to numerical precision
// let polynomial = BernsteinPolynomial3(b0: 0, b1: 96, b2: -24, b3: -36)
// let roots = findRoots(of: polynomial, between: 0, and: 1)
// XCTAssertEqual(roots.count, 2)
// XCTAssertEqual(roots[0], 0.0)
// XCTAssertEqual(roots[1], 2.0 / 3.0, accuracy: accuracy)
// }

func testDegree4() {
// x^4 - 2.44x^2 + 1.44
let polynomial = BernsteinPolynomial4(b0: 1.44, b1: 1.44, b2: 1.44 - 1.22 / 3, b3: 0.22, b4: 0)
XCTAssertEqual(polynomial.coefficients, [1.44, 1.44, 1.44 - 1.22 / 3, 0.22, 0])
let roots = findRoots(of: polynomial, between: -2, and: 2)
let polynomial = BernsteinPolynomial4(b0: 1.44, b1: 1.44, b2: CGFloat(1.44 - 1.22 / 3), b3: 0.22, b4: 0)
XCTAssertEqual(polynomial.coefficients, [1.44, 1.44, CGFloat(1.44 - 1.22 / 3), 0.22, 0])
let roots = findDistinctRoots(of: polynomial, between: -2, and: 2)
XCTAssertEqual(roots[0], -1.2, accuracy: accuracy)
XCTAssertEqual(roots[1], -1, accuracy: accuracy)
XCTAssertEqual(roots[2], 1, accuracy: accuracy)
Expand All @@ -87,7 +97,7 @@ class PolynomialTests: XCTestCase {
func testDegree4RepeatedRoots() {
// x^4 - 2x^2 + 1
let polynomial = BernsteinPolynomial4(b0: 1, b1: 1, b2: 2.0 / 3.0, b3: 0, b4: 0)
let roots = findRoots(of: polynomial, between: -2, and: 2)
let roots = findDistinctRoots(of: polynomial, between: -2, and: 2)
XCTAssertEqual(roots.count, 2)
XCTAssertEqual(roots[0], -1, accuracy: accuracy)
XCTAssertEqual(roots[1], 1, accuracy: accuracy)
Expand All @@ -97,16 +107,15 @@ class PolynomialTests: XCTestCase {
// 0.2x^5 - 0.813333x^3 - 8.56x
let polynomial = BernsteinPolynomial5(b0: 0, b1: -1.712, b2: -3.424, b3: -5.2173333, b4: -7.1733332, b5: -9.173333)
XCTAssertEqual(polynomial.coefficients, [0, -1.712, -3.424, -5.2173333, -7.1733332, -9.173333])
let roots = findRoots(of: polynomial, between: -4, and: 4)
XCTAssertEqual(polynomial.analyticalRoots(between: -5, and: 5), nil, "shouldn't be possible to solve analytically")
let roots = findDistinctRoots(of: polynomial, between: -4, and: 4)
XCTAssertEqual(roots[0], -2.9806382, accuracy: accuracy)
XCTAssertEqual(roots[1], 0, accuracy: accuracy)
XCTAssertEqual(roots[2], 2.9806382, accuracy: accuracy)
}

func testDegree4RealWorldIssue() {
let polynomial = BernsteinPolynomial4(b0: 1819945.4373168945, b1: -3353335.8194732666, b2: 3712712.6330566406, b3: -2836657.1703338623, b4: 2483314.5947265625)
let roots = findRoots(of: polynomial, between: 0, and: 1)
let roots = findDistinctRootsInUnitInterval(of: polynomial)
XCTAssertEqual(roots.count, 2)
XCTAssertEqual(roots[0], 0.15977874432923783, accuracy: 1.0e-5)
XCTAssertEqual(roots[1], 0.407811682610126, accuracy: 1.0e-5)
Expand Down
2 changes: 0 additions & 2 deletions BezierKit/BezierKitTests/QuadraticCurveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class QuadraticCurveTests: XCTestCase {
// func testLength() {
// }
//
// func testExtrema() {
// }

func testProject() {
let epsilon: CGFloat = 1.0e-5
Expand Down

0 comments on commit 70b38d1

Please sign in to comment.