From 6376c1d46fdf997eb3fd1589a675ea7cc8128470 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:15:46 -0700 Subject: [PATCH 01/10] Eff to Effect --- docs/Data/ST/Matrix.md | 24 ++++++++++++------------ docs/Data/ST/Matrix4.md | 14 +++++++------- src/Data/ST/Matrix.purs | 28 ++++++++++++++-------------- src/Data/ST/Matrix4.purs | 20 ++++++++++---------- test/Main.purs | 8 ++++---- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/docs/Data/ST/Matrix.md b/docs/Data/ST/Matrix.md index c8e7bde..f071e5d 100644 --- a/docs/Data/ST/Matrix.md +++ b/docs/Data/ST/Matrix.md @@ -12,13 +12,13 @@ newtype STMat s h a #### `copyImpl` ``` purescript -copyImpl :: forall a b h r. a -> Eff (st :: ST h | r) b +copyImpl :: forall a b h. a -> Effect b ``` #### `freeze` ``` purescript -freeze :: forall a h r. STArray h a -> Eff (st :: ST h | r) (Array a) +freeze :: forall a h. STArray h a -> Effect (Array a) ``` Create an immutable copy of a mutable array. @@ -26,7 +26,7 @@ Create an immutable copy of a mutable array. #### `thaw` ``` purescript -thaw :: forall a h r. Array a -> Eff (st :: ST h | r) (STArray h a) +thaw :: forall a h. Array a -> Effect (STArray h a) ``` Create a mutable copy of an immutable array. @@ -48,55 +48,55 @@ unsafeThaw :: forall a h. Array a -> STArray h a #### `cloneSTMat` ``` purescript -cloneSTMat :: forall s h a r. (STMat s h a) -> Eff (st :: ST h | r) (STMat s h a) +cloneSTMat :: forall s h a. (STMat s h a) -> Effect (STMat s h a) ``` #### `fromSTMat` ``` purescript -fromSTMat :: forall s h a r. Sized s => (STMat s h a) -> Eff (st :: ST h | r) (Mat s a) +fromSTMat :: forall s h a. Sized s => (STMat s h a) -> Effect (Mat s a) ``` #### `toSTMat` ``` purescript -toSTMat :: forall s h a r. (Mat s a) -> Eff (st :: ST h | r) (STMat s h a) +toSTMat :: forall s h a. (Mat s a) -> Effect (STMat s h a) ``` #### `copyToSTMat` ``` purescript -copyToSTMat :: forall s h a r. (Mat s a) -> (STMat s h a) -> Eff (st :: ST h | r) Unit +copyToSTMat :: forall s h a. (Mat s a) -> (STMat s h a) -> Effect Unit ``` #### `identityST'` ``` purescript -identityST' :: forall s h r. Sized s => Eff (st :: ST h | r) (STMat s h Number) +identityST' :: forall s h. Sized s => Effect (STMat s h Number) ``` #### `scaleSTMatrixInt` ``` purescript -scaleSTMatrixInt :: forall a h r. EuclideanRing a => a -> STArray h a -> Eff (st :: ST h | r) Unit +scaleSTMatrixInt :: forall a h. EuclideanRing a => a -> STArray h a -> Effect Unit ``` #### `scaleSTMatrix` ``` purescript -scaleSTMatrix :: forall s a h r. EuclideanRing a => a -> (STMat s h a) -> Eff (st :: ST h | r) (STMat s h a) +scaleSTMatrix :: forall s a h. EuclideanRing a => a -> (STMat s h a) -> Effect (STMat s h a) ``` #### `fromMatrix` ``` purescript -fromMatrix :: forall s h r a. Mat s a -> Eff (st :: ST h | r) (STMat s h a) +fromMatrix :: forall s h a. Mat s a -> Effect (STMat s h a) ``` #### `runSTMatrix` ``` purescript -runSTMatrix :: forall s a r. (forall h. Eff (st :: ST h | r) (STMat s h a)) -> Eff r (Mat s a) +runSTMatrix :: forall s a. (forall h. Effect (STMat s h a)) -> Effect (Mat s a) ``` diff --git a/docs/Data/ST/Matrix4.md b/docs/Data/ST/Matrix4.md index 9309c6e..19169ff 100644 --- a/docs/Data/ST/Matrix4.md +++ b/docs/Data/ST/Matrix4.md @@ -11,43 +11,43 @@ type STMat4 h = STMat Four h Number #### `identityST` ``` purescript -identityST :: forall h r. Eff (st :: ST h | r) (STMat Four h Number) +identityST :: forall h r. Effect (STMat Four h Number) ``` #### `rotateST` ``` purescript -rotateST :: forall h r. Number -> Vec3N -> STMat4 h -> Eff (st :: ST h | r) Unit +rotateST :: forall h r. Number -> Vec3N -> STMat4 h -> Effect Unit ``` #### `rotateSTX` ``` purescript -rotateSTX :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +rotateSTX :: forall h r. Number -> STMat4 h -> Effect Unit ``` #### `rotateSTY` ``` purescript -rotateSTY :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +rotateSTY :: forall h r. Number -> STMat4 h -> Effect Unit ``` #### `rotateSTZ` ``` purescript -rotateSTZ :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +rotateSTZ :: forall h r. Number -> STMat4 h -> Effect Unit ``` #### `translateST` ``` purescript -translateST :: forall h r. Vec3N -> STMat4 h -> Eff (st :: ST h | r) Unit +translateST :: forall h r. Vec3N -> STMat4 h -> Effect Unit ``` #### `scaleST3` ``` purescript -scaleST3 :: forall h r. Number -> Number -> Number -> STMat4 h -> Eff (st :: ST h | r) Unit +scaleST3 :: forall h r. Number -> Number -> Number -> STMat4 h -> Effect Unit ``` diff --git a/src/Data/ST/Matrix.purs b/src/Data/ST/Matrix.purs index 2a9536f..991e636 100644 --- a/src/Data/ST/Matrix.purs +++ b/src/Data/ST/Matrix.purs @@ -15,7 +15,7 @@ module Data.ST.Matrix where import Prelude -import Control.Monad.Eff (Eff) +import Effect (Effect) import Control.Monad.ST (ST()) import Data.TypeNat (class Sized) import Data.Array.ST (STArray) @@ -26,14 +26,14 @@ newtype STMat s h a = STMat (STArray h a) -- try array cloning with .slice() instead of the for-loop -- implementation in Data.Array.ST. Needs benchmarking. -foreign import copyImpl :: forall a b h r. a -> Eff (st :: ST h | r) b +foreign import copyImpl :: forall a b. a -> Effect b -- | Create an immutable copy of a mutable array. -freeze :: forall a h r. STArray h a -> Eff (st :: ST h | r) (Array a) +freeze :: forall a h. STArray h a -> Effect (Array a) freeze = copyImpl -- | Create a mutable copy of an immutable array. -thaw :: forall a h r. Array a -> Eff (st :: ST h | r) (STArray h a) +thaw :: forall a h. Array a -> Effect (STArray h a) thaw = copyImpl -- | Freeze an ST array. Do not mutate the STArray afterwards! @@ -41,32 +41,32 @@ foreign import unsafeFreeze :: forall a h. STArray h a -> Array a foreign import unsafeThaw :: forall a h. Array a -> STArray h a -cloneSTMat :: forall s h a r. (STMat s h a) -> Eff (st :: ST h | r) (STMat s h a) +cloneSTMat :: forall s h a. (STMat s h a) -> Effect (STMat s h a) cloneSTMat (STMat arr) = STMat <<< unsafeThaw <$> freeze arr -fromSTMat :: forall s h a r. (Sized s) => (STMat s h a) -> Eff (st :: ST h | r) (M.Mat s a) +fromSTMat :: forall s h a. (Sized s) => (STMat s h a) -> Effect (M.Mat s a) fromSTMat (STMat arr) = do x <- freeze arr pure (M.fromArray x) -toSTMat :: forall s h a r. (M.Mat s a) -> Eff (st :: ST h | r) (STMat s h a) +toSTMat :: forall s h a. (M.Mat s a) -> Effect (STMat s h a) toSTMat m = STMat <$> thaw (M.toArray m) --- copyToSTMat :: forall s h a r. (M.Matrix (M.Mat s) a) => (M.Mat s a) -> (STMat s h a) -> Eff (st :: ST h | r) Unit +-- copyToSTMat :: forall s h a. (M.Matrix (M.Mat s) a) => (M.Mat s a) -> (STMat s h a) -> Effect Unit -foreign import copyToSTMat :: forall s h a r. (M.Mat s a) -> (STMat s h a) -> Eff (st :: ST h | r) Unit +foreign import copyToSTMat :: forall s h a. (M.Mat s a) -> (STMat s h a) -> Effect Unit -identityST' :: forall s h r. (Sized s) => Eff (st :: ST h | r) (STMat s h Number) +identityST' :: forall s h. (Sized s) => Effect (STMat s h Number) identityST' = let m = M.identity' :: M.Mat s Number in STMat <$> thaw (M.toArray m) -foreign import scaleSTMatrixInt :: forall a h r. (EuclideanRing a) => a -> STArray h a -> Eff (st :: ST h | r) Unit +foreign import scaleSTMatrixInt :: forall a h. (EuclideanRing a) => a -> STArray h a -> Effect Unit -scaleSTMatrix :: forall s a h r. (EuclideanRing a) => a -> (STMat s h a) -> Eff (st :: ST h | r) (STMat s h a) +scaleSTMatrix :: forall s a h. (EuclideanRing a) => a -> (STMat s h a) -> Effect (STMat s h a) scaleSTMatrix x v@(STMat arr) = scaleSTMatrixInt x arr *> pure v -fromMatrix :: forall s h r a. M.Mat s a -> Eff (st :: ST h | r) (STMat s h a) +fromMatrix :: forall s h a. M.Mat s a -> Effect (STMat s h a) fromMatrix (M.Mat m) = STMat <$> thaw m -foreign import runSTMatrix :: forall s a r. (forall h. Eff (st :: ST h | r) (STMat s h a)) -> Eff r (M.Mat s a) +foreign import runSTMatrix :: forall s a. (forall h. Effect (STMat s h a)) -> Effect (M.Mat s a) diff --git a/src/Data/ST/Matrix4.purs b/src/Data/ST/Matrix4.purs index 10d566c..74ea776 100644 --- a/src/Data/ST/Matrix4.purs +++ b/src/Data/ST/Matrix4.purs @@ -18,25 +18,25 @@ import Prelude (Unit) import Data.TypeNat (Four) import Data.Matrix4 (Vec3N()) import Data.ST.Matrix (STMat) -import Control.Monad.Eff (Eff) +import Effect (Effect) import Control.Monad.ST (ST()) type STMat4 h = STMat Four h Number -foreign import identityST :: forall h r. Eff (st :: ST h | r) (STMat Four h Number) +foreign import identityST :: forall h. Effect (STMat Four h Number) -foreign import rotateST :: forall h r. Number -> Vec3N -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import rotateST :: forall h. Number -> Vec3N -> STMat4 h -> Effect Unit -foreign import rotateSTX :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import rotateSTX :: forall h. Number -> STMat4 h -> Effect Unit -foreign import rotateSTY :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import rotateSTY :: forall h. Number -> STMat4 h -> Effect Unit -foreign import rotateSTZ :: forall h r. Number -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import rotateSTZ :: forall h. Number -> STMat4 h -> Effect Unit --- generic type was :: forall h r. Number -> [Number] -> STArray h Number -> Eff (st :: ST h | r) Unit +-- generic type was :: forall h. Number -> [Number] -> STArray h Number -> Effect Unit -foreign import translateST :: forall h r. Vec3N -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import translateST :: forall h. Vec3N -> STMat4 h -> Effect Unit --- generic type was :: forall h r. [Number] -> STArray h Number -> Eff (st :: ST h | r) Unit +-- generic type was :: forall h. [Number] -> STArray h Number -> Effect Unit -foreign import scaleST3 :: forall h r. Number -> Number -> Number -> STMat4 h -> Eff (st :: ST h | r) Unit +foreign import scaleST3 :: forall h. Number -> Number -> Number -> STMat4 h -> Effect Unit diff --git a/test/Main.purs b/test/Main.purs index b67d2d0..6e057e9 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -7,12 +7,12 @@ import Data.ST.Matrix4 (STMat4, translateST, rotateST, identityST) as M import Data.ST.Matrix (runSTMatrix) as M import Data.Vector as V -import Control.Monad.Eff (Eff) +import Effect (Effect) import Control.Monad.ST (ST()) -import Control.Monad.Eff.Console (logShow, CONSOLE) +import Effect.Console (logShow) -ble :: forall h r . Eff (st :: ST h | r) (M.STMat4 h) +ble :: forall h. Effect (M.STMat4 h) -- ble = fromMatrix (M.fromArray [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]) >>= stackPush >>= scaleSTMatrix 2 >>= stackPop -- ble = M.identityST >>= M.scaleSTMatrix 2 ble = M.identityST @@ -26,7 +26,7 @@ ys = M.rotate 90.0 meh $ M.identity zs :: M.Mat4 zs = M.translate meh $ M.identity -main :: forall eff. Eff (console :: CONSOLE | eff) Unit +main :: Effect Unit main = do xs <- M.runSTMatrix (ble >>= \m -> M.rotateST 90.0 meh m *> pure m) From 8b9eecf5ea10300ee04c2eee637615b330160e5e Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:31:17 -0700 Subject: [PATCH 02/10] Replace purescript-extensions fail with unsafeCrashWith. --- bower.json | 4 ---- src/Data/Matrix.purs | 7 +++--- src/Data/Matrix3.purs | 4 ++-- src/Data/Matrix4.purs | 52 +++++++++++++++++++++---------------------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/bower.json b/bower.json index db89421..6b13fc9 100644 --- a/bower.json +++ b/bower.json @@ -28,15 +28,11 @@ "dependencies": { "purescript-vector": "^2.0.0", "purescript-arrays": "^4.2.0", - "purescript-extensions": "^2.2.0", "purescript-proxy": "^2.1.0" }, "devDependencies": { "purescript-assert": "^3.0.0", "purescript-console": "^3.0.0", "purescript-random": "^3.0.0" - }, - "resolutions": { - "purescript-extensions": "^2.2.0" } } diff --git a/src/Data/Matrix.purs b/src/Data/Matrix.purs index 42003df..f2d14bd 100644 --- a/src/Data/Matrix.purs +++ b/src/Data/Matrix.purs @@ -19,8 +19,7 @@ import Data.Array (length, (!!), zipWith, slice, range, concat) import Data.Maybe (fromJust) import Data.TypeNat (class Sized, Four, Three, Two, sized) import Type.Proxy (Proxy(Proxy)) -import Extensions (fail) -import Partial.Unsafe (unsafePartial) +import Partial.Unsafe (unsafePartial, unsafeCrashWith) newtype Mat s a = Mat (Array a) @@ -61,7 +60,7 @@ columns mat@(Mat m) | sized (Proxy :: Proxy s) == 2 = slice 8 12 m, slice 12 16 m] | otherwise = - fail "Matrix>>columns: Proxy size not supprted!" + unsafeCrashWith "Matrix>>columns: Proxy size not supprted!" instance eqMat :: (Eq a) => Eq (Mat s a) where eq (Mat l) (Mat r) = l == r @@ -107,7 +106,7 @@ fromArray l = let size = sized (Proxy :: Proxy s) in case size * size of i | i == length l -> Mat l - | otherwise -> fail "Matrix>>fromArray: Wrong array length!" + | otherwise -> unsafeCrashWith "Matrix>>fromArray: Wrong array length!" toArray :: forall s a. Mat s a -> Array a toArray (Mat a) = a diff --git a/src/Data/Matrix3.purs b/src/Data/Matrix3.purs index bba063b..ccfb48e 100644 --- a/src/Data/Matrix3.purs +++ b/src/Data/Matrix3.purs @@ -18,7 +18,7 @@ import Prelude ((*), (+), (-), ($), (/), (==)) import Data.TypeNat (Four, Three) import Data.Matrix (Mat(Mat), fromArray) import Data.Maybe (Maybe(Just, Nothing)) -import Extensions (fail) +import Partial.Unsafe (unsafeCrashWith) type Mat3 = Mat Three Number @@ -63,4 +63,4 @@ normalFromMat4 (Mat [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, (a31 * b05 - a32 * b04 + a33 * b03) * det, (a32 * b02 - a30 * b05 - a33 * b01) * det, (a30 * b04 - a31 * b02 + a33 * b00) * det] -normalFromMat4 _ = fail "Matrix4>>normalFromMat4: Impossible!" +normalFromMat4 _ = unsafeCrashWith "Matrix4>>normalFromMat4: Impossible!" diff --git a/src/Data/Matrix4.purs b/src/Data/Matrix4.purs index 529fce2..2062c46 100644 --- a/src/Data/Matrix4.purs +++ b/src/Data/Matrix4.purs @@ -22,7 +22,7 @@ import Data.Vector4 (Vec4) as V import Data.Vector (Vec(Vec), normalize, direction, dot) as V import Data.Maybe (Maybe(Just, Nothing)) import Math (sin, cos, sqrt, pi, tan) -import Extensions (fail) +import Partial.Unsafe (unsafeCrashWith) type Vec3N = V.Vec3 Number @@ -48,7 +48,7 @@ transform (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, t4 = V.Vec[x14,x24,x34] w = V.dot v t4 + x44 in V.Vec [(V.dot v t1 + x41) / w,(V.dot v t2 + x42) / w,(V.dot v t3 + x43) / w] -transform _ _ = fail "Matrix4>>transform: Impossible!" +transform _ _ = unsafeCrashWith "Matrix4>>transform: Impossible!" -- | Computes the inverse of the given matrix m, assuming that the matrix is -- orthonormal. @@ -62,8 +62,8 @@ inverseOrthonormal v@(Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33 r13 = negate (V.dot (V.Vec [y12,y22,y32]) t) r14 = negate (V.dot (V.Vec [y13,y23,y33]) t) in Mat [y11, y12, y13, 0.0, y21, y22, y23, 0.0, y31, y32, y33, 0.0, r12, r13, r14, y44] - _ -> fail "Matrix4>>inverseOrthonormal: Impossible!" -inverseOrthonormal _ = fail "Matrix4>>inverseOrthonormal: Impossible!" + _ -> unsafeCrashWith "Matrix4>>inverseOrthonormal: Impossible!" +inverseOrthonormal _ = unsafeCrashWith "Matrix4>>inverseOrthonormal: Impossible!" -- Calculates the inverse matrix of a mat4 inverse :: Mat4 -> Maybe Mat4 @@ -101,7 +101,7 @@ inverse v@(Mat [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, (a00 * b09 - a01 * b07 + a02 * b06) * invDet, (-a30 * b03 + a31 * b01 - a32 * b00) * invDet, (a20 * b03 - a21 * b01 + a22 * b00) * invDet] -inverse _ = fail "Matrix4>>inverse: Impossible!" +inverse _ = unsafeCrashWith "Matrix4>>inverse: Impossible!" -- | Creates a matrix for a projection frustum with the given parameters. -- Parameters: @@ -192,7 +192,7 @@ mulM (Mat [x11, x21, x31, x41, x12, x22, x32, x42, x13, x23, x33, x43, x14, x24, x21 * y14 + x22 * y24 + x23 * y34 + x24 * y44, x31 * y14 + x32 * y24 + x33 * y34 + x34 * y44, x41 * y14 + x42 * y24 + x43 * y34 + x44 * y44] -mulM _ _ = fail "Matrix4>>mulM: Impossible!" +mulM _ _ = unsafeCrashWith "Matrix4>>mulM: Impossible!" -- | Matrix multiplication, assuming a and b are affine: a * b mulAffine :: Mat4 -> Mat4 -> Mat4 @@ -214,7 +214,7 @@ mulAffine (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, x21 * y14 + x22 * y24 + x23 * y34 + x24, x31 * y14 + x32 * y24 + x33 * y34 + x34, 1.0] -mulAffine _ _ = fail "Matrix4>>mulAffine: Impossible!" +mulAffine _ _ = unsafeCrashWith "Matrix4>>mulAffine: Impossible!" -- | Creates a transformation matrix for rotation in radians about the 3-element V.Vector axis. makeRotate :: Number -> Vec3N -> Mat4 @@ -228,7 +228,7 @@ makeRotate angle axis = x*y*c1-z*s,y*y*c1+c,y*z*c1+x*s,0.0, x*z*c1+y*s,y*z*c1-x*s,z*z*c1+c,0.0, 0.0,0.0,0.0,1.0] - _ -> fail "Matrix4>>makeRotate: Impossible!" + _ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!" -- | Concatenates a rotation in radians about an axis to the given matrix. rotate :: Number -> Vec3N -> Mat4 -> Mat4 @@ -270,7 +270,7 @@ rotate angle (V.Vec [a0,a1,a2]) m31 * t13 + m32 * t23 + m33 * t33, m41 * t13 + m42 * t23 + m43 * t33, m14,m24,m34,m44] -rotate _ _ _ = fail "Matrix4>>rotate: Impossible!" +rotate _ _ _ = unsafeCrashWith "Matrix4>>rotate: Impossible!" -- | Creates a transformation matrix for scaling by 3 scalar values, one for -- each of the x, y, and z directions. @@ -284,7 +284,7 @@ makeScale3 x y z = Mat [x,0.0,0.0,0.0, -- the amount given in the corresponding element of the 3-element V.Vector. makeScale :: Vec3N -> Mat4 makeScale (V.Vec [x,y,z]) = makeScale3 x y z -makeScale _ = fail "Matrix4>>makeScale: Impossible!" +makeScale _ = unsafeCrashWith "Matrix4>>makeScale: Impossible!" -- | Concatenates a scaling to the given matrix. scale3 :: Number -> Number -> Number -> Mat4 -> Mat4 @@ -293,12 +293,12 @@ scale3 x y z (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x x21*y, x22*y, x23*y, x24*y, x31*z, x32*z, x33*z, x34*z, x41, x42, x43, x44] -scale3 _ _ _ _ = fail "Matrix4>>scale3: Impossible!" +scale3 _ _ _ _ = unsafeCrashWith "Matrix4>>scale3: Impossible!" -- | Concatenates a scaling to the given matrix. scale :: Vec3N -> Mat4 -> Mat4 scale (V.Vec [x,y,z]) = scale3 x y z -scale _ = fail "Matrix4>>scale: Impossible!" +scale _ = unsafeCrashWith "Matrix4>>scale: Impossible!" -- | Creates a transformation matrix for translating by 3 scalar values, one for -- each of the x, y, and z directions. @@ -312,7 +312,7 @@ makeTranslate3 x y z = Mat [1.0,0.0,0.0,0.0, -- axes by the amount given in the corresponding element of the 3-element V.Vector. makeTranslate :: Vec3N -> Mat4 makeTranslate (V.Vec [x,y,z]) = makeTranslate3 x y z -makeTranslate _ = fail "Matrix4>>makeTranslate: Impossible!" +makeTranslate _ = unsafeCrashWith "Matrix4>>makeTranslate: Impossible!" -- | Concatenates a translation to the given matrix. translate3 :: Number -> Number -> Number -> Mat4 -> Mat4 @@ -324,12 +324,12 @@ translate3 x y z (Mat [m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m4 m21 * x + m22 * y + m23 * z + m24, m31 * x + m32 * y + m33 * z + m34, m41 * x + m42 * y + m43 * z + m44] -translate3 x y z _ = fail "Matrix3>>translate3: Impossible!" +translate3 x y z _ = unsafeCrashWith "Matrix3>>translate3: Impossible!" -- | Concatenates a translation to the given matrix. translate :: Vec3N -> Mat4 -> Mat4 translate (V.Vec [x,y,z]) m = translate3 x y z m -translate _ _ = fail "Matrix3>>translate: Impossible!" +translate _ _ = unsafeCrashWith "Matrix3>>translate: Impossible!" -- | Creates a transformation matrix for a camera. -- Parameters: @@ -353,10 +353,10 @@ makeLookAt eye@(V.Vec [e0,e1,e2]) center up = 0.0,0.0,1.0,0.0, (-e0),(-e1),(-e2),1.0] in mulM m1 m2 - _ -> fail "Matrix4>>makeRotate: Impossible!" - _ -> fail "Matrix4>>makeRotate: Impossible!" - _ -> fail "Matrix4>>makeRotate: Impossible!" -makeLookAt _ _ _ = fail "Matrix4>>makeLookAt: Impossible!" + _ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!" + _ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!" + _ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!" +makeLookAt _ _ _ = unsafeCrashWith "Matrix4>>makeLookAt: Impossible!" -- | Creates a transform from a basis consisting of 3 linearly independent V.Vectors. makeBasis :: Vec3N -> Vec3N -> Vec3N -> Mat4 @@ -365,7 +365,7 @@ makeBasis (V.Vec [x0,x1,x2]) (V.Vec [y0,y1,y2]) (V.Vec [z0,z1,z2])= y0,y1,y2,0.0, z0,z1,z2,0.0, 0.0,0.0,0.0,1.0] -makeBasis _ _ _ = fail "Matrix4>>makeBasis: Impossible!" +makeBasis _ _ _ = unsafeCrashWith "Matrix4>>makeBasis: Impossible!" project :: Vec3N -> Mat4 @@ -407,9 +407,9 @@ project (V.Vec [objx,objy,objz]) (gt1' * 0.5 + 0.5) * vp3 + vp1, -- This is only correct when glDepthRange(0.0, 1.0) (1.0 + gt2') * 0.5]) -- Between 0 and 1 - _ -> fail "Matrix4>>project: Impossible!" - _ -> fail "Matrix4>>project: Impossible!" -project _ _ _ _ = fail "Matrix4>>project: Impossible!" + _ -> unsafeCrashWith "Matrix4>>project: Impossible!" + _ -> unsafeCrashWith "Matrix4>>project: Impossible!" +project _ _ _ _ = unsafeCrashWith "Matrix4>>project: Impossible!" unProject :: Vec3N -> Mat4 @@ -437,8 +437,8 @@ unProject (V.Vec [winx,winy,winz]) then Nothing else let out3' = 1.0 / out3 in Just (V.Vec [out0 * out3',out1 * out3',out2 * out3']) - _ -> fail "Matrix4>>unProject: Impossible!" -unProject _ _ _ _ = fail "Matrix4>>unProject: Impossible!" + _ -> unsafeCrashWith "Matrix4>>unProject: Impossible!" +unProject _ _ _ _ = unsafeCrashWith "Matrix4>>unProject: Impossible!" mulMatVect :: Mat4 -> Vec4N -> Vec4N mulMatVect @@ -448,4 +448,4 @@ mulMatVect m21 * v0 + m22 * v1 + m23 * v2 + m24 * v3, m31 * v0 + m32 * v1 + m33 * v2 + m34 * v3, m41 * v0 + m42 * v1 + m43 * v2 + m44 * v3] -mulMatVect _ _ = fail "Matrix4>>mulMatVect: Impossible!" +mulMatVect _ _ = unsafeCrashWith "Matrix4>>mulMatVect: Impossible!" From b87f87617c36a28bac4228f95c70028efafc8e5e Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:31:46 -0700 Subject: [PATCH 03/10] Update external dependencies. --- bower.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 6b13fc9..1ab52a6 100644 --- a/bower.json +++ b/bower.json @@ -27,12 +27,13 @@ ], "dependencies": { "purescript-vector": "^2.0.0", - "purescript-arrays": "^4.2.0", - "purescript-proxy": "^2.1.0" + "purescript-arrays": "^5.0.0", + "purescript-proxy": "^3.0.0", + "purescript-effect": "2.0.0" }, "devDependencies": { - "purescript-assert": "^3.0.0", - "purescript-console": "^3.0.0", - "purescript-random": "^3.0.0" + "purescript-assert": "^4.0.0", + "purescript-console": "^4.1.0", + "purescript-random": "^4.0.0" } } From f1284d711ebbb6faf17d0ac7dbabbe038d3a4ec0 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:32:07 -0700 Subject: [PATCH 04/10] Vector to Charle-Schleich version. --- bower.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 1ab52a6..8b22489 100644 --- a/bower.json +++ b/bower.json @@ -26,7 +26,8 @@ "package.json" ], "dependencies": { - "purescript-vector": "^2.0.0", + "purescript-vector": + "Charles-Schleich/purescript-vector#94ae6dee32ba3fde1ef6c0b6ada8d466f81da4a4", "purescript-arrays": "^5.0.0", "purescript-proxy": "^3.0.0", "purescript-effect": "2.0.0" From 8501c89d6e595093eddf4055183288e52edccf5e Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:32:24 -0700 Subject: [PATCH 05/10] Removed redundant imports. --- src/Data/ST/Matrix.purs | 1 - src/Data/ST/Matrix4.purs | 1 - test/Main.purs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Data/ST/Matrix.purs b/src/Data/ST/Matrix.purs index 991e636..5e4a139 100644 --- a/src/Data/ST/Matrix.purs +++ b/src/Data/ST/Matrix.purs @@ -16,7 +16,6 @@ module Data.ST.Matrix where import Prelude import Effect (Effect) -import Control.Monad.ST (ST()) import Data.TypeNat (class Sized) import Data.Array.ST (STArray) import Data.Matrix as M diff --git a/src/Data/ST/Matrix4.purs b/src/Data/ST/Matrix4.purs index 74ea776..bf9e778 100644 --- a/src/Data/ST/Matrix4.purs +++ b/src/Data/ST/Matrix4.purs @@ -19,7 +19,6 @@ import Data.TypeNat (Four) import Data.Matrix4 (Vec3N()) import Data.ST.Matrix (STMat) import Effect (Effect) -import Control.Monad.ST (ST()) type STMat4 h = STMat Four h Number diff --git a/test/Main.purs b/test/Main.purs index 6e057e9..6348a6d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -8,7 +8,6 @@ import Data.ST.Matrix (runSTMatrix) as M import Data.Vector as V import Effect (Effect) -import Control.Monad.ST (ST()) import Effect.Console (logShow) From e0ced086977b33c58f358e15ac9fd1567ef9a4d6 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:43:12 -0700 Subject: [PATCH 06/10] formatting --- bower.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 8b22489..cf2e29f 100644 --- a/bower.json +++ b/bower.json @@ -2,13 +2,9 @@ "name": "purescript-matrix", "homepage": "https://github.com/jutaro/purescript-matrix", "version": "0.2.0", - "authors": [ - "Juergen Nicklisch-Franken " - ], + "authors": ["Juergen Nicklisch-Franken "], "description": "Matrices for purescript", - "keywords": [ - "purescript" - ], + "keywords": ["purescript"], "repository": { "type": "git", "url": "git://github.com/jutaro/purescript-matrix.git" From 3f74a5d91369681f9dca06fb714c0c9c36a015f1 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:43:18 -0700 Subject: [PATCH 07/10] updated url. --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index cf2e29f..ce07106 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,7 @@ "keywords": ["purescript"], "repository": { "type": "git", - "url": "git://github.com/jutaro/purescript-matrix.git" + "url": "git://github.com/mgmeier/purescript-matrix.git" }, "license": "Apache-2.0", "ignore": [ From 805fefb9bb008795579247c3c1d8bbf49a8c9821 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 10:43:30 -0700 Subject: [PATCH 08/10] Updated version in bower. --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index ce07106..70d1fe8 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "purescript-matrix", "homepage": "https://github.com/jutaro/purescript-matrix", - "version": "0.2.0", + "version": "3.0.0", "authors": ["Juergen Nicklisch-Franken "], "description": "Matrices for purescript", "keywords": ["purescript"], From f9622779b2f072c4f1b18b2018ebbcac10fe1cef Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 12:15:08 -0700 Subject: [PATCH 09/10] Use my 0.12 vector --- bower.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 70d1fe8..04bc736 100644 --- a/bower.json +++ b/bower.json @@ -22,8 +22,7 @@ "package.json" ], "dependencies": { - "purescript-vector": - "Charles-Schleich/purescript-vector#94ae6dee32ba3fde1ef6c0b6ada8d466f81da4a4", + "purescript-vector": "AlexMouton/purescript-vector#compiler-0.12", "purescript-arrays": "^5.0.0", "purescript-proxy": "^3.0.0", "purescript-effect": "2.0.0" From f9b013fb89a97b4049fdadfbed62e288c9410495 Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Tue, 31 Jul 2018 15:40:23 -0700 Subject: [PATCH 10/10] pulp to 12.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfa5fc1..7f6ce5e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "devDependencies": { - "pulp": "^9.0.1", + "pulp": "^12.2.1", "browserify": "*", "benchmark": "*", "microtime": "*"