Skip to content

Commit 8b9eecf

Browse files
committed
Replace purescript-extensions fail with unsafeCrashWith.
1 parent 6376c1d commit 8b9eecf

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

bower.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828
"dependencies": {
2929
"purescript-vector": "^2.0.0",
3030
"purescript-arrays": "^4.2.0",
31-
"purescript-extensions": "^2.2.0",
3231
"purescript-proxy": "^2.1.0"
3332
},
3433
"devDependencies": {
3534
"purescript-assert": "^3.0.0",
3635
"purescript-console": "^3.0.0",
3736
"purescript-random": "^3.0.0"
38-
},
39-
"resolutions": {
40-
"purescript-extensions": "^2.2.0"
4137
}
4238
}

src/Data/Matrix.purs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import Data.Array (length, (!!), zipWith, slice, range, concat)
1919
import Data.Maybe (fromJust)
2020
import Data.TypeNat (class Sized, Four, Three, Two, sized)
2121
import Type.Proxy (Proxy(Proxy))
22-
import Extensions (fail)
23-
import Partial.Unsafe (unsafePartial)
22+
import Partial.Unsafe (unsafePartial, unsafeCrashWith)
2423

2524
newtype Mat s a = Mat (Array a)
2625

@@ -61,7 +60,7 @@ columns mat@(Mat m) | sized (Proxy :: Proxy s) == 2 =
6160
slice 8 12 m,
6261
slice 12 16 m]
6362
| otherwise =
64-
fail "Matrix>>columns: Proxy size not supprted!"
63+
unsafeCrashWith "Matrix>>columns: Proxy size not supprted!"
6564

6665
instance eqMat :: (Eq a) => Eq (Mat s a) where
6766
eq (Mat l) (Mat r) = l == r
@@ -107,7 +106,7 @@ fromArray l =
107106
let size = sized (Proxy :: Proxy s)
108107
in case size * size of
109108
i | i == length l -> Mat l
110-
| otherwise -> fail "Matrix>>fromArray: Wrong array length!"
109+
| otherwise -> unsafeCrashWith "Matrix>>fromArray: Wrong array length!"
111110

112111
toArray :: forall s a. Mat s a -> Array a
113112
toArray (Mat a) = a

src/Data/Matrix3.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Prelude ((*), (+), (-), ($), (/), (==))
1818
import Data.TypeNat (Four, Three)
1919
import Data.Matrix (Mat(Mat), fromArray)
2020
import Data.Maybe (Maybe(Just, Nothing))
21-
import Extensions (fail)
21+
import Partial.Unsafe (unsafeCrashWith)
2222

2323
type Mat3 = Mat Three Number
2424

