math.trig: use deg>rad in a few places to reduce duplication.

char-rename
John Benediktsson 2016-11-10 10:17:22 -08:00
parent 3641defa66
commit ac04040edc
5 changed files with 19 additions and 34 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license
USING: accessors colors colors.lab colors.luv colors.xyz kernel
locals math math.constants math.functions math.libm ;
locals math math.functions math.libm math.trig ;
IN: colors.lch
@ -10,16 +10,6 @@ TUPLE: LCHuv l c h alpha ;
C: <LCHuv> LCHuv
<PRIVATE
: deg>rad ( degrees -- radians )
pi * 180 / ; inline
: rad>deg ( radians -- degrees )
180 * pi / ; inline
PRIVATE>
M: LCHuv >rgba >luva >rgba ;
M: LCHuv >xyza >luva >xyza ;

View File

@ -1,9 +1,9 @@
! Copyright (C) 2010 Erik Charlebois
! See http://factorcode.org/license.txt for BSD license.
USING: accessors colors.constants game.loop game.worlds gpu
gpu.framebuffers gpu.util.wasd game.debug kernel literals locals
make math math.constants math.matrices math.parser sequences
alien.c-types specialized-arrays ui.gadgets.worlds ui.pixel-formats ;
USING: accessors colors.constants game.debug game.loop
game.worlds gpu gpu.framebuffers gpu.util.wasd kernel literals
locals make math math.matrices math.parser math.trig sequences
specialized-arrays ui.gadgets.worlds ui.pixel-formats ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
IN: game.debug.tests
@ -13,9 +13,6 @@ IN: game.debug.tests
{ default-attachment color }
} clear-framebuffer ;
: deg>rad ( d -- r )
180 / pi * ;
:: draw-debug-tests ( world -- )
world [ wasd-p-matrix ] [ wasd-mv-matrix ] bi m. :> mvp-matrix
{ 0 0 0 } clear-screen

View File

@ -1,6 +1,6 @@
! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel math math.constants math.functions
USING: arrays kernel math math.functions math.trig
math.vectors sequences ;
IN: rosetta-code.haversine-formula
@ -27,7 +27,7 @@ CONSTANT: R_earth 6372.8 ! in kilometers
: haversininv ( y -- x ) 2 * 1 swap - acos ;
: haversineDist ( as bs -- d )
[ [ 180 / pi * ] map ] bi@
[ [ deg>rad ] map ] bi@
[ [ swap - haversin ] 2map ]
[ [ first cos ] bi@ * 1 swap 2array ]
2bi

View File

@ -1,7 +1,10 @@
! (c)2009 Joe Groff, see BSD license
USING: accessors arrays assocs fry kernel math math.affine-transforms math.constants
math.functions math.parser math.vectors memoize peg.ebnf sequences sequences.squish
splitting strings xml.data xml.syntax ;
USING: accessors arrays assocs fry kernel math
math.affine-transforms math.functions math.parser math.trig
peg.ebnf sequences sequences.squish splitting strings xml.data
xml.syntax ;
IN: svg
XML-NS: svg-name http://www.w3.org/2000/svg
@ -14,8 +17,6 @@ XML-NS: inkscape-name http://www.inkscape.org/namespaces/inkscape
[ string>number ] [ [ string>number 10^ ] [ 1 ] if* ] bi* *
>float ;
: degrees ( deg -- rad ) pi * 180.0 / ;
EBNF: svg-transform>affine-transform
transforms =
@ -45,13 +46,13 @@ scale =
=> [[ sx sy sx or <scale> ]]
rotate =
"rotate" wsp* "(" wsp* number:a ( comma-wsp number:cx comma-wsp number:cy => [[ cx cy 2array ]])?:c wsp* ")"
=> [[ a degrees <rotation> c [ center-rotation ] when* ]]
=> [[ a deg>rad <rotation> c [ center-rotation ] when* ]]
skewX =
"skewX" wsp* "(" wsp* number:a wsp* ")"
=> [[ { 1.0 0.0 } a degrees tan 1.0 2array { 0.0 0.0 } <affine-transform> ]]
=> [[ { 1.0 0.0 } a deg>rad tan 1.0 2array { 0.0 0.0 } <affine-transform> ]]
skewY =
"skewY" wsp* "(" wsp* number:a wsp* ")"
=> [[ 1.0 a degrees tan 2array { 0.0 1.0 } { 0.0 0.0 } <affine-transform> ]]
=> [[ 1.0 a deg>rad tan 2array { 0.0 1.0 } { 0.0 0.0 } <affine-transform> ]]
number =
sign? (floating-point-constant | integer-constant) => [[ squish-strings svg-string>number ]]
comma-wsp =

View File

@ -1,7 +1,7 @@
! (c)2009 Joe Groff, Doug Coleman. bsd license
USING: accessors arrays combinators game.input game.loop
game.input.scancodes grouping kernel literals locals
math math.constants math.functions math.order
math math.constants math.functions math.order math.trig
math.vectors opengl opengl.capabilities opengl.gl
opengl.shaders opengl.textures opengl.textures.private
sequences sequences.product specialized-arrays
@ -69,12 +69,9 @@ TUPLE: terrain-world < game-world
[ yaw>> 0.0 1.0 0.0 glRotatef ]
[ location>> vneg first3 glTranslatef ] tri ;
: degrees ( deg -- rad )
pi 180.0 / * ; inline
TYPED: eye-rotate ( yaw: float pitch: float v: float-4 -- v': float-4 )
[ float-4{ 0.0 -1.0 0.0 0.0 } swap degrees rotation-matrix4 ]
[ float-4{ -1.0 0.0 0.0 0.0 } swap degrees rotation-matrix4 m4. ]
[ float-4{ 0.0 -1.0 0.0 0.0 } swap deg>rad rotation-matrix4 ]
[ float-4{ -1.0 0.0 0.0 0.0 } swap deg>rad rotation-matrix4 m4. ]
[ m4.v ] tri* float-4{ t t t f } vand ;
: forward-vector ( player -- v )