@@ -22,7 +22,7 @@ import Data.Vector4 (Vec4) as V
2222import Data.Vector (Vec (Vec), normalize , direction , dot ) as V
2323import Data.Maybe (Maybe (Just, Nothing))
2424import Math (sin , cos , sqrt , pi , tan )
25- import Extensions ( fail )
25+ import Partial.Unsafe ( unsafeCrashWith )
2626
2727
2828type 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
6969inverse :: 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
198198mulAffine :: 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.
220220makeRotate :: 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.
234234rotate :: 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.
285285makeScale :: Vec3N -> Mat4
286286makeScale (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.
290290scale3 :: 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.
299299scale :: Vec3N -> Mat4 -> Mat4
300300scale (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.
313313makeTranslate :: Vec3N -> Mat4
314314makeTranslate (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.
318318translate3 :: 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.
330330translate :: Vec3N -> Mat4 -> Mat4
331331translate (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.
362362makeBasis :: 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
370370project :: 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
414414unProject :: 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
443443mulMatVect :: Mat4 -> Vec4N -> Vec4N
444444mulMatVect
@@ -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