renames in bbox

main
Matthew Butterick 6 years ago
parent 1e73c9555b
commit 7549e1fca3

@ -1,44 +1,33 @@
#lang racket/base
(require racket/contract racket/struct)
(provide (struct-out BBox) make-BBox bbox->list)
(struct BBox (minX minY maxX maxY) #:transparent #:mutable)
(define (make-BBox
; The minimum X position in the bounding box
[minX +inf.0]
; The minimum Y position in the bounding box
[minY +inf.0]
; The maxmimum X position in the bounding box
[maxX -inf.0]
; The maxmimum Y position in the bounding box
[maxY -inf.0])
(BBox minX minY maxX maxY))
;; The width of the bounding box
(define/contract (width bb)
(BBox? . -> . number?)
(- (BBox-maxX bb) (BBox-minX bb)))
;; The height of the bounding box
(define/contract (height bb)
(BBox? . -> . number?)
(- (BBox-maxY bb) (BBox-minY bb)))
(define/contract (addPoint bb x y)
(BBox? number? number? . -> . void?)
(set-BBox-minX! bb (min x (BBox-minX bb)))
(set-BBox-minY! bb (min y (BBox-minY bb)))
(set-BBox-maxX! bb (max x (BBox-maxX bb)))
(set-BBox-maxY! bb (max y (BBox-maxY bb))))
(define/contract (copy bb)
(BBox? . -> . BBox?)
(apply make-BBox (bbox->list bb)))
(require racket/struct)
(provide (all-defined-out))
(struct bbox (min-x min-y max-x max-y) #:transparent #:mutable)
(define (+bbox [min-x +inf.0] [min-y +inf.0] [max-x -inf.0] [max-y -inf.0])
(bbox min-x min-y max-x max-y))
(define (bbox-width bb)
(unless (bbox? bb)
(raise-argument-error 'bbox-width "bbox" bb))
(- (bbox-max-x bb) (bbox-min-x bb)))
(define (bbox-height bb)
(unless (bbox? bb)
(raise-argument-error 'bbox-height "bbox" bb))
(- (bbox-max-y bb) (bbox-min-y bb)))
(define (bbox-add-point bb x y)
(unless (bbox? bb)
(raise-argument-error 'bbox-add-point "bbox" bb))
(set-bbox-min-x! bb (min x (bbox-min-x bb)))
(set-bbox-min-y! bb (min y (bbox-min-y bb)))
(set-bbox-max-x! bb (max x (bbox-max-x bb)))
(set-bbox-max-y! bb (max y (bbox-max-y bb))))
(define (bbox-copy bb)
(unless (bbox? bb)
(raise-argument-error 'bbox-copy "bbox" bb))
(apply +bbox (bbox->list bb)))
(define bbox->list struct->list)

@ -154,14 +154,12 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
;; The fonts bounding box, i.e. the box that encloses all glyphs in the font.
(define (bbox this)
(define (font-bbox this)
(define head-table (get-head-table this))
(make-BBox (· head-table xMin) (· head-table yMin) (· head-table xMax) (· head-table yMax)))
(define font-bbox bbox) ; todo: avoid name collision in pitfall/embedded
(+bbox (· head-table xMin) (· head-table yMin) (· head-table xMax) (· head-table yMax)))
(test-module
(check-equal? (bbox->list (bbox f)) '(-161 -236 1193 963)))
(check-equal? (bbox->list (font-bbox f)) '(-161 -236 1193 963)))
(define current-layout-caching (make-parameter #false))

Loading…
Cancel
Save