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

# SCM Repository

[sml3d] Diff of /src/common/sml3d-type-util.sml
 [sml3d] / src / common / sml3d-type-util.sml

# Diff of /src/common/sml3d-type-util.sml

revision 19, Mon Feb 18 17:47:01 2008 UTC revision 20, Mon Feb 18 18:20:34 2008 UTC
# Line 6  Line 6
6   * Utility functions on the various vector types.   * Utility functions on the various vector types.
7   *)   *)
8
9  structure SML3DTypeUtil : GL_TYPE_UTIL =  structure SML3dTypeUtil : SML3D_TYPE_UTIL =
10    struct    struct
11
12      open SML3DTypes      open SML3dTypes
13
14    (* pack tuples as records *)    (* pack tuples as records *)
15      fun packv2 (x, y)           = {x=x, y=y}      fun packv2 (x, y)           = {x=x, y=y}
# Line 36  Line 36
36      fun unpackc4 {r, g, b, a}   = (r, g, b, a)      fun unpackc4 {r, g, b, a}   = (r, g, b, a)
37
38    (* iterators *)    (* iterators *)
39      fun mapv2 f {x, y, z, w} = {x = f x, y = f y}      fun mapv2 f {x, y} = {x = f x, y = f y}
40      fun mapv3 f {x, y, z, w} = {x = f x, y = f y, z = f z}      fun mapv3 f {x, y, z} = {x = f x, y = f y, z = f z}
41      fun mapv4 f {x, y, z, w} = {x = f x, y = f y, z = f z, w = f w}      fun mapv4 f {x, y, z, w} = {x = f x, y = f y, z = f z, w = f w}
42
43      fun mapt2 f {s, t} = {s = f s, t = f t}      fun mapt2 f {s, t} = {s = f s, t = f t}
# Line 47  Line 47
47      fun mapc3 f {r, g, b} = {r = f r, g = f g, b = f b}      fun mapc3 f {r, g, b} = {r = f r, g = f g, b = f b}
48      fun mapc4 f {r, g, b, a} = {r = f r, g = f g, b = f b, a = f a}      fun mapc4 f {r, g, b, a} = {r = f r, g = f g, b = f b, a = f a}
49
50      fun appv2 f {x, y} = (f x; f y)      fun appv2 (f : 'a -> unit) {x, y} = (f x; f y)
51      fun appv3 f {x, y, z} = (f x; f y; f z)      fun appv3 (f : 'a -> unit) {x, y, z} = (f x; f y; f z)
52      fun appv4 f {x, y, z, w} = (f x; f y; f z; f w)      fun appv4 (f : 'a -> unit) {x, y, z, w} = (f x; f y; f z; f w)
53
54      fun appt2 f {s, t} = (s = f s; t = f t)      fun appt2 (f : 'a -> unit) {s, t} = (f s; f t)
55      fun appt3 f {s, t, r} = (s = f s; t = f t; r = f r)      fun appt3 (f : 'a -> unit) {s, t, r} = (f s; f t; f r)
56      fun appt4 f {s, t, r, q} = (s = f s; t = f t; r = f r; q = f q)      fun appt4 (f : 'a -> unit) {s, t, r, q} = (f s; f t; f r; f q)
57
58      fun appc3 f {r, g, b} = (r = f r; g = f g; b = f b)      fun appc3 (f : 'a -> unit) {r, g, b} = (f r; f g; f b)
59      fun appc4 f {r, g, b, a} = (r = f r; g = f g; b = f b; a = f a)      fun appc4 (f : 'a -> unit) {r, g, b, a} = (f r; f g; f b; f a)
60
61      (* string representations *)
62        fun fmtv2 fmt {x, y} = String.concat[
63                "{x=", fmt x, ", y=", fmt y, "}"
64              ]
65        fun fmtv3 fmt {x, y, z} = String.concat[
66                "{x=", fmt x, ", y=", fmt y, ", z=", fmt z, "}"
67              ]
68        fun fmtv4 fmt {x, y, z, w} = String.concat[
69                "{x=", fmt x, ", y=", fmt y, ", z=", fmt z, ", w=", fmt w, "}"
70              ]
71
72        fun fmtt2 fmt {s, t} = String.concat[
73                "{s=", fmt s, ", t=", fmt t, "}"
74              ]
75        fun fmtt3 fmt {s, t, r} = String.concat[
76                "{s=", fmt s, ", t=", fmt t, ", r=", fmt r, "}"
77              ]
78        fun fmtt4 fmt {s, t, r, q} = String.concat[
79                "{s=", fmt s, ", t=", fmt t, ", r=", fmt r, ", q=", fmt q, "}"
80              ]
81
82        fun fmtc3 fmt {r,g,b} = String.concat[
83                "{r=", fmt r, ", g=", fmt g, ", b=", fmt b, "}"
84              ]
85        fun fmtc4 fmt {r, g, b, a} = String.concat[
86                "{r=", fmt r, ", g=", fmt g, ", b=", fmt b, ", a=", fmt a, "}"
87              ]
88
89        fun fmt2 fmt (a, b) = String.concat["(", fmt a, ", ", fmt b, ")"]
90        fun fmt3 fmt (a, b, c) = String.concat[
91                "(", fmt a, ", ", fmt b, ", ", fmt c, ")"
92              ]
93        fun fmt4 fmt (a, b, c, d) = String.concat[
94                "(", fmt a, ", ", fmt b, ", ", fmt c, ", ", fmt d, ")"
95              ]
96
97    end    end

Legend:
 Removed from v.19 changed lines Added in v.20