You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/quad/quad/repl.rkt

36 lines
1.1 KiB
Racket

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

#lang br
(require quad racket/draw pict pict/convert)
(provide (all-defined-out))
(verbose-quad-printing? #t)
(define (quad->pict q)
(match-define (list bbox-x bbox-y) (bounding-box q))
(define scaling-factor 3)
(define stroke-width 0.5)
(unsafe-dc
(λ (dc dx dy)
(send dc scale scaling-factor scaling-factor)
(send dc translate stroke-width stroke-width)
(send dc set-pen
(new pen% [width stroke-width] [color "slategray"]))
(let loop ([q q])
(define args (append (quad-origin q) (quad-size q)))
(send dc draw-rectangle . args)
(map loop (quad-elems q))))
(* scaling-factor (+ bbox-x (* stroke-width 2)))
(* scaling-factor (+ bbox-y (* stroke-width 2)))))
(struct quad-pict quad ()
#:property prop:pict-convertible quad->pict)
(define make-quad (make-quad-constructor quad-pict))
(define q1 (make-quad #:size '(20 20)))
(define q2 (make-quad #:size '(15 15)))
(define p (make-quad #:size '(35 35)
#:elems (list q1)))
;; todo: make these equal
(bounding-box (position p))
(bounding-box p)