racket/collects/plot/plot3d/shape.rkt
Neil Toronto 6b39863f1c Source reorg
Added non-rendering plot elements
Optimizations
2011-11-10 12:59:41 -07:00

37 lines
1.2 KiB
Racket

#lang racket/base
(require racket/match
"../common/math.rkt")
(provide (all-defined-out))
(struct shape (alpha center) #:transparent)
(struct polygon shape (vs pen-color pen-width pen-style brush-color brush-style) #:transparent)
(struct line shape (v1 v2 pen-color pen-width pen-style) #:transparent)
(struct text shape (anchor angle str font-size font-family color) #:transparent)
(struct glyph shape (symbol size pen-color pen-width pen-style brush-color brush-style) #:transparent)
(struct tick-glyph shape (radius angle pen-color pen-width pen-style) #:transparent)
(struct shapes shape (list) #:transparent)
(define (shape-normal s)
(cond [(polygon? s) (vnormal (polygon-vs s))]
[else (vector 0 -1 0)]))
(define (shape-coords s)
(cond [(polygon? s) (polygon-vs s)]
[(line? s) (list (line-v1 s) (line-v2 s))]
[else (list (shape-center s))]))
(define (draw-before? s1 s2)
(match-define (vector x1 y1 z1) (shape-center s1))
(match-define (vector x2 y2 z2) (shape-center s2))
(or (y1 . > . y2)
(and (y1 . = . y2)
(if (z1 . = . z2)
(and (polygon? s1) (not (polygon? s2)))
(z1 . < . z2)))))
(define (depth-sort shapes)
(sort shapes draw-before?))