soegaard/metapict

Coordinate system

Closed this issue · 7 comments

The coordinate system is a little cumbersome: it requires both the size of the picture and some additional offsetting via a window.

Wouldn't it be possible, using picts, to get rid at least of the window (if not of the picture size) and center the picture?

No specific use case right now, but I'm likely to have several use cases in the near future (for writing papers and making presentations).

I understand the use of the two coordinates systems (and it is indeed useful), but you should be able to avoid having to specify the dimensions of the frame and of the window by hand. Just center everything automatically and adapt the bounding box to capture everything.

Sorry - by use case, I meant a concrete MetaPict example.

But I think I got it now. When drawing nodes it is cumbersome to keep track of the size of the entire diagram. Automatically scaling the resulting image makes sense.

Automatic scaling is not always what you want - if you draw pdfs, then (cm 1) needs to produce
something of length 1cm.

But I have an idea. Maybe I can determine the final bounding box and crop the image to fit snugly around the diagram. I.e. interpret the curve-pict-size as the maximum window.

Would that fit your workflow?

The function crop/inked from "crop.rkt" was added to solve this problem.

Thanks!
Example extracted from crop.rkt:

#lang racket

(require pict
         metapict/crop)
(crop/inked (disk 20 #:border-width 20))
(pict-width (crop/inked (disk 20 #:border-width 20)))
(crop/inked (frame (crop/inked (cc-superimpose (blank 100 100) (circle 10)))))
(newline)
(crop/inked (frame (cc-superimpose (blank 100 100) (circle 10))))
(newline)
(crop/inked (frame (crop/inked (circle 100))))

(require (only-in metapict aligned smoothed unsmoothed))
(pict-width (crop/inked (aligned    (disk 20 #:border-width 20))))
(pict-width (crop/inked (smoothed   (disk 20 #:border-width 20))))
(pict-width (crop/inked (unsmoothed (disk 20 #:border-width 20))))
 

Or do you have a better example?