source: 2014/24/EemeliK/Zombieland/Jypeli/AdvanceMath/IO/MathWriter.cs @ 5974

Revision 5974, 3.9 KB checked in by empaheik, 4 years ago (diff)
Line 
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26
27#if UseDouble
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32using System;
33using System.IO;
34using System.Text;
35
36namespace AdvanceMath.IO
37{
38    public class MathWriter : BinaryWriter
39    {
40        protected static Stream GetBaseStream(BinaryWriter writer)
41        {
42            if (writer == null) { throw new ArgumentNullException("writer"); }
43            return writer.BaseStream;
44        }
45        public MathWriter(Stream output)
46            : base(output) { }
47        public MathWriter(Stream output, Encoding encoding)
48            : base(output, encoding) { }
49        public MathWriter(BinaryWriter writer)
50            : base(GetBaseStream(writer)) { }
51        public void Write(Vector2D value)
52        {
53            Write(value.X);
54            Write(value.Y);
55        }
56        public void Write(Vector3D value)
57        {
58            Write(value.X);
59            Write(value.Y);
60            Write(value.Z);
61        }
62        public void Write(Vector4D value)
63        {
64            Write(value.X);
65            Write(value.Y);
66            Write(value.Z);
67            Write(value.W);
68        }
69        public void Write(Quaternion value)
70        {
71            Write(value.X);
72            Write(value.Y);
73            Write(value.Z);
74            Write(value.W);
75        }
76        public void Write(Matrix2x2 value)
77        {
78            Write(value.m00);
79            Write(value.m01);
80
81            Write(value.m10);
82            Write(value.m11);
83        }
84        public void Write(Matrix3x3 value)
85        {
86            Write(value.m00);
87            Write(value.m01);
88            Write(value.m02);
89
90            Write(value.m10);
91            Write(value.m11);
92            Write(value.m12);
93
94            Write(value.m20);
95            Write(value.m21);
96            Write(value.m22);
97        }
98        public void Write(Matrix4x4 value)
99        {
100            Write(value.m00);
101            Write(value.m01);
102            Write(value.m02);
103            Write(value.m03);
104
105            Write(value.m10);
106            Write(value.m11);
107            Write(value.m12);
108            Write(value.m13);
109
110            Write(value.m20);
111            Write(value.m21);
112            Write(value.m22);
113            Write(value.m23);
114
115            Write(value.m30);
116            Write(value.m31);
117            Write(value.m32);
118            Write(value.m33);
119        }
120        public void Write(Scalar[] array)
121        {
122            if (array == null) { throw new ArgumentNullException("array"); }
123            Write(array.Length);
124            for (int index = 0; index < array.Length; index++)
125            {
126                Write(array[index]);
127            }
128        }
129    }
130}
Note: See TracBrowser for help on using the repository browser.