diff --git a/basis/images/normalization/normalization.factor b/basis/images/normalization/normalization.factor index 6eaca01e15..db68e4bad6 100644 --- a/basis/images/normalization/normalization.factor +++ b/basis/images/normalization/normalization.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types byte-arrays combinators fry grouping images kernel locals math math.vectors -sequences specialized-arrays half-floats ; +sequences specialized-arrays math.floats.half ; FROM: alien.c-types => float ; SPECIALIZED-ARRAY: half SPECIALIZED-ARRAY: float diff --git a/basis/half-floats/authors.txt b/basis/math/floats/half/authors.txt similarity index 100% rename from basis/half-floats/authors.txt rename to basis/math/floats/half/authors.txt diff --git a/basis/half-floats/half-floats-tests.factor b/basis/math/floats/half/half-tests.factor similarity index 93% rename from basis/half-floats/half-floats-tests.factor rename to basis/math/floats/half/half-tests.factor index d6b26cb129..82db3d195b 100644 --- a/basis/half-floats/half-floats-tests.factor +++ b/basis/math/floats/half/half-tests.factor @@ -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 ; SPECIALIZED-ARRAY: half -IN: half-floats.tests +IN: math.floats.half.tests [ HEX: 0000 ] [ 0.0 half>bits ] unit-test [ HEX: 8000 ] [ -0.0 half>bits ] unit-test diff --git a/basis/half-floats/half-floats.factor b/basis/math/floats/half/half.factor similarity index 98% rename from basis/half-floats/half-floats.factor rename to basis/math/floats/half/half.factor index 4c84bb81cc..ffa3550452 100644 --- a/basis/half-floats/half-floats.factor +++ b/basis/math/floats/half/half.factor @@ -2,7 +2,7 @@ USING: accessors alien.accessors alien.c-types alien.data alien.syntax kernel math math.order ; FROM: math => float ; -IN: half-floats +IN: math.floats.half : half>bits ( float -- bits ) float>bits diff --git a/basis/half-floats/summary.txt b/basis/math/floats/half/summary.txt similarity index 100% rename from basis/half-floats/summary.txt rename to basis/math/floats/half/summary.txt diff --git a/build-support/factor.sh b/build-support/factor.sh index d8b547d8d6..9da4ae295a 100755 --- a/build-support/factor.sh +++ b/build-support/factor.sh @@ -195,8 +195,9 @@ find_architecture() { } write_test_program() { - $ECHO "#include " > $C_WORD.c - $ECHO "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c + #! Must be 'echo' + echo "#include " > $C_WORD.c + echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c } c_find_word_size() { diff --git a/extra/game/models/half-edge/authors.txt b/extra/game/models/half-edge/authors.txt new file mode 100644 index 0000000000..f13c9c1e77 --- /dev/null +++ b/extra/game/models/half-edge/authors.txt @@ -0,0 +1 @@ +Joe Groff diff --git a/extra/game/models/half-edge/half-edge-tests.factor b/extra/game/models/half-edge/half-edge-tests.factor new file mode 100644 index 0000000000..cbfe514d7e --- /dev/null +++ b/extra/game/models/half-edge/half-edge-tests.factor @@ -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 diff --git a/extra/game/models/half-edge/half-edge.factor b/extra/game/models/half-edge/half-edge.factor new file mode 100644 index 0000000000..eeb3e6116f --- /dev/null +++ b/extra/game/models/half-edge/half-edge.factor @@ -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) ; + diff --git a/extra/game/models/half-edge/summary.txt b/extra/game/models/half-edge/summary.txt new file mode 100644 index 0000000000..6f0aac5c4a --- /dev/null +++ b/extra/game/models/half-edge/summary.txt @@ -0,0 +1 @@ +Iterators for half-edge geometry structures diff --git a/extra/gpu/render/render.factor b/extra/gpu/render/render.factor index 6e66832a2f..d1cb0357ed 100755 --- a/extra/gpu/render/render.factor +++ b/extra/gpu/render/render.factor @@ -4,7 +4,7 @@ assocs classes classes.mixin classes.parser classes.singleton classes.struct classes.tuple classes.tuple.private combinators combinators.tuple destructors fry generic generic.parser gpu gpu.buffers gpu.framebuffers 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 opengl.gl parser quotations sequences slots sorting specialized-arrays strings ui.gadgets.worlds variants diff --git a/extra/gpu/shaders/shaders.factor b/extra/gpu/shaders/shaders.factor index 8a2931e431..d1c137128a 100755 --- a/extra/gpu/shaders/shaders.factor +++ b/extra/gpu/shaders/shaders.factor @@ -8,7 +8,7 @@ kernel lexer literals locals math math.parser memoize multiline namespaces opengl opengl.gl opengl.shaders parser quotations sequences specialized-arrays splitting strings tr ui.gadgets.worlds 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 SPECIALIZED-ARRAY: int SPECIALIZED-ARRAY: void*