Refactor: extract thumbnail aspect-fit math into ThumbnailGeometry#10
Merged
Merged
Conversation
CaptureManager.saveJPEGThumbnail computed the scaled thumbnail size inline (min-of-ratios, clamped to 1.0, guarded for non-positive input). Move that into a pure ThumbnailGeometry.fittedSize(for:maxDimension:) so the rule is testable without AppKit drawing. Behavior-preserving. Adds ThumbnailGeometryTests (6 cases).
GamalAnwar
pushed a commit
that referenced
this pull request
Jun 18, 2026
… NSImage.encoded EditorView.writeImageSync chose PNG vs JPEG-0.9 by file extension and inlined both encoders; the JPEG branch duplicated CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail duplicated both the JPEG encoder and the thumbnail sizing math (the latter already extracted as ThumbnailGeometry in #10). Add ImageExportFormat (.png / .jpeg(quality), plus .forPath(_:) extension decision) and a single NSImage.encoded(as:) encoder. Rewire all three call sites: EditorView.writeImageSync, CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail (now also using ThumbnailGeometry). Behavior-preserving. Adds ImageExportFormatTests (8 cases) covering the path decision and PNG/JPEG signatures of the encoded data.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
Lift CaptureManager.saveJPEGThumbnail's inline aspect-fit math (min-of-ratios, clamp to 1.0, non-positive guard) into a pure ThumbnailGeometry.fittedSize( for:maxDimension:). Behavior-preserving. Adds ThumbnailGeometryTests (6 cases). CI green.
GamalAnwar
pushed a commit
that referenced
this pull request
Jun 18, 2026
… NSImage.encoded EditorView.writeImageSync chose PNG vs JPEG-0.9 by file extension and inlined both encoders; the JPEG branch duplicated CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail duplicated both the JPEG encoder and the thumbnail sizing math (the latter already extracted as ThumbnailGeometry in #10). Add ImageExportFormat (.png / .jpeg(quality), plus .forPath(_:) extension decision) and a single NSImage.encoded(as:) encoder. Rewire all three call sites: EditorView.writeImageSync, CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail (now also using ThumbnailGeometry). Behavior-preserving. Adds ImageExportFormatTests (8 cases) covering the path decision and PNG/JPEG signatures of the encoded data.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
… NSImage.encoded EditorView.writeImageSync chose PNG vs JPEG-0.9 by file extension and inlined both encoders; the JPEG branch duplicated CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail duplicated both the JPEG encoder and the thumbnail sizing math (the latter already extracted as ThumbnailGeometry in #10). Add ImageExportFormat (.png / .jpeg(quality), plus .forPath(_:) extension decision) and a single NSImage.encoded(as:) encoder. Rewire all three call sites: EditorView.writeImageSync, CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail (now also using ThumbnailGeometry). Behavior-preserving. Adds ImageExportFormatTests (8 cases) covering the path decision and PNG/JPEG signatures of the encoded data.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
Lift CaptureManager.saveJPEGThumbnail's inline aspect-fit math (min-of-ratios, clamp to 1.0, non-positive guard) into a pure ThumbnailGeometry.fittedSize( for:maxDimension:). Behavior-preserving. Adds ThumbnailGeometryTests (6 cases). CI green.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Slice 1 of 2 (the JPEG/thumbnail path).
CaptureManager.saveJPEGThumbnailcomputed the scaled thumbnail size inline — min-of-ratios, clamped to1.0(never upscale), guarded for non-positive input — interleaved with theNSImagedrawing. This lifts the pure geometry into:so the aspect-fit rule is testable without any AppKit drawing. The drawing code stays put and just consumes the computed size.
Scope / safety
min(maxDim/w, maxDim/h, 1.0)math; the non-positive guard now readsguard thumbSize.width > 0(fittedSizereturns.zerofor non-positive input), identical effect to the oldguard w > 0, h > 0.saveJPEGitself (theNSBitmapImageRep→ JPEG encoder shared by full-size save and thumbnail) is unchanged.Tests
ThumbnailGeometryTests(6 cases): landscape fits to width, portrait fits to height, never upscales, aspect ratio preserved + within box, zero/negative →.zero, square scales uniformly.🤖 Generated with Claude Code
Generated by Claude Code