elm-community / linear-algebra

Fast Linear Algebra for Elm.
http://package.elm-lang.org/packages/elm-community/linear-algebra/latest
BSD 3-Clause "New" or "Revised" License
14 stars 9 forks source link

Convertors for Mat4 type #11

Closed w0rm closed 7 years ago

w0rm commented 7 years ago

All types in linear algebra, except Mat4 may be constructed from floats and deconstructed back.

I need to get the raw data out of Mat4 for the CSS3D transforms in this example: https://github.com/w0rm/elm-webgl-playground/blob/master/CSS3d.elm

fredcy commented 7 years ago

Sounds reasonable to me. Do you have a particular API in mind?

w0rm commented 7 years ago

@fredcy the problem with Mat4 is that it contains more values than we can have in a Tuple, but should work just fine with a record type.

mat4 : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
toRecord : Mat4 -> Mat4Record
fromRecord : Mat4Record -> Mat4
type alias Mat4Record =
    { m11 : Float
    , m21 : Float
    , m31 : Float
    , m41 : Float
    , m12 : Float
    , m22 : Float
    , m32 : Float
    , m42 : Float
    , m13 : Float
    , m23 : Float
    , m33 : Float
    , m43 : Float
    , m14 : Float
    , m24 : Float
    , m34 : Float
    , m44 : Float
    }
fredcy commented 7 years ago

Can you float this API plan to the Elm WebGL community (and/or other users of this package) and get some feedback on whether it's the right one?

felixLam commented 7 years ago

I have added a constructor a while back: makeFromList not sure if that helps. But yeah a record would also be nice as this does somewhat away with the question of how the col/rows are aligned in the list.

w0rm commented 7 years ago

@felixLam oh, I've missed it, because I assumed that all the make... functions were generating Mat4 and not taking the raw values.

w0rm commented 7 years ago

Summarizing the discussion here and on Slack, fromRecord/toRecord is good, because:

  1. it is consistent with the rest modules from this package
  2. it names the order of the cols/rows
  3. it forces to provide all the values (while List may have more or less values, so it is uncertain)
  4. record has a faster access

I got Ok from @eeue56 and @Zinggi so I will open a pull request.