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