]> gitweb.factorcode.org Git - factor.git/commitdiff
math.trig: use deg>rad in a few places to reduce duplication.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 10 Nov 2016 18:17:22 +0000 (10:17 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 10 Nov 2016 18:17:22 +0000 (10:17 -0800)
extra/colors/lch/lch.factor
extra/game/debug/tests/tests.factor
extra/rosetta-code/haversine-formula/haversine-formula.factor
extra/svg/svg.factor
extra/terrain/terrain.factor

index d09e1fb213509ccc397e3c9ad86d5efe44b8befc..bdfe54bd796f2d9d0e6488e6f263f81717851995 100644 (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 ;
index 2bc2f3e708d054fb71e1b1eb8be87bd7f90e204c..818b4045347cfbe9e0df94c16111f3c9cd89b849 100644 (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
index 2af50fa60b937a95db9a9f0bca866e8648e457c5..9f887ad5b5130f71e32d761d9ef888e283306d50 100644 (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
index 318c0de8563ea54a9ee8aae5ba461caef471551f..51bf7a9668959a40ea652fd57dc84df79a0a8686 100644 (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 =
index dfc5ffb417a54b2f53783a483b5b2b18d9222486..1b7f0f942e1fb0cb17c5fa98749be420079093de 100644 (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 )