@@ -63,4 +63,4 @@ normalFromMat4 (Mat [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23,
6363
(a31 * b05 - a32 * b04 + a33 * b03) * det,
6464
(a32 * b02 - a30 * b05 - a33 * b01) * det,
6565
(a30 * b04 - a31 * b02 + a33 * b00) * det]
66-
normalFromMat4 _ = fail "Matrix4>>normalFromMat4: Impossible!"
66+
normalFromMat4 _ = unsafeCrashWith "Matrix4>>normalFromMat4: Impossible!"

src/Data/Matrix4.purs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Data.Vector4 (Vec4) as V
2222
import Data.Vector (Vec(Vec), normalize, direction, dot) as V
2323
import Data.Maybe (Maybe(Just, Nothing))
2424
import Math (sin, cos, sqrt, pi, tan)
25-
import Extensions (fail)
25+
import Partial.Unsafe (unsafeCrashWith)
2626

2727

2828
type Vec3N = V.Vec3 Number
@@ -48,7 +48,7 @@ transform (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41,
4848
t4 = V.Vec[x14,x24,x34]
4949
w = V.dot v t4 + x44
5050
in V.Vec [(V.dot v t1 + x41) / w,(V.dot v t2 + x42) / w,(V.dot v t3 + x43) / w]
51-
transform _ _ = fail "Matrix4>>transform: Impossible!"
51+
transform _ _ = unsafeCrashWith "Matrix4>>transform: Impossible!"
5252

5353
-- | Computes the inverse of the given matrix m, assuming that the matrix is
5454
-- orthonormal.
@@ -62,8 +62,8 @@ inverseOrthonormal v@(Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33
6262
r13 = negate (V.dot (V.Vec [y12,y22,y32]) t)
6363
r14 = negate (V.dot (V.Vec [y13,y23,y33]) t)
6464
in Mat [y11, y12, y13, 0.0, y21, y22, y23, 0.0, y31, y32, y33, 0.0, r12, r13, r14, y44]
65-
_ -> fail "Matrix4>>inverseOrthonormal: Impossible!"
66-
inverseOrthonormal _ = fail "Matrix4>>inverseOrthonormal: Impossible!"
65+
_ -> unsafeCrashWith "Matrix4>>inverseOrthonormal: Impossible!"
66+
inverseOrthonormal _ = unsafeCrashWith "Matrix4>>inverseOrthonormal: Impossible!"
6767

6868
-- Calculates the inverse matrix of a mat4
6969
inverse :: Mat4 -> Maybe Mat4
@@ -101,7 +101,7 @@ inverse v@(Mat [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30,
101101
(a00 * b09 - a01 * b07 + a02 * b06) * invDet,
102102
(-a30 * b03 + a31 * b01 - a32 * b00) * invDet,
103103
(a20 * b03 - a21 * b01 + a22 * b00) * invDet]
104-
inverse _ = fail "Matrix4>>inverse: Impossible!"
104+
inverse _ = unsafeCrashWith "Matrix4>>inverse: Impossible!"
105105

106106
-- | Creates a matrix for a projection frustum with the given parameters.
107107
-- Parameters:
@@ -192,7 +192,7 @@ mulM (Mat [x11, x21, x31, x41, x12, x22, x32, x42, x13, x23, x33, x43, x14, x24,
192192
x21 * y14 + x22 * y24 + x23 * y34 + x24 * y44,
193193
x31 * y14 + x32 * y24 + x33 * y34 + x34 * y44,
194194
x41 * y14 + x42 * y24 + x43 * y34 + x44 * y44]
195-
mulM _ _ = fail "Matrix4>>mulM: Impossible!"
195+
mulM _ _ = unsafeCrashWith "Matrix4>>mulM: Impossible!"
196196

197197
-- | Matrix multiplication, assuming a and b are affine: a * b
198198
mulAffine :: Mat4 -> Mat4 -> Mat4
@@ -214,7 +214,7 @@ mulAffine (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41,
214214
x21 * y14 + x22 * y24 + x23 * y34 + x24,
215215
x31 * y14 + x32 * y24 + x33 * y34 + x34,
216216
1.0]
217-
mulAffine _ _ = fail "Matrix4>>mulAffine: Impossible!"
217+
mulAffine _ _ = unsafeCrashWith "Matrix4>>mulAffine: Impossible!"
218218

219219
-- | Creates a transformation matrix for rotation in radians about the 3-element V.Vector axis.
220220
makeRotate :: Number -> Vec3N -> Mat4
@@ -228,7 +228,7 @@ makeRotate angle axis =
228228
x*y*c1-z*s,y*y*c1+c,y*z*c1+x*s,0.0,
229229
x*z*c1+y*s,y*z*c1-x*s,z*z*c1+c,0.0,
230230
0.0,0.0,0.0,1.0]
231-
_ -> fail "Matrix4>>makeRotate: Impossible!"
231+
_ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!"
232232

233233
-- | Concatenates a rotation in radians about an axis to the given matrix.
234234
rotate :: Number -> Vec3N -> Mat4 -> Mat4
@@ -270,7 +270,7 @@ rotate angle (V.Vec [a0,a1,a2])
270270
m31 * t13 + m32 * t23 + m33 * t33,
271271
m41 * t13 + m42 * t23 + m43 * t33,
272272
m14,m24,m34,m44]
273-
rotate _ _ _ = fail "Matrix4>>rotate: Impossible!"
273+
rotate _ _ _ = unsafeCrashWith "Matrix4>>rotate: Impossible!"
274274

275275
-- | Creates a transformation matrix for scaling by 3 scalar values, one for
276276
-- each of the x, y, and z directions.
@@ -284,7 +284,7 @@ makeScale3 x y z = Mat [x,0.0,0.0,0.0,
284284
-- the amount given in the corresponding element of the 3-element V.Vector.
285285
makeScale :: Vec3N -> Mat4
286286
makeScale (V.Vec [x,y,z]) = makeScale3 x y z
287-
makeScale _ = fail "Matrix4>>makeScale: Impossible!"
287+
makeScale _ = unsafeCrashWith "Matrix4>>makeScale: Impossible!"
288288

289289
-- | Concatenates a scaling to the given matrix.
290290
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
293293
x21*y, x22*y, x23*y, x24*y,
294294
x31*z, x32*z, x33*z, x34*z,
295295
x41, x42, x43, x44]
296-
scale3 _ _ _ _ = fail "Matrix4>>scale3: Impossible!"
296+
scale3 _ _ _ _ = unsafeCrashWith "Matrix4>>scale3: Impossible!"
297297

298298
-- | Concatenates a scaling to the given matrix.
299299
scale :: Vec3N -> Mat4 -> Mat4
300300
scale (V.Vec [x,y,z]) = scale3 x y z
301-
scale _ = fail "Matrix4>>scale: Impossible!"
301+
scale _ = unsafeCrashWith "Matrix4>>scale: Impossible!"
302302

303303
-- | Creates a transformation matrix for translating by 3 scalar values, one for
304304
-- 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,
312312
-- axes by the amount given in the corresponding element of the 3-element V.Vector.
313313
makeTranslate :: Vec3N -> Mat4
314314
makeTranslate (V.Vec [x,y,z]) = makeTranslate3 x y z
315-
makeTranslate _ = fail "Matrix4>>makeTranslate: Impossible!"
315+
makeTranslate _ = unsafeCrashWith "Matrix4>>makeTranslate: Impossible!"
316316

317317
-- | Concatenates a translation to the given matrix.
318318
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
324324
m21 * x + m22 * y + m23 * z + m24,
325325
m31 * x + m32 * y + m33 * z + m34,
326326
m41 * x + m42 * y + m43 * z + m44]
327-
translate3 x y z _ = fail "Matrix3>>translate3: Impossible!"
327+
translate3 x y z _ = unsafeCrashWith "Matrix3>>translate3: Impossible!"
328328

329329
-- | Concatenates a translation to the given matrix.
330330
translate :: Vec3N -> Mat4 -> Mat4
331331
translate (V.Vec [x,y,z]) m = translate3 x y z m
332-
translate _ _ = fail "Matrix3>>translate: Impossible!"
332+
translate _ _ = unsafeCrashWith "Matrix3>>translate: Impossible!"
333333

334334
-- | Creates a transformation matrix for a camera.
335335
-- Parameters:
@@ -353,10 +353,10 @@ makeLookAt eye@(V.Vec [e0,e1,e2]) center up =
353353
0.0,0.0,1.0,0.0,
354354
(-e0),(-e1),(-e2),1.0]
355355
in mulM m1 m2
356-
_ -> fail "Matrix4>>makeRotate: Impossible!"
357-
_ -> fail "Matrix4>>makeRotate: Impossible!"
358-
_ -> fail "Matrix4>>makeRotate: Impossible!"
359-
makeLookAt _ _ _ = fail "Matrix4>>makeLookAt: Impossible!"
356+
_ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!"
357+
_ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!"
358+
_ -> unsafeCrashWith "Matrix4>>makeRotate: Impossible!"
359+
makeLookAt _ _ _ = unsafeCrashWith "Matrix4>>makeLookAt: Impossible!"
360360

361361
-- | Creates a transform from a basis consisting of 3 linearly independent V.Vectors.
362362
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])=
365365
y0,y1,y2,0.0,
366366
z0,z1,z2,0.0,
367367
0.0,0.0,0.0,1.0]
368-
makeBasis _ _ _ = fail "Matrix4>>makeBasis: Impossible!"
368+
makeBasis _ _ _ = unsafeCrashWith "Matrix4>>makeBasis: Impossible!"
369369

