1 ! Copyright (C) 2010 Slava Pestov.
2 USING: accessors combinators fry kernel locals math.vectors
3 namespaces sets sequences game.models.half-edge euler.b-rep
7 : (polygon>double-face) ( polygon -- edge )
8 [ first2 make-vefs ] keep
9 [ drop opposite-edge>> ] [ 2 tail-slice [ make-ev-one ] each ] 2bi
12 SYMBOLS: smooth-smooth
21 : polygon>double-face ( polygon mode -- edge )
22 ! This only handles the simple case with no repeating vertices
24 dup all-unique? [ "polygon>double-face doesn't support repeating vertices yet" throw ] unless
25 (polygon>double-face) ;
27 :: extrude-simple ( edge dist sharp? -- edge )
28 edge face-normal dist v*n :> vec
29 edge vertex-pos vec v+ :> pos
30 edge pos make-ev-one :> e0!
31 e0 opposite-edge>> :> e-end
32 edge face-ccw :> edge!
34 [ edge e-end eq? not ] [
35 edge vertex-pos vec v+ :> pos
36 edge pos make-ev-one :> e1
42 e-end face-ccw :> e-end
47 : check-bridge-rings ( e1 e2 -- )
49 [ [ face>> assert-no-rings ] bi@ ]
50 [ [ face>> assert-base-face ] bi@ ]
51 [ assert-different-faces ]
52 [ [ face-sides ] bi@ assert= ]
55 :: bridge-rings-simple ( e1 e2 sharp? -- edge )
56 e1 e2 check-bridge-rings
58 e1 e2 make-e-kill-r face-cw :> ea!
61 ea eb make-ef opposite-edge>> face-cw ea!
66 :: project-pt-line ( p p0 p1 -- q )
72 :: project-pt-plane ( line-p0 line-vt plane-n plane-d -- q )
73 plane-d neg plane-n line-p0 v. -
75 line-vt n*v line-p0 v+ ; inline
77 : project-poly-plane ( poly vdir plane-n plane-d -- qoly )
78 '[ _ _ _ project-pt-plane ] map ; inline