|
|
|
@ -57,17 +57,17 @@
|
|
|
|
|
[(or 'bi 'bo 'baseline-in 'baseline-out) (vertical-baseline-offset q)]
|
|
|
|
|
[_ 0])))))
|
|
|
|
|
|
|
|
|
|
(define (at-point q)
|
|
|
|
|
;; calculate absolute location of in-point
|
|
|
|
|
(define (to-point q)
|
|
|
|
|
;; calculate absolute location
|
|
|
|
|
;; based on current origin and point type.
|
|
|
|
|
;; don't include offset, so location is on bounding box
|
|
|
|
|
(anchor->global-point q (quad-at q)))
|
|
|
|
|
(anchor->global-point q (quad-to q)))
|
|
|
|
|
|
|
|
|
|
(define (on-point q)
|
|
|
|
|
;; calculate absolute location of out-point
|
|
|
|
|
(define (from-point q)
|
|
|
|
|
;; calculate absolute location
|
|
|
|
|
;; based on current origin and point type.
|
|
|
|
|
;; don't include offset, so location is on bounding box
|
|
|
|
|
(anchor->global-point q (quad-on q)))
|
|
|
|
|
(anchor->global-point q (quad-from q)))
|
|
|
|
|
|
|
|
|
|
(define (anchor->global-point q anchor)
|
|
|
|
|
;; don't include shift here: it should be baked into origin calculation
|
|
|
|
@ -76,10 +76,10 @@
|
|
|
|
|
(define (position q [ref-src #f])
|
|
|
|
|
;; recursively calculates coordinates for quad & subquads
|
|
|
|
|
(define ref-pt (cond
|
|
|
|
|
[(quad? ref-src) (anchor->global-point ref-src (quad-on q))]
|
|
|
|
|
[(quad? ref-src) (anchor->global-point ref-src (quad-from q))]
|
|
|
|
|
[ref-src] ; for passing explicit points in testing
|
|
|
|
|
[else (pt 0 0)]))
|
|
|
|
|
(define this-origin (pt- ref-pt (at-point q)))
|
|
|
|
|
(define this-origin (pt- ref-pt (to-point q)))
|
|
|
|
|
(define shifted-origin (pt+ this-origin (quad-shift q)))
|
|
|
|
|
;; need to position before recurring, so subquads have accurate reference point
|
|
|
|
|
(define positioned-q (struct-copy quad q
|
|
|
|
@ -94,14 +94,14 @@
|
|
|
|
|
(match elems
|
|
|
|
|
[(? null?) (reverse prev-elems)]
|
|
|
|
|
[(cons (? quad? this-q) rest)
|
|
|
|
|
(define ref-q (if (or (quad-on-parent this-q) (null? prev-elems))
|
|
|
|
|
(define ref-q (if (or (quad-from-parent this-q) (null? prev-elems))
|
|
|
|
|
parent-q
|
|
|
|
|
(car prev-elems)))
|
|
|
|
|
(loop (cons (position this-q ref-q) prev-elems) rest)]
|
|
|
|
|
[(cons x rest) (loop (cons x prev-elems) rest)]))])))
|
|
|
|
|
|
|
|
|
|
(define (distance q)
|
|
|
|
|
(match (pt- (on-point q) (at-point q))
|
|
|
|
|
(match (pt- (from-point q) (to-point q))
|
|
|
|
|
[(list-no-order 0 val) val]
|
|
|
|
|
[(list ∆x ∆y) (sqrt (+ (expt ∆x 2) (expt ∆y 2)))]))
|
|
|
|
|
|
|
|
|
@ -111,14 +111,14 @@
|
|
|
|
|
"origins"
|
|
|
|
|
(define size (pt 10 10))
|
|
|
|
|
(define orig (pt 5 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'nw #:size size) orig)) (pt 5 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'n #:size size) orig)) (pt 0 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'ne #:size size) orig)) (pt -5 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'e #:size size) orig)) (pt -5 0))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'se #:size size) orig)) (pt -5 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 's #:size size) orig)) (pt 0 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'sw #:size size) orig)) (pt 5 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'w #:size size) orig)) (pt 5 0)))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'nw #:size size) orig)) (pt 5 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'n #:size size) orig)) (pt 0 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'ne #:size size) orig)) (pt -5 5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'e #:size size) orig)) (pt -5 0))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'se #:size size) orig)) (pt -5 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 's #:size size) orig)) (pt 0 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'sw #:size size) orig)) (pt 5 -5))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'w #:size size) orig)) (pt 5 0)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
@ -126,43 +126,43 @@
|
|
|
|
|
(define size (pt 10 10))
|
|
|
|
|
(define orig (pt 5 5))
|
|
|
|
|
(define shift (pt 3 3))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'nw #:size size #:shift shift) orig)) (pt+ (pt 5 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'n #:size size #:shift shift) orig)) (pt+ (pt 0 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'ne #:size size #:shift shift) orig)) (pt+ (pt -5 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'e #:size size #:shift shift) orig)) (pt+ (pt -5 0) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'se #:size size #:shift shift) orig)) (pt+ (pt -5 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 's #:size size #:shift shift) orig)) (pt+ (pt 0 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'sw #:size size #:shift shift) orig)) (pt+ (pt 5 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:at 'w #:size size #:shift shift) orig)) (pt+ (pt 5 0) shift)))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'nw #:size size #:shift shift) orig)) (pt+ (pt 5 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'n #:size size #:shift shift) orig)) (pt+ (pt 0 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'ne #:size size #:shift shift) orig)) (pt+ (pt -5 5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'e #:size size #:shift shift) orig)) (pt+ (pt -5 0) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'se #:size size #:shift shift) orig)) (pt+ (pt -5 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 's #:size size #:shift shift) orig)) (pt+ (pt 0 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'sw #:size size #:shift shift) orig)) (pt+ (pt 5 -5) shift))
|
|
|
|
|
(check-equal? (quad-origin (position (q #:to 'w #:size size #:shift shift) orig)) (pt+ (pt 5 0) shift)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"in points"
|
|
|
|
|
(define size '(10 10))
|
|
|
|
|
(define pos '(5 5))
|
|
|
|
|
(check-equal? (at-point (q #:at 'nw #:size size #:origin pos)) (pt 5 5))
|
|
|
|
|
(check-equal? (at-point (q #:at 'n #:size size #:origin pos)) (pt 10 5))
|
|
|
|
|
(check-equal? (at-point (q #:at 'ne #:size size #:origin pos)) (pt 15 5))
|
|
|
|
|
(check-equal? (at-point (q #:at 'w #:size size #:origin pos)) (pt 5 10))
|
|
|
|
|
(check-equal? (at-point (q #:at 'c #:size size #:origin pos)) (pt 10 10))
|
|
|
|
|
(check-equal? (at-point (q #:at 'e #:size size #:origin pos)) (pt 15 10))
|
|
|
|
|
(check-equal? (at-point (q #:at 'sw #:size size #:origin pos)) (pt 5 15))
|
|
|
|
|
(check-equal? (at-point (q #:at 's #:size size #:origin pos)) (pt 10 15))
|
|
|
|
|
(check-equal? (at-point (q #:at 'se #:size size #:origin pos)) (pt 15 15)))
|
|
|
|
|
(check-equal? (to-point (q #:to 'nw #:size size #:origin pos)) (pt 5 5))
|
|
|
|
|
(check-equal? (to-point (q #:to 'n #:size size #:origin pos)) (pt 10 5))
|
|
|
|
|
(check-equal? (to-point (q #:to 'ne #:size size #:origin pos)) (pt 15 5))
|
|
|
|
|
(check-equal? (to-point (q #:to 'w #:size size #:origin pos)) (pt 5 10))
|
|
|
|
|
(check-equal? (to-point (q #:to 'c #:size size #:origin pos)) (pt 10 10))
|
|
|
|
|
(check-equal? (to-point (q #:to 'e #:size size #:origin pos)) (pt 15 10))
|
|
|
|
|
(check-equal? (to-point (q #:to 'sw #:size size #:origin pos)) (pt 5 15))
|
|
|
|
|
(check-equal? (to-point (q #:to 's #:size size #:origin pos)) (pt 10 15))
|
|
|
|
|
(check-equal? (to-point (q #:to 'se #:size size #:origin pos)) (pt 15 15)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"out points"
|
|
|
|
|
(define size (pt 10 10))
|
|
|
|
|
(define pos (pt 5 5))
|
|
|
|
|
(check-equal? (on-point (q #:on 'nw #:size size #:origin pos)) (pt 5 5))
|
|
|
|
|
(check-equal? (on-point (q #:on 'n #:size size #:origin pos)) (pt 10 5))
|
|
|
|
|
(check-equal? (on-point (q #:on 'ne #:size size #:origin pos)) (pt 15 5))
|
|
|
|
|
(check-equal? (on-point (q #:on 'w #:size size #:origin pos)) (pt 5 10))
|
|
|
|
|
(check-equal? (on-point (q #:on 'c #:size size #:origin pos)) (pt 10 10))
|
|
|
|
|
(check-equal? (on-point (q #:on 'e #:size size #:origin pos)) (pt 15 10))
|
|
|
|
|
(check-equal? (on-point (q #:on 'sw #:size size #:origin pos)) (pt 5 15))
|
|
|
|
|
(check-equal? (on-point (q #:on 's #:size size #:origin pos)) (pt 10 15))
|
|
|
|
|
(check-equal? (on-point (q #:on 'se #:size size #:origin pos)) (pt 15 15)))
|
|
|
|
|
(check-equal? (from-point (q #:from 'nw #:size size #:origin pos)) (pt 5 5))
|
|
|
|
|
(check-equal? (from-point (q #:from 'n #:size size #:origin pos)) (pt 10 5))
|
|
|
|
|
(check-equal? (from-point (q #:from 'ne #:size size #:origin pos)) (pt 15 5))
|
|
|
|
|
(check-equal? (from-point (q #:from 'w #:size size #:origin pos)) (pt 5 10))
|
|
|
|
|
(check-equal? (from-point (q #:from 'c #:size size #:origin pos)) (pt 10 10))
|
|
|
|
|
(check-equal? (from-point (q #:from 'e #:size size #:origin pos)) (pt 15 10))
|
|
|
|
|
(check-equal? (from-point (q #:from 'sw #:size size #:origin pos)) (pt 5 15))
|
|
|
|
|
(check-equal? (from-point (q #:from 's #:size size #:origin pos)) (pt 10 15))
|
|
|
|
|
(check-equal? (from-point (q #:from 'se #:size size #:origin pos)) (pt 15 15)))
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|