370370
project :: Vec3N
371371
-> Mat4
@@ -407,9 +407,9 @@ project (V.Vec [objx,objy,objz])
407407
(gt1' * 0.5 + 0.5) * vp3 + vp1,
408408
-- This is only correct when glDepthRange(0.0, 1.0)
409409
(1.0 + gt2') * 0.5]) -- Between 0 and 1
410-
_ -> fail "Matrix4>>project: Impossible!"
411-
_ -> fail "Matrix4>>project: Impossible!"
412-
project _ _ _ _ = fail "Matrix4>>project: Impossible!"
410+
_ -> unsafeCrashWith "Matrix4>>project: Impossible!"
411+
_ -> unsafeCrashWith "Matrix4>>project: Impossible!"
412+
project _ _ _ _ = unsafeCrashWith "Matrix4>>project: Impossible!"
413413

414414
unProject :: Vec3N
415415
-> Mat4
@@ -437,8 +437,8 @@ unProject (V.Vec [winx,winy,winz])
437437
then Nothing
438438
else let out3' = 1.0 / out3
439439
in Just (V.Vec [out0 * out3',out1 * out3',out2 * out3'])
440-
_ -> fail "Matrix4>>unProject: Impossible!"
441-
unProject _ _ _ _ = fail "Matrix4>>unProject: Impossible!"
440+
_ -> unsafeCrashWith "Matrix4>>unProject: Impossible!"
441+
unProject _ _ _ _ = unsafeCrashWith "Matrix4>>unProject: Impossible!"
442442

443443
mulMatVect :: Mat4 -> Vec4N -> Vec4N
444444
mulMatVect
@@ -448,4 +448,4 @@ mulMatVect
448448
m21 * v0 + m22 * v1 + m23 * v2 + m24 * v3,
449449
m31 * v0 + m32 * v1 + m33 * v2 + m34 * v3,
450450
m41 * v0 + m42 * v1 + m43 * v2 + m44 * v3]
451-
mulMatVect _ _ = fail "Matrix4>>mulMatVect: Impossible!"
451+
mulMatVect _ _ = unsafeCrashWith "Matrix4>>mulMatVect: Impossible!"

0 commit comments

Comments
 (0)