Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /src/common/vec4.sml
ViewVC logotype

View of /src/common/vec4.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 37 - (download) (annotate)
Thu Mar 13 14:29:38 2008 UTC (11 years, 8 months ago) by jhr
File size: 878 byte(s)
  Merged math library into common; fixed type errors in ONB code
(* vec4.sml
 * COPYRIGHT (c) 2008 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.
 * Some common structural operations on 4-element vectors.

structure Vec4 =

    fun unpack {x, y, z, w} = (x, y, z, w)
    fun pack (x, y, z, w) = {x=x, y=y, z=z, w=w}
    fun toList {x, y, z, w} = [x, y, z, w]

    fun setX ({x, y, z, w}, v) = {x=v, y=y, z=z, w=w}
    fun setY ({x, y, z, w}, v) = {x=x, y=v, z=z, w=w}
    fun setZ ({x, y, z, w}, v) = {x=x, y=y, z=v, w=w}
    fun setW ({x, y, z, w}, v) = {x=x, y=y, z=w, w=v}

    fun nth ({x, y, z, w}, 0) = x
      | nth ({x, y, z, w}, 1) = y
      | nth ({x, y, z, w}, 2) = z
      | nth ({x, y, z, w}, 3) = w
      | nth _ = raise Subscript

  (* iterators *)
    fun map f {x, y, z, w} = {x = f x, y = f y, z = f z, w = f w}
    fun app (f : 'a -> unit) {x, y, z, w} = (f x; f y; f z; f w)


ViewVC Help
Powered by ViewVC 1.0.0