Skip to content

Commit

Permalink
Merge pull request #111 from hfutrell/0.15.0-release
Browse files Browse the repository at this point in the history
0.15.0 release
  • Loading branch information
hfutrell authored Jun 28, 2022
2 parents 72c5240 + 1f4805b commit 11a87c2
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 42 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@ name: BezierKit Mac + Linux
on: [push, pull_request]

jobs:
build:
name: BezierKit on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

Mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Run tests
run: |
swift test --enable-test-discovery --enable-code-coverage
xcrun llvm-cov export -format="lcov" .build/debug/BezierKitPackageTests.xctest/Contents/MacOS/BezierKitPackageTests -instr-profile .build/debug/codecov/default.profdata > info.lcov
- name: code coverage upload to codecov.io
uses: codecov/[email protected]
with:
file: info.lcov
Linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Run tests
run: swift test --enable-test-discovery
run: swift test --enable-test-discovery
2 changes: 1 addition & 1 deletion .github/workflows/wasmBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
name: BezierKit WASM support
runs-on: ubuntu-latest
container: ghcr.io/swiftwasm/carton:0.12.1
container: ghcr.io/swiftwasm/carton:0.16.0

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion BezierKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |s|
s.name = "BezierKit"
s.version = "0.14.0"
s.version = "0.15.0"
s.summary = "comprehensive Bezier Path library written in Swift"
s.homepage = "https://github.com/hfutrell/BezierKit"
s.license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion BezierKit/BezierKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 1320;
LastUpgradeCheck = 1340;
ORGANIZATIONNAME = "Holmes Futrell";
TargetAttributes = {
FD0F54F41DC43FFB0084CDCD = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 4 additions & 2 deletions BezierKit/BezierKitTests/CubicCurveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import XCTest
@testable import BezierKit
#if !os(WASI)

class CubicCurveTests: XCTestCase {

override func setUp() {
Expand Down Expand Up @@ -505,6 +505,8 @@ class CubicCurveTests: XCTestCase {
XCTAssertEqual(c1.intersections(with: c2, accuracy: 1.0e-8), expectedIntersections)
}

// Skip on platforms where CGFloat is 32bit
#if !(arch(i386) || arch(arm) || arch(wasm32))
func testRealWorldNearlyCoincidentCurvesIntersection() {
// these curves are nearly coincident over from c1's t = 0.278 to 1.0
// staying roughly 0.0002 distance of eachother
Expand All @@ -524,6 +526,7 @@ class CubicCurveTests: XCTestCase {
XCTAssertEqual(intersections[1].t1, 1)
XCTAssertEqual(intersections[1].t2, 0)
}
#endif

func testIntersectionsCubicButActuallyLinear() {
// this test presents a challenge for an implicitization based approach
Expand Down Expand Up @@ -655,4 +658,3 @@ class CubicCurveTests: XCTestCase {
XCTAssertNotEqual(c1, c5)
}
}
#endif
4 changes: 0 additions & 4 deletions BezierKit/BezierKitTests/Path+DataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,17 @@ class PathDataTests: XCTestCase {

#endif

#if !os(WASI)
func testEmptyData() {
let path = Path(data: Data())
XCTAssertEqual(path, nil)
}
#endif

let simpleRectangle = {
Path(rect: CGRect(x: 1, y: 2, width: 3, height: 4))
}()

let expectedSimpleRectangleData = Data(base64Encoded: "JbPlSAUAAAAAAQEBAQAAAAAAAPA/AAAAAAAAAEAAAAAAAAAQQAAAAAAAAABAAAAAAAAAEEAAAAAAAAAYQAAAAAAAAPA/AAAAAAAAGEAAAAAAAADwPwAAAAAAAABA")!

#if !os(WASI)
func testSimpleRectangle() {
XCTAssertEqual(simpleRectangle.data, expectedSimpleRectangleData)
}
Expand Down Expand Up @@ -239,5 +236,4 @@ class PathDataTests: XCTestCase {
let corruptData6 = data[0..<10] // commands cut off
XCTAssertEqual(Path(data: corruptData6), nil)
}
#endif
}
3 changes: 2 additions & 1 deletion BezierKit/BezierKitTests/PolynomialTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class PolynomialTests: XCTestCase {
XCTAssertEqual(roots[2], 1, accuracy: accuracy)
XCTAssertEqual(roots[3], 1.2, accuracy: accuracy)
}
#if !os(WASI)
// Skip on platforms where CGFloat is 32bit
#if !(arch(i386) || arch(arm) || arch(wasm32))
func testDegree4RepeatedRoots() {
// x^4 - 2x^2 + 1
let polynomial = BernsteinPolynomial4(b0: 1, b1: 1, b2: 2.0 / 3.0, b3: 0, b4: 0)
Expand Down
3 changes: 3 additions & 0 deletions BezierKit/Library/BezierKit-ObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public extension Path {
@objc(initWithData:) convenience init?(_objc_data: Data) {
self.init(data: _objc_data)
}
@objc(data) var _objc_data: Data {
return data
}
}

// MARK: Path+Projection.swift
Expand Down
28 changes: 20 additions & 8 deletions BezierKit/Library/Path+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2019 Holmes Futrell. All rights reserved.
//

#if !os(WASI)

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
Expand All @@ -24,14 +22,30 @@ fileprivate extension Data {
}
}

fileprivate extension InputStream {
func readNativeValue<T>(_ value: UnsafeMutablePointer<T>) -> Bool {
private struct DataStream {
var dataCursor: Data.Index
let data: Data

init(data: Data) {
self.data = data
self.dataCursor = data.startIndex
}

mutating func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength: Int) -> Int {
let startIndex = dataCursor
let endIndex = min(dataCursor + maxLength, data.count)
data.copyBytes(to: buffer, from: startIndex..<endIndex)
let readBytes = endIndex - startIndex
dataCursor += readBytes
return readBytes
}
mutating func readNativeValue<T>(_ value: UnsafeMutablePointer<T>) -> Bool {
let size = MemoryLayout<T>.size
return value.withMemoryRebound(to: UInt8.self, capacity: size) {
self.read($0, maxLength: size) == size
}
}
func appendNativeValues<T>(to array: inout [T], count: Int) -> Bool {
mutating func appendNativeValues<T>(to array: inout [T], count: Int) -> Bool {
guard count > 0 else { return true }
let size = count * MemoryLayout<T>.stride
let buffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: size)
Expand Down Expand Up @@ -65,8 +79,7 @@ public extension Path {
var commandCount: SerializationTypes.CommandCount = 0
var commands: [SerializationTypes.Command] = []

let stream = InputStream(data: data)
stream.open()
var stream = DataStream(data: data)

// check the magic number
var magic = SerializationTypes.MagicNumber.max
Expand Down Expand Up @@ -148,4 +161,3 @@ public extension Path {
return result
}
}
#endif
8 changes: 5 additions & 3 deletions BezierKit/Library/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal func windingCountImpliesContainment(_ count: Int, using rule: PathFillR
}
}

open class Path: NSObject, NSSecureCoding {
open class Path: NSObject {
/// lock to make external accessing of lazy vars threadsafe
private let lock = UnfairLock()

Expand Down Expand Up @@ -352,7 +352,6 @@ open class Path: NSObject, NSSecureCoding {
return outerComponents.values.map { Path(components: $0) }
}

#if !os(WASI)
public override var hash: Int {
// override is needed because NSObject hashing is independent of Swift's Hashable
return lock.sync {
Expand All @@ -366,9 +365,12 @@ open class Path: NSObject, NSSecureCoding {
return h
}
}
#endif
}

#if !os(WASI)
extension Path: NSSecureCoding {}
#endif

extension Path: Transformable {
public func copy(using t: CGAffineTransform) -> Self {
return type(of: self).init(components: self.components.map { $0.copy(using: t)})
Expand Down
23 changes: 17 additions & 6 deletions BezierKit/Library/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@ internal class Utils {
return atan2(d1.cross(d2), d1.dot(d2))
}

@inline(__always) private static func shouldRecurse<C>(for subcurve: Subcurve<C>, boundingBoxSize: CGPoint, accuracy: CGFloat) -> Bool {
guard subcurve.canSplit else { return false }
guard boundingBoxSize.x + boundingBoxSize.y >= accuracy else { return false }
if MemoryLayout<CGFloat>.size == 4 {
let curve = subcurve.curve
// limit recursion when we exceed Float32 precision
let midPoint = curve.point(at: 0.5)
if midPoint == curve.startingPoint ||
midPoint == curve.endingPoint {
guard curve.selfIntersects else { return false }
}
}
return true
}

// disable this SwiftLint warning about function having more than 5 parameters
// swiftlint:disable function_parameter_count

Expand All @@ -325,12 +340,8 @@ internal class Utils {
guard results.count <= maximumIntersections else { return false }
guard c1b.overlaps(c2b) else { return true }

let canSplit1 = c1.canSplit
let canSplit2 = c2.canSplit
let size1 = c1b.size
let size2 = c2b.size
let shouldRecurse1 = canSplit1 && ((size1.x + size1.y) >= accuracy)
let shouldRecurse2 = canSplit2 && ((size2.x + size2.y) >= accuracy)
let shouldRecurse1 = shouldRecurse(for: c1, boundingBoxSize: c1b.size, accuracy: accuracy)
let shouldRecurse2 = shouldRecurse(for: c2, boundingBoxSize: c2b.size, accuracy: accuracy)

if shouldRecurse1 == false, shouldRecurse2 == false {
// subcurves are small enough or we simply cannot recurse any more
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To integrate BezierKit into your Xcode project using CocoaPods, add it to your t

```ruby
target '<Your Target Name>' do
pod 'BezierKit', '>= 0.14.0'
pod 'BezierKit', '>= 0.15.0'
end
```

Expand All @@ -66,7 +66,7 @@ import PackageDescription
let package = Package(
name: "<Your Target Name>",
dependencies: [
.package(url: "https://github.com/hfutrell/BezierKit.git", from: "0.14.0"),
.package(url: "https://github.com/hfutrell/BezierKit.git", from: "0.15.0"),
]
)
```
Expand Down

0 comments on commit 11a87c2

Please sign in to comment.