Skip to content

Commit

Permalink
Begin extracting redactions module
Browse files Browse the repository at this point in the history
  • Loading branch information
Arclite committed May 9, 2024
1 parent 3b803ee commit bb7e22a
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 57 deletions.
19 changes: 19 additions & 0 deletions Modules/Capabilities/Redactions/Sources/GeometryExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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
}
}
20 changes: 20 additions & 0 deletions Modules/Capabilities/Redactions/Sources/Redaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Created by Geoff Pado on 5/6/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.

public struct Redaction: Equatable {
public let color: RedactionColor
public let parts: [RedactionPart]

init(color: RedactionColor, parts: [RedactionPart]) {
self.color = color
self.parts = parts.filter { part in
if case .shape(let shape) = part {
return shape.isNotEmpty
} else { return true }
}
}

public var paths: [RedactionPath] {
parts.map(\.path)
}
}
14 changes: 14 additions & 0 deletions Modules/Capabilities/Redactions/Sources/RedactionDefinitions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Created by Geoff Pado on 5/8/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit

public typealias RedactionColor = NSColor
public typealias RedactionPath = NSBezierPath
#elseif canImport(UIKit)
import UIKit

public typealias RedactionColor = UIColor
public typealias RedactionPath = UIBezierPath
#endif
14 changes: 14 additions & 0 deletions Modules/Capabilities/Redactions/Sources/RedactionPart.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Created by Geoff Pado on 5/8/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

public enum RedactionPart: Equatable {
case path(RedactionPath)
case shape(Shape)

var path: RedactionPath {
switch self {
case .path(let path): return path
case .shape(let shape): return RedactionPath(cgPath: shape.path)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Created by Geoff Pado on 2/4/23.
// Copyright © 2023 Cocoatype, LLC. All rights reserved.

import Foundation
import CoreGraphics
import Foundation

public struct Shape: Hashable {
let bottomLeft: CGPoint
let bottomRight: CGPoint
let topLeft: CGPoint
let topRight: CGPoint
public let bottomLeft: CGPoint
public let bottomRight: CGPoint
public let topLeft: CGPoint
public let topRight: CGPoint

internal init(bottomLeft: CGPoint, bottomRight: CGPoint, topLeft: CGPoint, topRight: CGPoint) {
self.bottomLeft = bottomLeft
Expand Down Expand Up @@ -114,3 +114,10 @@ public struct Shape: Hashable {
return abs(area) > 0.01
}
}

extension CGPoint: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(x)
hasher.combine(y)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// file intentionally left blank
1 change: 1 addition & 0 deletions Modules/Legacy/Editing/Sources/BrushStampFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright © 2020 Cocoatype, LLC. All rights reserved.

import ErrorHandling
import Redactions
import UIKit

public class BrushStampFactory: NSObject {
Expand Down
45 changes: 0 additions & 45 deletions Modules/Legacy/Editing/Sources/Redactions/Redaction.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ import AppKit
import UIKit
#endif

import Redactions

struct CharacterObservation: Hashable {
let bounds: Shape
let textObservationUUID: UUID
}

extension CGPoint: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(x)
hasher.combine(y)
}
}
2 changes: 2 additions & 0 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let project = Project(
Logging.target,
Receipts.target,
Redacting.target,
Redactions.target,
TestHelpers.target,
// tests
AppRatings.testTarget,
Expand All @@ -51,6 +52,7 @@ let project = Project(
Editing.testTarget,
ErrorHandling.testTarget,
Logging.testTarget,
Redactions.testTarget,
],
schemes: [
.scheme(
Expand Down
1 change: 1 addition & 0 deletions Tuist/ProjectDescriptionHelpers/Targets/Editing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum Editing {
dependencies: [
.target(AutoRedactionsUI.target),
.target(ErrorHandling.target),
.target(Redactions.target),
.package(product: "ClippingBezier", type: .runtime),
.package(product: "Introspect", type: .runtime),
],
Expand Down
7 changes: 7 additions & 0 deletions Tuist/ProjectDescriptionHelpers/Targets/Redactions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ProjectDescription

public enum Redactions {
public static let target = Target.capabilitiesTarget(name: "Redactions")

public static let testTarget = Target.capabilitiesTestTarget(name: "Redactions")
}

0 comments on commit bb7e22a

Please sign in to comment.