MCPcopy
hub / github.com/docker/docker-agent / FormatDimensionNote

Function FormatDimensionNote

pkg/chat/image.go:202–219  ·  view source on GitHub ↗

FormatDimensionNote produces a human-readable note describing the resize mapping. This helps the model translate coordinates from the resized image back to the original. Because ResizeImage uses fitDimensions (which preserves aspect ratio), the X and Y scale factors are always equal in practice. If

(r *ImageResizeResult)

Source from the content-addressed store, hash-verified

200// the function is called with a manually constructed ImageResizeResult), we emit
201// separate per-axis factors so that coordinate mapping remains correct.
202func FormatDimensionNote(r *ImageResizeResult) string {
203 if !r.Resized {
204 return ""
205 }
206 scaleX := float64(r.OriginalWidth) / float64(r.Width)
207 scaleY := float64(r.OriginalHeight) / float64(r.Height)
208
209 // Uniform scaling (the normal path): a single factor suffices.
210 const epsilon = 0.01
211 if abs(scaleX-scaleY) < epsilon {
212 return fmt.Sprintf("[Image: original %dx%d, displayed at %dx%d. Multiply coordinates by %.2f to map to original image.]",
213 r.OriginalWidth, r.OriginalHeight, r.Width, r.Height, scaleX)
214 }
215
216 // Non-uniform scaling: provide separate X and Y factors.
217 return fmt.Sprintf("[Image: original %dx%d, displayed at %dx%d. Multiply X coordinates by %.2f and Y coordinates by %.2f to map to original image.]",
218 r.OriginalWidth, r.OriginalHeight, r.Width, r.Height, scaleX, scaleY)
219}
220
221func abs(x float64) float64 {
222 if x < 0 {

Callers 3

readImageFileMethod · 0.92
processFileAttachmentMethod · 0.92
TestFormatDimensionNoteFunction · 0.85

Calls 1

absFunction · 0.70

Tested by 1

TestFormatDimensionNoteFunction · 0.68