Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2010-04-29 01:32:39 -04:00
commit 6ba458896f
12 changed files with 134 additions and 8 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types byte-arrays combinators fry USING: accessors alien.c-types byte-arrays combinators fry
grouping images kernel locals math math.vectors grouping images kernel locals math math.vectors
sequences specialized-arrays half-floats ; sequences specialized-arrays math.floats.half ;
FROM: alien.c-types => float ; FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: half SPECIALIZED-ARRAY: half
SPECIALIZED-ARRAY: float SPECIALIZED-ARRAY: float

View File

@ -1,7 +1,7 @@
USING: accessors alien.c-types alien.syntax half-floats kernel USING: accessors alien.c-types alien.syntax math.floats.half kernel
math tools.test specialized-arrays alien.data classes.struct ; math tools.test specialized-arrays alien.data classes.struct ;
SPECIALIZED-ARRAY: half SPECIALIZED-ARRAY: half
IN: half-floats.tests IN: math.floats.half.tests
[ HEX: 0000 ] [ 0.0 half>bits ] unit-test [ HEX: 0000 ] [ 0.0 half>bits ] unit-test
[ HEX: 8000 ] [ -0.0 half>bits ] unit-test [ HEX: 8000 ] [ -0.0 half>bits ] unit-test

View File

@ -2,7 +2,7 @@
USING: accessors alien.accessors alien.c-types alien.data USING: accessors alien.accessors alien.c-types alien.data
alien.syntax kernel math math.order ; alien.syntax kernel math math.order ;
FROM: math => float ; FROM: math => float ;
IN: half-floats IN: math.floats.half
: half>bits ( float -- bits ) : half>bits ( float -- bits )
float>bits float>bits

View File

