-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish extracting Redactions module after merging Observations
- Loading branch information
Showing
68 changed files
with
270 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Modules/Capabilities/Observations/Sources/Extensions/GeometryExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Created by Geoff Pado on 5/8/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import CoreGraphics | ||
|
||
extension CGPoint { | ||
static func flippedPoint(from point: CGPoint, scaledTo size: CGSize) -> CGPoint { | ||
var scaledPoint = point | ||
|
||
#if canImport(UIKit) | ||
scaledPoint.y = (1.0 - scaledPoint.y) | ||
#endif | ||
|
||
scaledPoint.x *= size.width | ||
scaledPoint.y *= size.height | ||
|
||
return scaledPoint | ||
} | ||
} | ||
|
||
extension CGSize { | ||
static func * (size: CGSize, multiplier: CGFloat) -> CGSize { | ||
return CGSize(width: size.width * multiplier, height: size.height * multiplier) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Sources/Extensions/StringExtensions.swift → ...Sources/Extensions/StringExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Modules/Capabilities/Observations/Sources/Observations/CharacterObservation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Created by Geoff Pado on 5/1/19. | ||
// Copyright © 2019 Cocoatype, LLC. All rights reserved. | ||
|
||
import CoreGraphics | ||
import Foundation | ||
|
||
public struct CharacterObservation: Hashable { | ||
public let bounds: Shape | ||
public let textObservationUUID: UUID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
...rces/Text Detection/WordObservation.swift → ...ources/Observations/WordObservation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Created by Geoff Pado on 10/19/23. | ||
// Copyright © 2023 Cocoatype, LLC. All rights reserved. | ||
|
||
import XCTest | ||
|
||
@testable import Observations | ||
|
||
final class ShapeTests: XCTestCase { | ||
func testIsNotEmptyReturnsFalseForEmptyShape() { | ||
let emptyShape = Shape( | ||
bottomLeft: CGPoint(x: 5, y: 5), | ||
bottomRight: CGPoint(x: 5, y: 5), | ||
topLeft: CGPoint(x: 5, y: 5), | ||
topRight: CGPoint(x: 5, y: 5) | ||
) | ||
|
||
XCTAssertFalse(emptyShape.isNotEmpty) | ||
} | ||
|
||
func testIsNotEmptyReturnsTrueForNonEmptyShape() { | ||
let shape = Shape( | ||
bottomLeft: CGPoint(x: 0, y: 5), | ||
bottomRight: CGPoint(x: 5, y: 5), | ||
topLeft: CGPoint(x: 0, y: 0), | ||
topRight: CGPoint(x: 5, y: 0) | ||
) | ||
|
||
XCTAssertTrue(shape.isNotEmpty) | ||
} | ||
} |
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
Modules/Capabilities/Redactions/Sources/Extensions/NSBezierPathExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Created by Geoff Pado on 5/8/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import Observations | ||
|
||
#if canImport(AppKit) && !targetEnvironment(macCatalyst) | ||
import AppKit | ||
|
||
extension NSBezierPath { | ||
convenience init(cgPath: CGPath) { | ||
self.init() | ||
|
||
cgPath.applyWithBlock { elementPointer in | ||
let element = elementPointer.pointee | ||
|
||
switch element.type { | ||
case .moveToPoint: | ||
let point = element.points.pointee | ||
self.move(to: point) | ||
case .addLineToPoint: | ||
let point = element.points.pointee | ||
self.line(to: point) | ||
case .addQuadCurveToPoint: | ||
break // NSBezierPath does not support | ||
case .addCurveToPoint: | ||
let bufferPointer = UnsafeBufferPointer(start: element.points, count: 3) | ||
let points = Array(bufferPointer) | ||
self.curve(to: points[0], controlPoint1: points[1], controlPoint2: points[2]) | ||
case .closeSubpath: | ||
self.close() | ||
@unknown default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
39 changes: 39 additions & 0 deletions
39
Modules/Capabilities/Redactions/Sources/Extensions/UIBezierPathExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Created by Geoff Pado on 5/8/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
#if canImport(UIKit) | ||
import Observations | ||
import SwiftUI | ||
import UIKit | ||
|
||
extension UIBezierPath { | ||
var shape: Observations.Shape? { | ||
let path = Path(self.cgPath) | ||
var elements = [Path.Element]() | ||
path.forEach { element in | ||
elements.append(element) | ||
} | ||
|
||
let points = elements.compactMap(\.point) | ||
|
||
return Shape( | ||
bottomLeft: points[1], | ||
bottomRight: points[2], | ||
topLeft: points[0], | ||
topRight: points[3] | ||
) | ||
} | ||
} | ||
|
||
private extension Path.Element { | ||
var point: CGPoint? { | ||
switch self { | ||
case .move(let to): return to | ||
case .line(let to): return to | ||
case .quadCurve: return nil | ||
case .curve: return nil | ||
case .closeSubpath: return nil | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.