Skip to content

Conversation

@mflatt
Copy link
Member

@mflatt mflatt commented Dec 27, 2024

A pict's bounding box does not bound the pixels of the pict's rendered form. That kind of "bounding" box works well for composing pictures, but it's confusing when lines and edges are cut off in a DrRacket interaction. A pict's default conversion to bitmap or SVG form, meanwhile, adds 3 units of padding around a pict to help avoid confusion and edge effects, especially when rendering to Scribble documents (where the passing is compensated by an inset return with the bitmap to preserve alignment). Printing in DrRacket does not convert a pict to a bitmap, but instead wraps it directly in a snip.

This commits adds 3 units of padding around the pict within a snip for its printed form. That padding extends the descent, so baseline alignment still works. Snips don't support horizontal inset, at least not in the same way as Scribble (or potentially other consumers of a pict-to-bitmap conversion), but that seems less important in a value-printing context.

With this change, the output of the following program looks nicer and almost certainly is a better reflection on the programmer's intent:

(require pict)
(hline 10 0)
(rectangle 10 10)

@mflatt
Copy link
Member Author

mflatt commented Dec 27, 2024

It would make sense to make the amount of padding configurable in DrRacket. I didn't implement that here, because I think it would rarely get changed. The amount of space for a pict's bitmap conversion is controlled by a parameter, but I have never considered changing it in any application.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and has added suggestions.

(draw-pict pict rdc
(if (< w 0) aw 0)
(if (< h 0) ah 0))
(+ (if (< w 0) aw 0) pad)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-comparison-to-negative?: This expression is equivalent to calling the negative? predicate.

Suggested change
(+ (if (< w 0) aw 0) pad)
(+ (if (negative? w) aw 0) pad)
Debugging details
Textual replacement
(line-replacement
  #:new-lines '#("                 (+ (if (negative? w) aw 0) pad)")
  #:original-lines '#("                 (+ (if (< w 0) aw 0) pad)")
  #:start-line 421)
Syntactic replacement
(syntax-replacement
  #:introduction-scope #<procedure:do-make-syntax-introducer>
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.15.0.11/pkgs/resyntax/default-recommendations/numeric-shortcuts.rkt:66:2 (negative? w)>
  #:original-syntax
    #<syntax:drracket/drracket/private/language.rkt:421:24 (< w 0)>
  #:source
    (file-source
     #<path:/home/runner/work/drracket/drracket/drracket/drracket/private/language.rkt>))

(if (< w 0) aw 0)
(if (< h 0) ah 0))
(+ (if (< w 0) aw 0) pad)
(+ (if (< h 0) ah 0) pad))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-comparison-to-negative?: This expression is equivalent to calling the negative? predicate.

Suggested change
(+ (if (< h 0) ah 0) pad))
(+ (if (negative? h) ah 0) pad))
Debugging details
Textual replacement
(line-replacement
  #:new-lines '#("                 (+ (if (negative? h) ah 0) pad))")
  #:original-lines '#("                 (+ (if (< h 0) ah 0) pad))")
  #:start-line 422)
Syntactic replacement
(syntax-replacement
  #:introduction-scope #<procedure:do-make-syntax-introducer>
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.15.0.11/pkgs/resyntax/default-recommendations/numeric-shortcuts.rkt:66:2 (negative? h)>
  #:original-syntax
    #<syntax:drracket/drracket/private/language.rkt:422:24 (< h 0)>
  #:source
    (file-source
     #<path:/home/runner/work/drracket/drracket/drracket/drracket/private/language.rkt>))

A pict's bounding box does not bound the pixels of the pict's rendered
form. That kind of "bounding" box works well for composing pictures,
but it's confusing when lines and edges are cut off in a DrRacket
interaction. A pict's default conversion to bitmap or SVG form,
meanwhile, adds 3 units of padding around a pict to help avoid
confusion and edge effects, especially when rendering to Scribble
documents (where the passing is compensated by an inset return with
the bitmap to preserve alignment). Printing in DrRacket does not
convert a pict to a bitmap, but instead wraps it directly in a snip.

This commits adds the same padding around the pict within a snip for
its printed form. That padding extends the descent, so baseline
alignment still works. Snips don't support horizontal inset, at least
not in the same way as Scribble (or potentially other consumers of a
pict-to-bitmap conversion), but that seems less important in a
value-printing context.

With this change, the output of the following program looks nicer and
almost certainly is a better reflection on the programmer's intent:

```
(require pict)
(hline 10 0)
(rectangle 10 10)
```
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and has added suggestions.

(draw-pict pict rdc
(if (< w 0) aw 0)
(if (< h 0) ah 0))
(+ (if (< w 0) aw 0) l-pad)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-comparison-to-negative?: This expression is equivalent to calling the negative? predicate.

Suggested change
(+ (if (< w 0) aw 0) l-pad)
(+ (if (negative? w) aw 0) l-pad)
Debugging details
Textual replacement
(line-replacement
  #:new-lines '#("                 (+ (if (negative? w) aw 0) l-pad)")
  #:original-lines '#("                 (+ (if (< w 0) aw 0) l-pad)")
  #:start-line 423)
Syntactic replacement
(syntax-replacement
  #:introduction-scope #<procedure:do-make-syntax-introducer>
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.15.0.11/pkgs/resyntax/default-recommendations/numeric-shortcuts.rkt:66:2 (negative? w)>
  #:original-syntax
    #<syntax:drracket/drracket/private/language.rkt:423:24 (< w 0)>
  #:source
    (file-source
     #<path:/home/runner/work/drracket/drracket/drracket/drracket/private/language.rkt>))

(if (< w 0) aw 0)
(if (< h 0) ah 0))
(+ (if (< w 0) aw 0) l-pad)
(+ (if (< h 0) ah 0) t-pad))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-comparison-to-negative?: This expression is equivalent to calling the negative? predicate.

Suggested change
(+ (if (< h 0) ah 0) t-pad))
(+ (if (negative? h) ah 0) t-pad))
Debugging details
Textual replacement
(line-replacement
  #:new-lines '#("                 (+ (if (negative? h) ah 0) t-pad))")
  #:original-lines '#("                 (+ (if (< h 0) ah 0) t-pad))")
  #:start-line 424)
Syntactic replacement
(syntax-replacement
  #:introduction-scope #<procedure:do-make-syntax-introducer>
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.15.0.11/pkgs/resyntax/default-recommendations/numeric-shortcuts.rkt:66:2 (negative? h)>
  #:original-syntax
    #<syntax:drracket/drracket/private/language.rkt:424:24 (< h 0)>
  #:source
    (file-source
     #<path:/home/runner/work/drracket/drracket/drracket/drracket/private/language.rkt>))

@rfindler rfindler merged commit 928972a into racket:master Dec 27, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants