From a0b6ab766670b1853012d45a1861463c311e3039 Mon Sep 17 00:00:00 2001 From: shima11 Date: Wed, 13 Mar 2024 19:14:43 +0900 Subject: [PATCH 1/4] update --- Dev/Sources/SwiftUIDemo/DemoCropView2.swift | 5 ++++ .../BrightroomEngine/Core/EditingCrop.swift | 4 +-- .../BrightroomEngine/Library/Geometry.swift | 25 ++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Dev/Sources/SwiftUIDemo/DemoCropView2.swift b/Dev/Sources/SwiftUIDemo/DemoCropView2.swift index fa26f373..b7a86f43 100644 --- a/Dev/Sources/SwiftUIDemo/DemoCropView2.swift +++ b/Dev/Sources/SwiftUIDemo/DemoCropView2.swift @@ -17,6 +17,7 @@ struct DemoCropView2: View { @StateObject var editingStack: EditingStack @State var resultImage: ResultImage? + @State var angle: EditingCrop.AdjustmentAngle = .zero init( editingStack: @escaping () -> EditingStack @@ -52,11 +53,15 @@ struct DemoCropView2: View { .fill(kind == nil ? Color.white : Color.white.opacity(0.6)) } ) + .adjustmentAngle(angle) .frame(height: 500) .clipped() + .background(Color.gray) Spacer() + Slider(value: $angle.degrees, in: -45.0...45.0, step: 1) + } VStack { diff --git a/Sources/BrightroomEngine/Core/EditingCrop.swift b/Sources/BrightroomEngine/Core/EditingCrop.swift index efd142b3..7274a7a6 100644 --- a/Sources/BrightroomEngine/Core/EditingCrop.swift +++ b/Sources/BrightroomEngine/Core/EditingCrop.swift @@ -169,7 +169,7 @@ public struct EditingCrop: Equatable { */ public mutating func updateCropExtent(toFitAspectRatio newAspectRatio: PixelAspectRatio) { - let maxSize = newAspectRatio.sizeThatFitsWithRounding(in: imageSize) + let maxSize = newAspectRatio.sizeThatFits(in: imageSize) let proposed = CGRect( origin: .init( @@ -329,7 +329,7 @@ public struct EditingCrop: Equatable { ) ) - let newRect = aspectRatio.rectThatFitsWithRounding(in: maxRect) + let newRect = aspectRatio.rectThatFits(in: maxRect) fixed = newRect diff --git a/Sources/BrightroomEngine/Library/Geometry.swift b/Sources/BrightroomEngine/Library/Geometry.swift index acdfabcf..332c6ca2 100644 --- a/Sources/BrightroomEngine/Library/Geometry.swift +++ b/Sources/BrightroomEngine/Library/Geometry.swift @@ -179,7 +179,7 @@ public struct PixelAspectRatio: Hashable, CustomReflectable, Identifiable { .init(width: height, height: width) } - public func sizeThatFillRounding(in boundingSize: CGSize) -> CGSize { + public func sizeThatFill(in boundingSize: CGSize) -> CGSize { let widthRatio = boundingSize.width / width let heightRatio = boundingSize.height / height var size = boundingSize @@ -191,12 +191,12 @@ public struct PixelAspectRatio: Hashable, CustomReflectable, Identifiable { } return CGSize( - width: size.width.rounded(.down), - height: size.height.rounded(.down) + width: size.width, + height: size.height ) } - public func sizeThatFitsWithRounding(in boundingSize: CGSize) -> CGSize { + public func sizeThatFits(in boundingSize: CGSize) -> CGSize { let widthRatio = boundingSize.width / width let heightRatio = boundingSize.height / height @@ -209,32 +209,27 @@ public struct PixelAspectRatio: Hashable, CustomReflectable, Identifiable { } return CGSize( - width: size.width.rounded(.down), - height: size.height.rounded(.down) + width: size.width, + height: size.height ) } - public func rectThatFitsWithRounding(in boundingRect: CGRect) -> CGRect { - let size = sizeThatFitsWithRounding(in: boundingRect.size) + public func rectThatFits(in boundingRect: CGRect) -> CGRect { + let size = sizeThatFits(in: boundingRect.size) var origin = boundingRect.origin origin.x += (boundingRect.size.width - size.width) / 2.0 origin.y += (boundingRect.size.height - size.height) / 2.0 - origin.x.round(.down) - origin.y.round(.down) - return CGRect(origin: origin, size: size) } - public func rectThatFillWithRounding(in boundingRect: CGRect) -> CGRect { - let size = sizeThatFillRounding(in: boundingRect.size) + public func rectThatFill(in boundingRect: CGRect) -> CGRect { + let size = sizeThatFill(in: boundingRect.size) var origin = CGPoint.zero origin.x = (boundingRect.size.width - size.width) / 2.0 origin.y = (boundingRect.size.height - size.height) / 2.0 - origin.x.round(.down) - origin.y.round(.down) return CGRect(origin: origin, size: size) } From 57dcfac9e407c0fa5632b23bed4f20d474e62429 Mon Sep 17 00:00:00 2001 From: shima11 Date: Thu, 14 Mar 2024 00:40:53 +0900 Subject: [PATCH 2/4] update --- Sources/BrightroomUI/Shared/Components/Crop/CropView.swift | 4 ++-- .../Shared/Components/Drawing/BlurryMaskingView.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift index 9456dc3a..22e1fa34 100644 --- a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift +++ b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift @@ -699,7 +699,7 @@ extension CropView { let bounds = self.bounds.inset(by: contentInset) let size = PixelAspectRatio(crop.cropExtent.size) - .sizeThatFitsWithRounding(in: bounds.size) + .sizeThatFits(in: bounds.size) return .init( origin: .init( @@ -746,7 +746,7 @@ extension CropView { let bounds = self.bounds.inset(by: contentInset) let size = PixelAspectRatio(crop.cropExtent.size) - .sizeThatFitsWithRounding(in: bounds.size) + .sizeThatFits(in: bounds.size) return .init( origin: .init( diff --git a/Sources/BrightroomUI/Shared/Components/Drawing/BlurryMaskingView.swift b/Sources/BrightroomUI/Shared/Components/Drawing/BlurryMaskingView.swift index 04b50515..a8f05899 100644 --- a/Sources/BrightroomUI/Shared/Components/Drawing/BlurryMaskingView.swift +++ b/Sources/BrightroomUI/Shared/Components/Drawing/BlurryMaskingView.swift @@ -42,7 +42,7 @@ public final class BlurryMaskingView: PixelEditorCodeBasedView, UIScrollViewDele } let aspectRatio = PixelAspectRatio(proposedCrop.cropExtent.size) - let size = aspectRatio.sizeThatFitsWithRounding(in: bounds.size) + let size = aspectRatio.sizeThatFits(in: bounds.size) let (min, _) = proposedCrop.calculateZoomScale(visibleSize: size) From b82de1707d39a3b15a115b795b088000684e0508 Mon Sep 17 00:00:00 2001 From: shima11 Date: Thu, 14 Mar 2024 01:57:02 +0900 Subject: [PATCH 3/4] update --- .../BrightroomEngine/Core/EditingCrop.swift | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/Sources/BrightroomEngine/Core/EditingCrop.swift b/Sources/BrightroomEngine/Core/EditingCrop.swift index 7274a7a6..b9ec8d53 100644 --- a/Sources/BrightroomEngine/Core/EditingCrop.swift +++ b/Sources/BrightroomEngine/Core/EditingCrop.swift @@ -148,8 +148,6 @@ public struct EditingCrop: Equatable { imageSize.width *= scale imageSize.height *= scale - imageSize.width.round(.down) - imageSize.height.round(.down) modified.cropExtent = Self.fittingRect( rect: cropExtent, @@ -260,31 +258,10 @@ public struct EditingCrop: Equatable { var fixed = rect - func containsFractionInCGFloat(_ value: CGFloat) -> Bool { - Int(exactly: value) == nil - } - - func rectIsPixelPerfect(_ rect: CGRect) -> Bool { - guard containsFractionInCGFloat(rect.origin.x) == false else { return false } - guard containsFractionInCGFloat(rect.origin.y) == false else { return false } - guard containsFractionInCGFloat(rect.size.width) == false else { return false } - guard containsFractionInCGFloat(rect.size.height) == false else { return false } - return true - } - func clamp(value: T, lower: T, upper: T) -> T { return min(max(value, lower), upper) } - /* - Drops decimal fraction - */ - - fixed.origin.x.round(.down) - fixed.origin.y.round(.down) - fixed.size.width.round(.down) - fixed.size.height.round(.down) - /* Cuts the area off that out of maximum bounds @@ -347,7 +324,6 @@ public struct EditingCrop: Equatable { assert(fixed.width <= imageSize.width) assert(fixed.height <= imageSize.height) - assert(rectIsPixelPerfect(fixed)) } #if DEBUG From d0493953fbe50b0b76dca2f501fddf60677a4bac Mon Sep 17 00:00:00 2001 From: shima11 Date: Thu, 14 Mar 2024 02:17:45 +0900 Subject: [PATCH 4/4] update --- .../Shared/Components/Crop/CropView.CropInsideOverlay.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/BrightroomUI/Shared/Components/Crop/CropView.CropInsideOverlay.swift b/Sources/BrightroomUI/Shared/Components/Crop/CropView.CropInsideOverlay.swift index e6706db5..03aa88c6 100644 --- a/Sources/BrightroomUI/Shared/Components/Crop/CropView.CropInsideOverlay.swift +++ b/Sources/BrightroomUI/Shared/Components/Crop/CropView.CropInsideOverlay.swift @@ -216,8 +216,8 @@ extension CropView { super.layoutSubviews() - let width = (bounds.width / 3).rounded(.down) - let height = (bounds.height / 3).rounded(.down) + let width = (bounds.width / 3) + let height = (bounds.height / 3) do {