@ -195,8 +195,9 @@ find_architecture() {
} }
write_test_program() { write_test_program() {
$ECHO "#include <stdio.h>" > $C_WORD.c #! Must be 'echo'
$ECHO "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c echo "#include <stdio.h>" > $C_WORD.c
echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
} }
c_find_word_size() { c_find_word_size() {

View File

@ -0,0 +1 @@
Joe Groff

View File

@ -0,0 +1,69 @@
USING: accessors game.models.half-edge kernel sequences
tools.test ;
IN: game.models.half-edge.tests
CONSTANT: cube-edges
{
T{ edge { face 0 } { vertex 0 } { opposite-edge 6 } { next-edge 1 } }
T{ edge { face 0 } { vertex 1 } { opposite-edge 19 } { next-edge 2 } }
T{ edge { face 0 } { vertex 3 } { opposite-edge 12 } { next-edge 3 } }
T{ edge { face 0 } { vertex 2 } { opposite-edge 21 } { next-edge 0 } }
T{ edge { face 1 } { vertex 4 } { opposite-edge 10 } { next-edge 5 } }
T{ edge { face 1 } { vertex 5 } { opposite-edge 16 } { next-edge 6 } }
T{ edge { face 1 } { vertex 1 } { opposite-edge 0 } { next-edge 7 } }
T{ edge { face 1 } { vertex 0 } { opposite-edge 20 } { next-edge 4 } }
T{ edge { face 2 } { vertex 6 } { opposite-edge 14 } { next-edge 9 } }
T{ edge { face 2 } { vertex 7 } { opposite-edge 17 } { next-edge 10 } }
T{ edge { face 2 } { vertex 5 } { opposite-edge 4 } { next-edge 11 } }
T{ edge { face 2 } { vertex 4 } { opposite-edge 23 } { next-edge 8 } }
T{ edge { face 3 } { vertex 2 } { opposite-edge 2 } { next-edge 13 } }
T{ edge { face 3 } { vertex 3 } { opposite-edge 22 } { next-edge 14 } }
T{ edge { face 3 } { vertex 7 } { opposite-edge 8 } { next-edge 15 } }
T{ edge { face 3 } { vertex 6 } { opposite-edge 18 } { next-edge 12 } }
T{ edge { face 4 } { vertex 1 } { opposite-edge 5 } { next-edge 17 } }
T{ edge { face 4 } { vertex 5 } { opposite-edge 9 } { next-edge 18 } }
T{ edge { face 4 } { vertex 7 } { opposite-edge 13 } { next-edge 19 } }
T{ edge { face 4 } { vertex 3 } { opposite-edge 1 } { next-edge 16 } }
T{ edge { face 5 } { vertex 4 } { opposite-edge 7 } { next-edge 21 } }
T{ edge { face 5 } { vertex 0 } { opposite-edge 3 } { next-edge 22 } }
T{ edge { face 5 } { vertex 2 } { opposite-edge 15 } { next-edge 23 } }
T{ edge { face 5 } { vertex 6 } { opposite-edge 11 } { next-edge 20 } }
}
: connect-cube-edges ( -- )
cube-edges [
[ cube-edges nth ] change-opposite-edge
[ cube-edges nth ] change-next-edge
drop
] each ;
connect-cube-edges
[ 0 1 ]
[ cube-edges first edge-vertices ] unit-test
[ { 0 0 0 } ]
[ cube-edges first vertex-edges [ vertex>> ] map ] unit-test
[ 3 ]
[ cube-edges first vertex-valence ] unit-test
[ { 0 1 3 2 } ]
[ cube-edges first face-edges [ vertex>> ] map ] unit-test
[ 4 ]
[ cube-edges first face-sides ] unit-test
[ { 1 4 2 } ]
[ cube-edges first vertex-neighbors ] unit-test
[ { 3 5 6 } ]
[ cube-edges first vertex-diagonals ] unit-test
[ { 1 4 3 5 } ]
[ cube-edges first face-neighbors ] unit-test

View File

@ -0,0 +1,54 @@
! (c)2010 Joe Groff bsd license
USING: accessors arrays fry kernel locals math sequences ;
IN: game.models.half-edge
TUPLE: edge < identity-tuple face vertex opposite-edge next-edge ;
: edge-vertices ( edge -- start end )
[ vertex>> ] [ opposite-edge>> vertex>> ] bi ;
! building blocks for edge loop iteration
: (collect) ( in quot iterator -- out )
[ collector ] dip dip >array ; inline
: (reduce) ( in initial quot iterator -- accum )
[ swap ] 2dip call ; inline
: (count) ( in iterator -- count )
[ 0 [ drop 1 + ] ] dip (reduce) ; inline
: edge-loop ( ..a edge quot: ( ..a edge -- ..b ) next-edge-quot: ( ..b edge -- ..a edge' ) -- ..a )
pick '[ _ _ bi dup _ eq? not ] loop drop ; inline
! iterate over related edges
: each-vertex-edge ( ... edge quot: ( ... edge -- ... ) -- ... )
[ opposite-edge>> next-edge>> ] edge-loop ; inline
: each-face-edge ( ... edge quot: ( ... edge -- ... ) -- ... )
[ next-edge>> ] edge-loop ; inline
!
: vertex-edges ( edge -- edges )
[ ] [ each-vertex-edge ] (collect) ;
: vertex-neighbors ( edge -- edges )
[ opposite-edge>> vertex>> ] [ each-vertex-edge ] (collect) ;
: vertex-diagonals ( edge -- edges )
[ next-edge>> opposite-edge>> vertex>> ] [ each-vertex-edge ] (collect) ;
: vertex-valence ( edge -- count )
[ each-vertex-edge ] (count) ;
: face-edges ( edge -- edges )
[ ] [ each-face-edge ] (collect) ;
: face-neighbors ( edge -- edges )
[ opposite-edge>> face>> ] [ each-face-edge ] (collect) ;
: face-sides ( edge -- count )
[ each-face-edge ] (count) ;

View File

@ -0,0 +1 @@
Iterators for half-edge geometry structures

View File

@ -4,7 +4,7 @@ assocs classes classes.mixin classes.parser classes.singleton classes.struct
classes.tuple classes.tuple.private combinators combinators.tuple destructors fry classes.tuple classes.tuple.private combinators combinators.tuple destructors fry
generic generic.parser gpu gpu.buffers gpu.framebuffers generic generic.parser gpu gpu.buffers gpu.framebuffers
gpu.framebuffers.private gpu.shaders gpu.shaders.private gpu.state gpu.framebuffers.private gpu.shaders gpu.shaders.private gpu.state
gpu.textures gpu.textures.private half-floats images kernel gpu.textures gpu.textures.private math.floats.half images kernel
lexer locals math math.order math.parser namespaces opengl lexer locals math math.order math.parser namespaces opengl
opengl.gl parser quotations sequences slots sorting opengl.gl parser quotations sequences slots sorting
specialized-arrays strings ui.gadgets.worlds variants specialized-arrays strings ui.gadgets.worlds variants

View File

@ -8,7 +8,7 @@ kernel lexer literals locals math math.parser memoize multiline namespaces
opengl opengl.gl opengl.shaders parser quotations sequences opengl opengl.gl opengl.shaders parser quotations sequences
specialized-arrays splitting strings tr ui.gadgets.worlds specialized-arrays splitting strings tr ui.gadgets.worlds
variants vectors vocabs vocabs.loader vocabs.parser words variants vectors vocabs vocabs.loader vocabs.parser words
words.constant half-floats typed ; words.constant math.floats.half typed ;
QUALIFIED-WITH: alien.c-types c QUALIFIED-WITH: alien.c-types c
SPECIALIZED-ARRAY: int SPECIALIZED-ARRAY: int
SPECIALIZED-ARRAY: void* SPECIALIZED-ARRAY: void*