on master help sign in
minor markdown fixes in comments
commit3965802a8a12d9e4c89befe7696a058fa299b909 authorEvan Czaplicki <info@elm-lang.org> dateMon 5 May 2014, 11:12 (13 years ago) parent1b3a66a
1 file changed+59−92
libraries/MJS.elm+59−92
libraries/MJS.elm+59−92
@@ -1,10 +1,7 @@
11module MJS where
22
3−{-| MJS
4−
5−A high performance linear algebra library using
6−native JS arrays. Geared towards 3D graphics
7−and use with Graphics.WebGL.
3+{-| A high performance linear algebra library using native JS arrays. Geared
4+towards 3D graphics and use with `Graphics.WebGL`.
85
96Both vectors and matrices are immutable.
107
@@ -40,126 +37,106 @@ data V2 = V2
4037data V3 = V3
4138data V4 = V4
4239
43−{-|
44−Creates a new 3-element vector with the given values
40+{-| Creates a new 3-element vector with the given values
4541-}
4642v3 : Float -> Float -> Float -> V3
4743v3 = Native.MJS.v3
4844
49−{-|
50−Convert to a native tuple
45+{-| Convert to a native tuple
5146-}
5247toTuple3 : V3 -> (Float,Float,Float)
5348toTuple3 = Native.MJS.toTuple3
5449
55−{-|
56−Vector addition: a + b
50+{-| Vector addition: a + b
5751-}
5852add : V3 -> V3 -> V3
5953add = Native.MJS.v3add
6054
61−{-|
62−Vector subtraction: a - b
55+{-| Vector subtraction: a - b
6356-}
6457sub : V3 -> V3 -> V3
6558sub = Native.MJS.v3sub
6659
67−{-|
68−Vector negation: -a
60+{-| Vector negation: -a
6961-}
7062neg : V3 -> V3
7163neg = Native.MJS.v3neg
7264
73−{-|
74−The normalized direction from a to b: (a - b) / |a - b|
65+{-| The normalized direction from a to b: (a - b) / |a - b|
7566-}
7667direction : V3 -> V3 -> V3
7768direction = Native.MJS.v3direction
7869
79−{-|
80−The length of the given vector: |a|
70+{-| The length of the given vector: |a|
8171-}
8272length : V3 -> Float
8373length = Native.MJS.v3length
8474
85−{-|
86−The square of the length of the given vector: |a|*|a|
75+{-| The square of the length of the given vector: |a| * |a|
8776-}
8877lengthSquared : V3 -> Float
8978lengthSquared = Native.MJS.v3lengthSquared
9079
91−{-|
92−A unit vector with the same direction as the given vector: a / |a|
80+{-| A unit vector with the same direction as the given vector: a / |a|
9381-}
9482normalize : V3 -> V3
9583normalize = Native.MJS.v3normalize
9684
97−{-|
98−Multiply the vector by a scalar: a * k
85+{-| Multiply the vector by a scalar: a * k
9986-}
10087scale : V3 -> Float -> V3
10188scale = Native.MJS.v3scale
10289
103−{-|
104−The dot product of a and b
90+{-| The dot product of a and b
10591-}
10692dot : V3 -> V3 -> Float
10793dot = Native.MJS.v3dot
10894
109−{-|
110−The cross product of a and b
95+{-| The cross product of a and b
11196-}
11297cross : V3 -> V3 -> V3
11398cross = Native.MJS.v3cross
11499
115−{-|
116−Methods for working with 4x4 matrices.
117−-}
118100data M4x4 = M4x4
119101
120−{-|
121−Multiple the vector by the 4x4 matrix: m * v
102+{-| Multiply a vector by a 4x4 matrix: m * v
122103-}
123104mul4x4 : M4x4 -> V3 -> V3
124105mul4x4 = Native.MJS.v3mul4x4
125106
126−{-|
127−A matrix with all 0s, except 1s on the diagonal
107+{-| A matrix with all 0s, except 1s on the diagonal.
128108-}
129109identity : M4x4
130110identity = Native.MJS.m4x4identity
131111
132−{-|
133−Computes the inverse of the given matrix m, assuming that
134−the matrix is orthonormal
112+{-| Computes the inverse of the given matrix m, assuming that the matrix is
113+orthonormal.
135114-}
136115inverseOrthonormal : M4x4 -> M4x4
137116inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
138117
139−{-|
140−Creates a matrix for a projection frustum with the given parameters.
118+{-| Creates a matrix for a projection frustum with the given parameters.
141119
142120Parameters:
143121
144− left - the left coordinate of the frustum
145− right- the right coordinate of the frustum
146− bottom - the bottom coordinate of the frustum
147− top - the top coordinate of the frustum
148− znear - the near z distance of the frustum
149− zfar - the far z distance of the frustum
122+ * left - the left coordinate of the frustum
123+ * right- the right coordinate of the frustum
124+ * bottom - the bottom coordinate of the frustum
125+ * top - the top coordinate of the frustum
126+ * znear - the near z distance of the frustum
127+ * zfar - the far z distance of the frustum
150128-}
151129makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
152130makeFrustrum = Native.MJS.m4x4makeFrustrum
153131
154−{-|
155−Creates a matrix for a perspective projection with the given parameters.
132+{-| Creates a matrix for a perspective projection with the given parameters.
156133
157−Parameters:
134+Parameters:
158135
159− fovy - field of view in the y axis, in degrees
160− aspect - aspect ratio
161− znear - the near z distance of the projection
162− zfar - the far z distance of the projection
136+ * fovy - field of view in the y axis, in degrees
137+ * aspect - aspect ratio
138+ * znear - the near z distance of the projection
139+ * zfar - the far z distance of the projection
163140-}
164141makePerspective : Float -> Float -> Float -> Float -> M4x4
165142makePerspective = Native.MJS.m4x4makePerspective
@@ -169,76 +146,68 @@ Creates a matrix for an orthogonal frustum projection with the given parameters.
169146
170147Parameters:
171148
172− left - the left coordinate of the frustum
173− right- the right coordinate of the frustum
174− bottom - the bottom coordinate of the frustum
175− top - the top coordinate of the frustum
176− znear - the near z distance of the frustum
177− zfar - the far z distance of the frustum
149+ * left - the left coordinate of the frustum
150+ * right- the right coordinate of the frustum
151+ * bottom - the bottom coordinate of the frustum
152+ * top - the top coordinate of the frustum
153+ * znear - the near z distance of the frustum
154+ * zfar - the far z distance of the frustum
178155-}
179156makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
180157makeOrtho = Native.MJS.m4x4makeOrtho
181158
182−{-|
183−Creates a matrix for a 2D orthogonal frustum projection with the given parameters.
184−znear and zfar are assumed to be -1 and 1, respectively.
159+{-| Creates a matrix for a 2D orthogonal frustum projection with the given
160+parameters. `znear` and `zfar` are assumed to be -1 and 1, respectively.
185161
186162Parameters:
187163
188− left - the left coordinate of the frustum
189− right- the right coordinate of the frustum
190− bottom - the bottom coordinate of the frustum
191− top - the top coordinate of the frustum
164+ * left - the left coordinate of the frustum
165+ * right- the right coordinate of the frustum
166+ * bottom - the bottom coordinate of the frustum
167+ * top - the top coordinate of the frustum
192168-}
193169makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
194170makeOrtho2D = Native.MJS.m4x4makeOrtho2D
195171
196−{-|
197−Matrix multiplcation: a * b
172+{-| Matrix multiplcation: a * b
198173-}
199174mul : M4x4 -> M4x4 -> M4x4
200175mul = Native.MJS.m4x4mul
201176
202−{-|
203−Matrix multiplication, assuming a and b are affine: a * b
177+{-| Matrix multiplication, assuming a and b are affine: a * b
204178-}
205179mulAffine : M4x4 -> M4x4 -> M4x4
206180mulAffine = Native.MJS.m4x4mulAffine
207181
208−{-|
209−Creates a transformation matrix for rotation by angle radians about the 3-element vector axis.
182+{-| Creates a transformation matrix for rotation in radians about the
183+3-element vector axis.
210184-}
211185makeRotate : Float -> V3 -> M4x4
212186makeRotate = Native.MJS.m4x4makeRotate
213187
214−{-|
215−Concatenates a rotation of angle radians about the axis to the given matrix.
188+{-| Concatenates a rotation of angle radians about the axis to the given matrix.
216189-}
217190rotate : Float -> V3 -> M4x4 -> M4x4
218191rotate = Native.MJS.m4x4rotate
219192
220−{-|
221−Creates a transformation matrix for scaling by 3 scalar values, one for
193+{-| Creates a transformation matrix for scaling by 3 scalar values, one for
222194each of the x, y, and z directions.
223195-}
224196makeScale3 : Float -> Float -> Float -> M4x4
225197makeScale3 = Native.MJS.m4x4makeScale3
226198
227−{-|
228−Creates a transformation matrix for scaling each of the x, y, and z axes by the amount
229−given in the corresponding element of the 3-element vector.
199+{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
200+the amount given in the corresponding element of the 3-element vector.
230201-}
231202makeScale : V3 -> M4x4
232203makeScale = Native.MJS.m4x4makeScale
233204
234−{-|
235−Concatenates a scaling to the given matrix.
205+{-| Concatenates a scaling to the given matrix.
236206-}
237207scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
238208scaleM3 = Native.MJS.m4x4scale3
239209
240−{-|
241−Concatenates a scaling to the given matrix.
210+{-| Concatenates a scaling to the given matrix.
242211-}
243212scaleM : V3 -> M4x4 -> M4x4
244213scaleM = Native.MJS.m4x4scale
@@ -250,9 +219,8 @@ each of the x, y, and z directions.
250219makeTranslate3 : Float -> Float -> Float -> M4x4
251220makeTranslate3 = Native.MJS.m4x4makeTranslate3
252221
253−{-|
254−Creates a transformation matrix for translating each of the x, y, and z axes by the amount
255−given in the corresponding element of the 3-element vector.
222+{-| Creates a transformation matrix for translating each of the x, y, and z
223+axes by the amount given in the corresponding element of the 3-element vector.
256224-}
257225makeTranslate : V3 -> M4x4
258226makeTranslate = Native.MJS.m4x4makeTranslate
@@ -273,7 +241,7 @@ translate = Native.MJS.m4x4translate
273241Creates a transformation matrix for a camera.
274242
275243Parameters:
276−
244+
277245 * eye - The location of the camera
278246 * center - The location of the focused object
279247 * up - The "up" direction according to the camera
@@ -281,14 +249,13 @@ Parameters:
281249makeLookAt : V3 -> V3 -> V3 -> M4x4
282250makeLookAt = Native.MJS.m4x4makeLookAt
283251
284−{-|
285−"Flip" the matrix across the diagonal by swapping row index and column index.
252+{-| "Flip" the matrix across the diagonal by swapping row index and column
253+index.
286254-}
287255transpose : M4x4 -> M4x4
288256transpose = Native.MJS.m4x4transpose
289257
290−{-|
291−Creates a transform from a basis consisting of 3 linearly independent vectors.
258+{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
292259-}
293260makeBasis : V3 -> V3 -> V3 -> M4x4
294261makeBasis = Native.MJS.m4x4makeBasis