Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions Source/CoreGraphicsPolyfill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,48 @@ import Foundation
return CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY)
}

public func applyWithBlock(_ block: (UnsafePointer<CGPathElement>) -> Void) {
for element in elements {
let cgPathElement: CGPathElement

switch element {
case .moveToPoint(let point):
cgPathElement = CGPathElement(
type: .moveToPoint,
points: (point, CGPoint.zero, CGPoint.zero)
)

case .addLineToPoint(let point):
cgPathElement = CGPathElement(
type: .addLineToPoint,
points: (point, CGPoint.zero, CGPoint.zero)
)

case .addQuadCurveToPoint(let control, let point):
cgPathElement = CGPathElement(
type: .addQuadCurveToPoint,
points: (control, point, CGPoint.zero)
)

case .addCurveToPoint(let control1, let control2, let point):
cgPathElement = CGPathElement(
type: .addCurveToPoint,
points: (control1, control2, point)
)

case .closeSubpath:
cgPathElement = CGPathElement(
type: .closeSubpath,
points: (CGPoint.zero, CGPoint.zero, CGPoint.zero)
)
}

withUnsafePointer(to: cgPathElement) { pointer in
block(pointer)
}
}
}

public func addRect(_ rect: CGRect) {

let newElements: [Element] = [
Expand Down Expand Up @@ -192,18 +234,16 @@ import Foundation
}

public struct CGPathElement {

public var type: CGPathElementType

public var points: (CGPoint, CGPoint, CGPoint)
public var points: [CGPoint]

public init(type: CGPathElementType, points: (CGPoint, CGPoint, CGPoint)) {

self.type = type
self.points = points
self.points = [points.0, points.1, points.2]
}
}

/// Rules for determining which regions are interior to a path.
///
/// When filling a path, regions that a fill rule defines as interior to the path are painted.
Expand Down
2 changes: 1 addition & 1 deletion Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ final class PolyfillTests: XCTestCase {
)

XCTAssertEqual(element.type, .moveToPoint)
XCTAssertEqual(element.points.0, CGPoint(x: 1, y: 2))
XCTAssertEqual(element.points[0], CGPoint(x: 1, y: 2))
}

// MARK: - CGPathElementType Tests
Expand Down