@@ -22,7 +22,7 @@ import Data.Vector4 (Vec4) as V
22
22
import Data.Vector (Vec (Vec), normalize , direction , dot ) as V
23
23
import Data.Maybe (Maybe (Just, Nothing))
24
24
import Math (sin , cos , sqrt , pi , tan )
25
- import Extensions ( fail )
25
+ import Partial.Unsafe ( unsafeCrashWith )
26
26
27
27
28
28
type Vec3N = V.Vec3 Number
@@ -48,7 +48,7 @@ transform (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41,
48
48
t4 = V.Vec [x14,x24,x34]
49
49
w = V .dot v t4 + x44
50
50
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!"
52
52
53
53
-- | Computes the inverse of the given matrix m, assuming that the matrix is
54
54
-- orthonormal.
@@ -62,8 +62,8 @@ inverseOrthonormal v@(Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33
62
62
r13 = negate (V .dot (V.Vec [y12,y22,y32]) t)
63
63
r14 = negate (V .dot (V.Vec [y13,y23,y33]) t)
64
64
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!"
67
67
68
68
-- Calculates the inverse matrix of a mat4
69
69
inverse :: Mat4 -> Maybe Mat4
@@ -101,7 +101,7 @@ inverse v@(Mat [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30,
101
101
(a00 * b09 - a01 * b07 + a02 * b06) * invDet,
102
102
(-a30 * b03 + a31 * b01 - a32 * b00) * invDet,
103
103
(a20 * b03 - a21 * b01 + a22 * b00) * invDet]
104
- inverse _ = fail " Matrix4>>inverse: Impossible!"
104
+ inverse _ = unsafeCrashWith " Matrix4>>inverse: Impossible!"
105
105
106
106
-- | Creates a matrix for a projection frustum with the given parameters.
107
107
-- Parameters:
@@ -192,7 +192,7 @@ mulM (Mat [x11, x21, x31, x41, x12, x22, x32, x42, x13, x23, x33, x43, x14, x24,
192
192
x21 * y14 + x22 * y24 + x23 * y34 + x24 * y44,
193
193
x31 * y14 + x32 * y24 + x33 * y34 + x34 * y44,
194
194
x41 * y14 + x42 * y24 + x43 * y34 + x44 * y44]
195
- mulM _ _ = fail " Matrix4>>mulM: Impossible!"
195
+ mulM _ _ = unsafeCrashWith " Matrix4>>mulM: Impossible!"
196
196
197
197
-- | Matrix multiplication, assuming a and b are affine: a * b
198
198
mulAffine :: Mat4 -> Mat4 -> Mat4
@@ -214,7 +214,7 @@ mulAffine (Mat [x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41,
214
214
x21 * y14 + x22 * y24 + x23 * y34 + x24,
215
215
x31 * y14 + x32 * y24 + x33 * y34 + x34,
216
216
1.0 ]
217
- mulAffine _ _ = fail " Matrix4>>mulAffine: Impossible!"
217
+ mulAffine _ _ = unsafeCrashWith " Matrix4>>mulAffine: Impossible!"
218
218
219
219
-- | Creates a transformation matrix for rotation in radians about the 3-element V.Vector axis.
220
220
makeRotate :: Number -> Vec3N -> Mat4
@@ -228,7 +228,7 @@ makeRotate angle axis =
228
228
x*y*c1-z*s,y*y*c1+c,y*z*c1+x*s,0.0 ,
229
229
x*z*c1+y*s,y*z*c1-x*s,z*z*c1+c,0.0 ,
230
230
0.0 ,0.0 ,0.0 ,1.0 ]
231
- _ -> fail " Matrix4>>makeRotate: Impossible!"
231
+ _ -> unsafeCrashWith " Matrix4>>makeRotate: Impossible!"
232
232
233
233
-- | Concatenates a rotation in radians about an axis to the given matrix.
234
234
rotate :: Number -> Vec3N -> Mat4 -> Mat4
@@ -270,7 +270,7 @@ rotate angle (V.Vec [a0,a1,a2])
270
270
m31 * t13 + m32 * t23 + m33 * t33,
271
271
m41 * t13 + m42 * t23 + m43 * t33,
272
272
m14,m24,m34,m44]
273
- rotate _ _ _ = fail " Matrix4>>rotate: Impossible!"
273
+ rotate _ _ _ = unsafeCrashWith " Matrix4>>rotate: Impossible!"
274
274
275
275
-- | Creates a transformation matrix for scaling by 3 scalar values, one for
276
276
-- each of the x, y, and z directions.
@@ -284,7 +284,7 @@ makeScale3 x y z = Mat [x,0.0,0.0,0.0,
284
284
-- the amount given in the corresponding element of the 3-element V.Vector.
285
285
makeScale :: Vec3N -> Mat4
286
286
makeScale (V.Vec [x,y,z]) = makeScale3 x y z
287
- makeScale _ = fail " Matrix4>>makeScale: Impossible!"
287
+ makeScale _ = unsafeCrashWith " Matrix4>>makeScale: Impossible!"
288
288
289
289
-- | Concatenates a scaling to the given matrix.
290
290
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
293
293
x21*y, x22*y, x23*y, x24*y,
294
294
x31*z, x32*z, x33*z, x34*z,
295
295
x41, x42, x43, x44]
296
- scale3 _ _ _ _ = fail " Matrix4>>scale3: Impossible!"
296
+ scale3 _ _ _ _ = unsafeCrashWith " Matrix4>>scale3: Impossible!"
297
297
298
298
-- | Concatenates a scaling to the given matrix.
299
299
scale :: Vec3N -> Mat4 -> Mat4
300
300
scale (V.Vec [x,y,z]) = scale3 x y z
301
- scale _ = fail " Matrix4>>scale: Impossible!"
301
+ scale _ = unsafeCrashWith " Matrix4>>scale: Impossible!"
302
302
303
303
-- | Creates a transformation matrix for translating by 3 scalar values, one for
304
304
-- 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,
312
312
-- axes by the amount given in the corresponding element of the 3-element V.Vector.
313
313
makeTranslate :: Vec3N -> Mat4
314
314
makeTranslate (V.Vec [x,y,z]) = makeTranslate3 x y z
315
- makeTranslate _ = fail " Matrix4>>makeTranslate: Impossible!"
315
+ makeTranslate _ = unsafeCrashWith " Matrix4>>makeTranslate: Impossible!"
316
316
317
317
-- | Concatenates a translation to the given matrix.
318
318
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
324
324
m21 * x + m22 * y + m23 * z + m24,
325
325
m31 * x + m32 * y + m33 * z + m34,
326
326
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!"
328
328
329
329
-- | Concatenates a translation to the given matrix.
330
330
translate :: Vec3N -> Mat4 -> Mat4
331
331
translate (V.Vec [x,y,z]) m = translate3 x y z m
332
- translate _ _ = fail " Matrix3>>translate: Impossible!"
332
+ translate _ _ = unsafeCrashWith " Matrix3>>translate: Impossible!"
333
333
334
334
-- | Creates a transformation matrix for a camera.
335
335
-- Parameters:
@@ -353,10 +353,10 @@ makeLookAt eye@(V.Vec [e0,e1,e2]) center up =
353
353
0.0 ,0.0 ,1.0 ,0.0 ,
354
354
(-e0),(-e1),(-e2),1.0 ]
355
355
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!"
360
360
361
361
-- | Creates a transform from a basis consisting of 3 linearly independent V.Vectors.
362
362
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])=
365
365
y0,y1,y2,0.0 ,
366
366
z0,z1,z2,0.0 ,
367
367
0.0 ,0.0 ,0.0 ,1.0 ]
368
- makeBasis _ _ _ = fail " Matrix4>>makeBasis: Impossible!"
368
+ makeBasis _ _ _ = unsafeCrashWith " Matrix4>>makeBasis: Impossible!"
369
369
370
370
project :: Vec3N
371
371
-> Mat4
@@ -407,9 +407,9 @@ project (V.Vec [objx,objy,objz])
407
407
(gt1' * 0.5 + 0.5 ) * vp3 + vp1,
408
408
-- This is only correct when glDepthRange(0.0, 1.0)
409
409
(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!"
413
413
414
414
unProject :: Vec3N
415
415
-> Mat4
@@ -437,8 +437,8 @@ unProject (V.Vec [winx,winy,winz])
437
437
then Nothing
438
438
else let out3' = 1.0 / out3
439
439
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!"
442
442
443
443
mulMatVect :: Mat4 -> Vec4N -> Vec4N
444
444
mulMatVect
@@ -448,4 +448,4 @@ mulMatVect
448
448
m21 * v0 + m22 * v1 + m23 * v2 + m24 * v3,
449
449
m31 * v0 + m32 * v1 + m33 * v2 + m34 * v3,
450
450
m41 * v0 + m42 * v1 + m43 * v2 + m44 * v3]
451
- mulMatVect _ _ = fail " Matrix4>>mulMatVect: Impossible!"
451
+ mulMatVect _ _ = unsafeCrashWith " Matrix4>>mulMatVect: Impossible!"
0 commit comments