diff options
author | Teravus Ovares | 2008-05-30 12:27:06 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-05-30 12:27:06 +0000 |
commit | 1a47ff8094ee414a47aebd310826906d89428a09 (patch) | |
tree | 0e90b3a33f43ff8617a077bb57b86d6b28e63e71 /OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs | |
parent | * Fixed a dangling event hook that I added. (diff) | |
download | opensim-SC_OLD-1a47ff8094ee414a47aebd310826906d89428a09.zip opensim-SC_OLD-1a47ff8094ee414a47aebd310826906d89428a09.tar.gz opensim-SC_OLD-1a47ff8094ee414a47aebd310826906d89428a09.tar.bz2 opensim-SC_OLD-1a47ff8094ee414a47aebd310826906d89428a09.tar.xz |
* This is Melanie's XEngine script engine. I've not tested this real well, however, it's confirmed to compile and OpenSimulator to run successfully without this script engine active.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs | 1411 |
1 files changed, 1411 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs b/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs new file mode 100644 index 0000000..2d5d2b8 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs | |||
@@ -0,0 +1,1411 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Text.RegularExpressions; | ||
31 | |||
32 | namespace OpenSim.Region.ScriptEngine.XEngine.Script | ||
33 | { | ||
34 | [Serializable] | ||
35 | public partial class LSL_Types | ||
36 | { | ||
37 | // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain | ||
38 | |||
39 | [Serializable] | ||
40 | public struct Vector3 | ||
41 | { | ||
42 | public double x; | ||
43 | public double y; | ||
44 | public double z; | ||
45 | |||
46 | #region Constructors | ||
47 | |||
48 | public Vector3(Vector3 vector) | ||
49 | { | ||
50 | x = (float)vector.x; | ||
51 | y = (float)vector.y; | ||
52 | z = (float)vector.z; | ||
53 | } | ||
54 | |||
55 | public Vector3(double X, double Y, double Z) | ||
56 | { | ||
57 | x = X; | ||
58 | y = Y; | ||
59 | z = Z; | ||
60 | } | ||
61 | |||
62 | public Vector3(string str) | ||
63 | { | ||
64 | str = str.Replace('<', ' '); | ||
65 | str = str.Replace('>', ' '); | ||
66 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | ||
67 | if (tmps.Length < 3) | ||
68 | { | ||
69 | x=y=z=0; | ||
70 | return; | ||
71 | } | ||
72 | bool res; | ||
73 | res = Double.TryParse(tmps[0], out x); | ||
74 | res = res & Double.TryParse(tmps[1], out y); | ||
75 | res = res & Double.TryParse(tmps[2], out z); | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | |||
80 | #region Overriders | ||
81 | |||
82 | public override string ToString() | ||
83 | { | ||
84 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); | ||
85 | return s; | ||
86 | } | ||
87 | |||
88 | public static explicit operator LSLString(Vector3 vec) | ||
89 | { | ||
90 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | ||
91 | return new LSLString(s); | ||
92 | } | ||
93 | |||
94 | public static explicit operator string(Vector3 vec) | ||
95 | { | ||
96 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | ||
97 | return s; | ||
98 | } | ||
99 | |||
100 | public static explicit operator Vector3(string s) | ||
101 | { | ||
102 | return new Vector3(s); | ||
103 | } | ||
104 | |||
105 | public static bool operator ==(Vector3 lhs, Vector3 rhs) | ||
106 | { | ||
107 | return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); | ||
108 | } | ||
109 | |||
110 | public static bool operator !=(Vector3 lhs, Vector3 rhs) | ||
111 | { | ||
112 | return !(lhs == rhs); | ||
113 | } | ||
114 | |||
115 | public override int GetHashCode() | ||
116 | { | ||
117 | return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode()); | ||
118 | } | ||
119 | |||
120 | public override bool Equals(object o) | ||
121 | { | ||
122 | if (!(o is Vector3)) return false; | ||
123 | |||
124 | Vector3 vector = (Vector3)o; | ||
125 | |||
126 | return (x == vector.x && x == vector.x && z == vector.z); | ||
127 | } | ||
128 | |||
129 | #endregion | ||
130 | |||
131 | #region Vector & Vector Math | ||
132 | |||
133 | // Vector-Vector Math | ||
134 | public static Vector3 operator +(Vector3 lhs, Vector3 rhs) | ||
135 | { | ||
136 | return new Vector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z); | ||
137 | } | ||
138 | |||
139 | public static Vector3 operator -(Vector3 lhs, Vector3 rhs) | ||
140 | { | ||
141 | return new Vector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z); | ||
142 | } | ||
143 | |||
144 | public static Vector3 operator *(Vector3 lhs, Vector3 rhs) | ||
145 | { | ||
146 | return new Vector3(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z); | ||
147 | } | ||
148 | |||
149 | public static Vector3 operator %(Vector3 v1, Vector3 v2) | ||
150 | { | ||
151 | //Cross product | ||
152 | Vector3 tv; | ||
153 | tv.x = (v1.y * v2.z) - (v1.z * v2.y); | ||
154 | tv.y = (v1.z * v2.x) - (v1.x * v2.z); | ||
155 | tv.z = (v1.x * v2.y) - (v1.y * v2.x); | ||
156 | return tv; | ||
157 | } | ||
158 | |||
159 | #endregion | ||
160 | |||
161 | #region Vector & Float Math | ||
162 | |||
163 | // Vector-Float and Float-Vector Math | ||
164 | public static Vector3 operator *(Vector3 vec, float val) | ||
165 | { | ||
166 | return new Vector3(vec.x * val, vec.y * val, vec.z * val); | ||
167 | } | ||
168 | |||
169 | public static Vector3 operator *(float val, Vector3 vec) | ||
170 | { | ||
171 | return new Vector3(vec.x * val, vec.y * val, vec.z * val); | ||
172 | } | ||
173 | |||
174 | public static Vector3 operator /(Vector3 v, float f) | ||
175 | { | ||
176 | v.x = v.x / f; | ||
177 | v.y = v.y / f; | ||
178 | v.z = v.z / f; | ||
179 | return v; | ||
180 | } | ||
181 | |||
182 | #endregion | ||
183 | |||
184 | #region Vector & Double Math | ||
185 | |||
186 | public static Vector3 operator *(Vector3 vec, double val) | ||
187 | { | ||
188 | return new Vector3(vec.x * val, vec.y * val, vec.z * val); | ||
189 | } | ||
190 | |||
191 | public static Vector3 operator *(double val, Vector3 vec) | ||
192 | { | ||
193 | return new Vector3(vec.x * val, vec.y * val, vec.z * val); | ||
194 | } | ||
195 | |||
196 | public static Vector3 operator /(Vector3 v, double f) | ||
197 | { | ||
198 | v.x = v.x / f; | ||
199 | v.y = v.y / f; | ||
200 | v.z = v.z / f; | ||
201 | return v; | ||
202 | } | ||
203 | |||
204 | #endregion | ||
205 | |||
206 | #region Vector & Rotation Math | ||
207 | |||
208 | // Vector-Rotation Math | ||
209 | public static Vector3 operator *(Vector3 v, Quaternion r) | ||
210 | { | ||
211 | Quaternion vq = new Quaternion(v.x, v.y, v.z, 0); | ||
212 | Quaternion nq = new Quaternion(-r.x, -r.y, -r.z, r.s); | ||
213 | |||
214 | // adapted for operator * computing "b * a" | ||
215 | Quaternion result = nq * (vq * r); | ||
216 | |||
217 | return new Vector3(result.x, result.y, result.z); | ||
218 | } | ||
219 | |||
220 | public static Vector3 operator /(Vector3 v, Quaternion r) | ||
221 | { | ||
222 | r.s = -r.s; | ||
223 | return v * r; | ||
224 | } | ||
225 | |||
226 | #endregion | ||
227 | |||
228 | #region Static Helper Functions | ||
229 | |||
230 | public static double Dot(Vector3 v1, Vector3 v2) | ||
231 | { | ||
232 | return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z); | ||
233 | } | ||
234 | |||
235 | public static Vector3 Cross(Vector3 v1, Vector3 v2) | ||
236 | { | ||
237 | return new Vector3 | ||
238 | ( | ||
239 | v1.y * v2.z - v1.z * v2.y, | ||
240 | v1.z * v2.x - v1.x * v2.z, | ||
241 | v1.x * v2.y - v1.y * v2.x | ||
242 | ); | ||
243 | } | ||
244 | |||
245 | public static double Mag(Vector3 v) | ||
246 | { | ||
247 | return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); | ||
248 | } | ||
249 | |||
250 | public static Vector3 Norm(Vector3 vector) | ||
251 | { | ||
252 | double mag = Mag(vector); | ||
253 | return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag); | ||
254 | } | ||
255 | |||
256 | #endregion | ||
257 | } | ||
258 | |||
259 | [Serializable] | ||
260 | public struct Quaternion | ||
261 | { | ||
262 | public double x; | ||
263 | public double y; | ||
264 | public double z; | ||
265 | public double s; | ||
266 | |||
267 | #region Constructors | ||
268 | |||
269 | public Quaternion(Quaternion Quat) | ||
270 | { | ||
271 | x = (float)Quat.x; | ||
272 | y = (float)Quat.y; | ||
273 | z = (float)Quat.z; | ||
274 | s = (float)Quat.s; | ||
275 | if (x == 0 && y == 0 && z == 0 && s == 0) | ||
276 | s = 1; | ||
277 | } | ||
278 | |||
279 | public Quaternion(double X, double Y, double Z, double S) | ||
280 | { | ||
281 | x = X; | ||
282 | y = Y; | ||
283 | z = Z; | ||
284 | s = S; | ||
285 | if (x == 0 && y == 0 && z == 0 && s == 0) | ||
286 | s = 1; | ||
287 | } | ||
288 | |||
289 | public Quaternion(string str) | ||
290 | { | ||
291 | str = str.Replace('<', ' '); | ||
292 | str = str.Replace('>', ' '); | ||
293 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | ||
294 | if (tmps.Length < 4) | ||
295 | { | ||
296 | x=y=z=s=0; | ||
297 | return; | ||
298 | } | ||
299 | bool res; | ||
300 | res = Double.TryParse(tmps[0], out x); | ||
301 | res = res & Double.TryParse(tmps[1], out y); | ||
302 | res = res & Double.TryParse(tmps[2], out z); | ||
303 | res = res & Double.TryParse(tmps[3], out s); | ||
304 | if (x == 0 && y == 0 && z == 0 && s == 0) | ||
305 | s = 1; | ||
306 | } | ||
307 | |||
308 | #endregion | ||
309 | |||
310 | #region Overriders | ||
311 | |||
312 | public override int GetHashCode() | ||
313 | { | ||
314 | return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode() ^ s.GetHashCode()); | ||
315 | } | ||
316 | |||
317 | public override bool Equals(object o) | ||
318 | { | ||
319 | if (!(o is Quaternion)) return false; | ||
320 | |||
321 | Quaternion quaternion = (Quaternion)o; | ||
322 | |||
323 | return x == quaternion.x && y == quaternion.y && z == quaternion.z && s == quaternion.s; | ||
324 | } | ||
325 | |||
326 | public override string ToString() | ||
327 | { | ||
328 | string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); | ||
329 | return st; | ||
330 | } | ||
331 | |||
332 | public static explicit operator string(Quaternion r) | ||
333 | { | ||
334 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | ||
335 | return s; | ||
336 | } | ||
337 | |||
338 | public static explicit operator LSLString(Quaternion r) | ||
339 | { | ||
340 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | ||
341 | return new LSLString(s); | ||
342 | } | ||
343 | |||
344 | public static explicit operator Quaternion(string s) | ||
345 | { | ||
346 | return new Quaternion(s); | ||
347 | } | ||
348 | |||
349 | public static bool operator ==(Quaternion lhs, Quaternion rhs) | ||
350 | { | ||
351 | // Return true if the fields match: | ||
352 | return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.s == rhs.s; | ||
353 | } | ||
354 | |||
355 | public static bool operator !=(Quaternion lhs, Quaternion rhs) | ||
356 | { | ||
357 | return !(lhs == rhs); | ||
358 | } | ||
359 | |||
360 | #endregion | ||
361 | |||
362 | public static Quaternion operator +(Quaternion a, Quaternion b) | ||
363 | { | ||
364 | return new Quaternion(a.x + b.x, a.y + b.y, a.z + b.z, a.s + b.s); | ||
365 | } | ||
366 | |||
367 | public static Quaternion operator /(Quaternion a, Quaternion b) | ||
368 | { | ||
369 | b.s = -b.s; | ||
370 | return a * b; | ||
371 | } | ||
372 | |||
373 | public static Quaternion operator -(Quaternion a, Quaternion b) | ||
374 | { | ||
375 | return new Quaternion(a.x - b.x, a.y - b.y, a.z - b.z, a.s - b.s); | ||
376 | } | ||
377 | |||
378 | // using the equations below, we need to do "b * a" to be compatible with LSL | ||
379 | public static Quaternion operator *(Quaternion b, Quaternion a) | ||
380 | { | ||
381 | Quaternion c; | ||
382 | c.x = a.s * b.x + a.x * b.s + a.y * b.z - a.z * b.y; | ||
383 | c.y = a.s * b.y + a.y * b.s + a.z * b.x - a.x * b.z; | ||
384 | c.z = a.s * b.z + a.z * b.s + a.x * b.y - a.y * b.x; | ||
385 | c.s = a.s * b.s - a.x * b.x - a.y * b.y - a.z * b.z; | ||
386 | return c; | ||
387 | } | ||
388 | } | ||
389 | |||
390 | [Serializable] | ||
391 | public class list | ||
392 | { | ||
393 | private object[] m_data; | ||
394 | |||
395 | public list(params object[] args) | ||
396 | { | ||
397 | m_data = new object[args.Length]; | ||
398 | m_data = args; | ||
399 | } | ||
400 | |||
401 | public int Length | ||
402 | { | ||
403 | get { | ||
404 | if (m_data == null) | ||
405 | m_data=new Object[0]; | ||
406 | return m_data.Length; | ||
407 | } | ||
408 | } | ||
409 | |||
410 | public object[] Data | ||
411 | { | ||
412 | get { | ||
413 | if (m_data == null) | ||
414 | m_data=new Object[0]; | ||
415 | return m_data; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | public static list operator +(list a, list b) | ||
420 | { | ||
421 | object[] tmp; | ||
422 | tmp = new object[a.Length + b.Length]; | ||
423 | a.Data.CopyTo(tmp, 0); | ||
424 | b.Data.CopyTo(tmp, a.Length); | ||
425 | return new list(tmp); | ||
426 | } | ||
427 | |||
428 | public void Add(object o) | ||
429 | { | ||
430 | object[] tmp; | ||
431 | tmp = new object[m_data.Length + 1]; | ||
432 | m_data.CopyTo(tmp, 0); | ||
433 | tmp[m_data.Length] = o; | ||
434 | m_data = tmp; | ||
435 | } | ||
436 | |||
437 | public bool Contains(object o) | ||
438 | { | ||
439 | bool ret = false; | ||
440 | foreach (object i in Data) | ||
441 | { | ||
442 | if (i == o) | ||
443 | { | ||
444 | ret = true; | ||
445 | break; | ||
446 | } | ||
447 | } | ||
448 | return ret; | ||
449 | } | ||
450 | |||
451 | public list DeleteSublist(int start, int end) | ||
452 | { | ||
453 | // Not an easy one | ||
454 | // If start <= end, remove that part | ||
455 | // if either is negative, count from the end of the array | ||
456 | // if the resulting start > end, remove all BUT that part | ||
457 | |||
458 | Object[] ret; | ||
459 | |||
460 | if (start < 0) | ||
461 | start=m_data.Length-start; | ||
462 | |||
463 | if (start < 0) | ||
464 | start=0; | ||
465 | |||
466 | if (end < 0) | ||
467 | end=m_data.Length-end; | ||
468 | if (end < 0) | ||
469 | end=0; | ||
470 | |||
471 | if (start > end) | ||
472 | { | ||
473 | if (end >= m_data.Length) | ||
474 | return new list(new Object[0]); | ||
475 | |||
476 | if (start >= m_data.Length) | ||
477 | start=m_data.Length-1; | ||
478 | |||
479 | return GetSublist(end, start); | ||
480 | } | ||
481 | |||
482 | // start >= 0 && end >= 0 here | ||
483 | if (start >= m_data.Length) | ||
484 | { | ||
485 | ret=new Object[m_data.Length]; | ||
486 | Array.Copy(m_data, 0, ret, 0, m_data.Length); | ||
487 | |||
488 | return new list(ret); | ||
489 | } | ||
490 | |||
491 | if (end >= m_data.Length) | ||
492 | end=m_data.Length-1; | ||
493 | |||
494 | // now, this makes the math easier | ||
495 | int remove=end+1-start; | ||
496 | |||
497 | ret=new Object[m_data.Length-remove]; | ||
498 | if (ret.Length == 0) | ||
499 | return new list(ret); | ||
500 | |||
501 | int src; | ||
502 | int dest=0; | ||
503 | |||
504 | for (src = 0; src < m_data.Length; src++) | ||
505 | { | ||
506 | if (src < start || src > end) | ||
507 | ret[dest++]=m_data[src]; | ||
508 | } | ||
509 | |||
510 | return new list(ret); | ||
511 | } | ||
512 | |||
513 | public list GetSublist(int start, int end) | ||
514 | { | ||
515 | |||
516 | object[] ret; | ||
517 | |||
518 | // Take care of neg start or end's | ||
519 | // NOTE that either index may still be negative after | ||
520 | // adding the length, so we must take additional | ||
521 | // measures to protect against this. Note also that | ||
522 | // after normalisation the negative indices are no | ||
523 | // longer relative to the end of the list. | ||
524 | |||
525 | if (start < 0) | ||
526 | { | ||
527 | start = m_data.Length + start; | ||
528 | } | ||
529 | |||
530 | if (end < 0) | ||
531 | { | ||
532 | end = m_data.Length + end; | ||
533 | } | ||
534 | |||
535 | // The conventional case is start <= end | ||
536 | // NOTE that the case of an empty list is | ||
537 | // dealt with by the initial test. Start | ||
538 | // less than end is taken to be the most | ||
539 | // common case. | ||
540 | |||
541 | if (start <= end) | ||
542 | { | ||
543 | |||
544 | // Start sublist beyond length | ||
545 | // Also deals with start AND end still negative | ||
546 | if (start >= m_data.Length || end < 0) | ||
547 | { | ||
548 | return new list(); | ||
549 | } | ||
550 | |||
551 | // Sublist extends beyond the end of the supplied list | ||
552 | if (end >= m_data.Length) | ||
553 | { | ||
554 | end = m_data.Length - 1; | ||
555 | } | ||
556 | |||
557 | // Sublist still starts before the beginning of the list | ||
558 | if (start < 0) | ||
559 | { | ||
560 | start = 0; | ||
561 | } | ||
562 | |||
563 | ret = new object[end - start + 1]; | ||
564 | |||
565 | Array.Copy(m_data, start, ret, 0, end - start + 1); | ||
566 | |||
567 | return new list(ret); | ||
568 | |||
569 | } | ||
570 | |||
571 | // Deal with the segmented case: 0->end + start->EOL | ||
572 | |||
573 | else | ||
574 | { | ||
575 | |||
576 | list result = null; | ||
577 | |||
578 | // If end is negative, then prefix list is empty | ||
579 | if (end < 0) | ||
580 | { | ||
581 | result = new list(); | ||
582 | // If start is still negative, then the whole of | ||
583 | // the existing list is returned. This case is | ||
584 | // only admitted if end is also still negative. | ||
585 | if (start < 0) | ||
586 | { | ||
587 | return this; | ||
588 | } | ||
589 | |||
590 | } | ||
591 | else | ||
592 | { | ||
593 | result = GetSublist(0,end); | ||
594 | } | ||
595 | |||
596 | // If start is outside of list, then just return | ||
597 | // the prefix, whatever it is. | ||
598 | if (start >= m_data.Length) | ||
599 | { | ||
600 | return result; | ||
601 | } | ||
602 | |||
603 | return result + GetSublist(start, Data.Length); | ||
604 | |||
605 | } | ||
606 | } | ||
607 | |||
608 | public list Sort(int stride, int ascending) | ||
609 | { | ||
610 | if (Data.Length == 0) | ||
611 | return new list(); // Don't even bother | ||
612 | |||
613 | string[] keys; | ||
614 | |||
615 | if (stride == 1) // The simple case | ||
616 | { | ||
617 | Object[] ret=new Object[Data.Length]; | ||
618 | |||
619 | Array.Copy(Data, 0, ret, 0, Data.Length); | ||
620 | |||
621 | keys=new string[Data.Length]; | ||
622 | |||
623 | for (int k = 0; k < Data.Length; k++) | ||
624 | keys[k] = Data[k].ToString(); | ||
625 | |||
626 | Array.Sort(keys, ret); | ||
627 | |||
628 | if (ascending == 0) | ||
629 | Array.Reverse(ret); | ||
630 | return new list(ret); | ||
631 | } | ||
632 | |||
633 | int src=0; | ||
634 | |||
635 | int len=(Data.Length+stride-1)/stride; | ||
636 | |||
637 | keys=new string[len]; | ||
638 | Object[][] vals=new Object[len][]; | ||
639 | |||
640 | int i; | ||
641 | |||
642 | while (src < Data.Length) | ||
643 | { | ||
644 | Object[] o=new Object[stride]; | ||
645 | |||
646 | for (i = 0; i < stride; i++) | ||
647 | { | ||
648 | if (src < Data.Length) | ||
649 | o[i]=Data[src++]; | ||
650 | else | ||
651 | { | ||
652 | o[i]=new Object(); | ||
653 | src++; | ||
654 | } | ||
655 | } | ||
656 | |||
657 | int idx=src/stride-1; | ||
658 | keys[idx]=o[0].ToString(); | ||
659 | vals[idx]=o; | ||
660 | } | ||
661 | |||
662 | Array.Sort(keys, vals); | ||
663 | if (ascending == 0) | ||
664 | { | ||
665 | Array.Reverse(vals); | ||
666 | } | ||
667 | |||
668 | Object[] sorted=new Object[stride*vals.Length]; | ||
669 | |||
670 | for (i = 0; i < vals.Length; i++) | ||
671 | for (int j = 0; j < stride; j++) | ||
672 | sorted[i*stride+j] = vals[i][j]; | ||
673 | |||
674 | return new list(sorted); | ||
675 | } | ||
676 | |||
677 | #region CSV Methods | ||
678 | |||
679 | public static list FromCSV(string csv) | ||
680 | { | ||
681 | return new list(csv.Split(',')); | ||
682 | } | ||
683 | |||
684 | public string ToCSV() | ||
685 | { | ||
686 | string ret = ""; | ||
687 | foreach (object o in this.Data) | ||
688 | { | ||
689 | if (ret == "") | ||
690 | { | ||
691 | ret = o.ToString(); | ||
692 | } | ||
693 | else | ||
694 | { | ||
695 | ret = ret + ", " + o.ToString(); | ||
696 | } | ||
697 | } | ||
698 | return ret; | ||
699 | } | ||
700 | |||
701 | private string ToSoup() | ||
702 | { | ||
703 | string output; | ||
704 | output = String.Empty; | ||
705 | if (m_data.Length == 0) | ||
706 | { | ||
707 | return String.Empty; | ||
708 | } | ||
709 | foreach (object o in m_data) | ||
710 | { | ||
711 | output = output + o.ToString(); | ||
712 | } | ||
713 | return output; | ||
714 | } | ||
715 | |||
716 | public static explicit operator String(list l) | ||
717 | { | ||
718 | return l.ToSoup(); | ||
719 | } | ||
720 | |||
721 | public static explicit operator LSLString(list l) | ||
722 | { | ||
723 | return new LSLString(l.ToSoup()); | ||
724 | } | ||
725 | |||
726 | public override string ToString() | ||
727 | { | ||
728 | return ToSoup(); | ||
729 | } | ||
730 | |||
731 | #endregion | ||
732 | |||
733 | #region Statistic Methods | ||
734 | |||
735 | public double Min() | ||
736 | { | ||
737 | double minimum = double.PositiveInfinity; | ||
738 | double entry; | ||
739 | for (int i = 0; i < Data.Length; i++) | ||
740 | { | ||
741 | if (double.TryParse(Data[i].ToString(), out entry)) | ||
742 | { | ||
743 | if (entry < minimum) minimum = entry; | ||
744 | } | ||
745 | } | ||
746 | return minimum; | ||
747 | } | ||
748 | |||
749 | public double Max() | ||
750 | { | ||
751 | double maximum = double.NegativeInfinity; | ||
752 | double entry; | ||
753 | for (int i = 0; i < Data.Length; i++) | ||
754 | { | ||
755 | if (double.TryParse(Data[i].ToString(), out entry)) | ||
756 | { | ||
757 | if (entry > maximum) maximum = entry; | ||
758 | } | ||
759 | } | ||
760 | return maximum; | ||
761 | } | ||
762 | |||
763 | public double Range() | ||
764 | { | ||
765 | return (this.Max() / this.Min()); | ||
766 | } | ||
767 | |||
768 | public int NumericLength() | ||
769 | { | ||
770 | int count = 0; | ||
771 | double entry; | ||
772 | for (int i = 0; i < Data.Length; i++) | ||
773 | { | ||
774 | if (double.TryParse(Data[i].ToString(), out entry)) | ||
775 | { | ||
776 | count++; | ||
777 | } | ||
778 | } | ||
779 | return count; | ||
780 | } | ||
781 | |||
782 | public static list ToDoubleList(list src) | ||
783 | { | ||
784 | list ret = new list(); | ||
785 | double entry; | ||
786 | for (int i = 0; i < src.Data.Length - 1; i++) | ||
787 | { | ||
788 | if (double.TryParse(src.Data[i].ToString(), out entry)) | ||
789 | { | ||
790 | ret.Add(entry); | ||
791 | } | ||
792 | } | ||
793 | return ret; | ||
794 | } | ||
795 | |||
796 | public double Sum() | ||
797 | { | ||
798 | double sum = 0; | ||
799 | double entry; | ||
800 | for (int i = 0; i < Data.Length; i++) | ||
801 | { | ||
802 | if (double.TryParse(Data[i].ToString(), out entry)) | ||
803 | { | ||
804 | sum = sum + entry; | ||
805 | } | ||
806 | } | ||
807 | return sum; | ||
808 | } | ||
809 | |||
810 | public double SumSqrs() | ||
811 | { | ||
812 | double sum = 0; | ||
813 | double entry; | ||
814 | for (int i = 0; i < Data.Length; i++) | ||
815 | { | ||
816 | if (double.TryParse(Data[i].ToString(), out entry)) | ||
817 | { | ||
818 | sum = sum + Math.Pow(entry, 2); | ||
819 | } | ||
820 | } | ||
821 | return sum; | ||
822 | } | ||
823 | |||
824 | public double Mean() | ||
825 | { | ||
826 | return (this.Sum() / this.NumericLength()); | ||
827 | } | ||
828 | |||
829 | public void NumericSort() | ||
830 | { | ||
831 | IComparer Numeric = new NumericComparer(); | ||
832 | Array.Sort(Data, Numeric); | ||
833 | } | ||
834 | |||
835 | public void AlphaSort() | ||
836 | { | ||
837 | IComparer Alpha = new AlphaCompare(); | ||
838 | Array.Sort(Data, Alpha); | ||
839 | } | ||
840 | |||
841 | public double Median() | ||
842 | { | ||
843 | return Qi(0.5); | ||
844 | } | ||
845 | |||
846 | public double GeometricMean() | ||
847 | { | ||
848 | double ret = 1.0; | ||
849 | list nums = ToDoubleList(this); | ||
850 | for (int i = 0; i < nums.Data.Length; i++) | ||
851 | { | ||
852 | ret *= (double)nums.Data[i]; | ||
853 | } | ||
854 | return Math.Exp(Math.Log(ret) / (double)nums.Data.Length); | ||
855 | } | ||
856 | |||
857 | public double HarmonicMean() | ||
858 | { | ||
859 | double ret = 0.0; | ||
860 | list nums = ToDoubleList(this); | ||
861 | for (int i = 0; i < nums.Data.Length; i++) | ||
862 | { | ||
863 | ret += 1.0 / (double)nums.Data[i]; | ||
864 | } | ||
865 | return ((double)nums.Data.Length / ret); | ||
866 | } | ||
867 | |||
868 | public double Variance() | ||
869 | { | ||
870 | double s = 0; | ||
871 | list num = ToDoubleList(this); | ||
872 | for (int i = 0; i < num.Data.Length; i++) | ||
873 | { | ||
874 | s += Math.Pow((double)num.Data[i], 2); | ||
875 | } | ||
876 | return (s - num.Data.Length * Math.Pow(num.Mean(), 2)) / (num.Data.Length - 1); | ||
877 | } | ||
878 | |||
879 | public double StdDev() | ||
880 | { | ||
881 | return Math.Sqrt(this.Variance()); | ||
882 | } | ||
883 | |||
884 | public double Qi(double i) | ||
885 | { | ||
886 | list j = this; | ||
887 | j.NumericSort(); | ||
888 | |||
889 | if (Math.Ceiling(this.Length * i) == this.Length * i) | ||
890 | { | ||
891 | return (double)((double)j.Data[(int)(this.Length * i - 1)] + (double)j.Data[(int)(this.Length * i)]) / 2; | ||
892 | } | ||
893 | else | ||
894 | { | ||
895 | return (double)j.Data[((int)(Math.Ceiling(this.Length * i))) - 1]; | ||
896 | } | ||
897 | } | ||
898 | |||
899 | #endregion | ||
900 | |||
901 | public string ToPrettyString() | ||
902 | { | ||
903 | string output; | ||
904 | if (m_data.Length == 0) | ||
905 | { | ||
906 | return "[]"; | ||
907 | } | ||
908 | output = "["; | ||
909 | foreach (object o in m_data) | ||
910 | { | ||
911 | if (o is String) | ||
912 | { | ||
913 | output = output + "\"" + o + "\", "; | ||
914 | } | ||
915 | else | ||
916 | { | ||
917 | output = output + o.ToString() + ", "; | ||
918 | } | ||
919 | } | ||
920 | output = output.Substring(0, output.Length - 2); | ||
921 | output = output + "]"; | ||
922 | return output; | ||
923 | } | ||
924 | |||
925 | public class AlphaCompare : IComparer | ||
926 | { | ||
927 | int IComparer.Compare(object x, object y) | ||
928 | { | ||
929 | return string.Compare(x.ToString(), y.ToString()); | ||
930 | } | ||
931 | } | ||
932 | |||
933 | public class NumericComparer : IComparer | ||
934 | { | ||
935 | int IComparer.Compare(object x, object y) | ||
936 | { | ||
937 | double a; | ||
938 | double b; | ||
939 | if (!double.TryParse(x.ToString(), out a)) | ||
940 | { | ||
941 | a = 0.0; | ||
942 | } | ||
943 | if (!double.TryParse(y.ToString(), out b)) | ||
944 | { | ||
945 | b = 0.0; | ||
946 | } | ||
947 | if (a < b) | ||
948 | { | ||
949 | return -1; | ||
950 | } | ||
951 | else if (a == b) | ||
952 | { | ||
953 | return 0; | ||
954 | } | ||
955 | else | ||
956 | { | ||
957 | return 1; | ||
958 | } | ||
959 | } | ||
960 | } | ||
961 | |||
962 | } | ||
963 | |||
964 | // | ||
965 | // BELOW IS WORK IN PROGRESS... IT WILL CHANGE, SO DON'T USE YET! :) | ||
966 | // | ||
967 | |||
968 | public struct StringTest | ||
969 | { | ||
970 | // Our own little string | ||
971 | internal string actualString; | ||
972 | public static implicit operator bool(StringTest mString) | ||
973 | { | ||
974 | if (mString.actualString.Length == 0) | ||
975 | return true; | ||
976 | return false; | ||
977 | } | ||
978 | public override string ToString() | ||
979 | { | ||
980 | return actualString; | ||
981 | } | ||
982 | |||
983 | } | ||
984 | |||
985 | [Serializable] | ||
986 | public struct key | ||
987 | { | ||
988 | public string value; | ||
989 | |||
990 | #region Constructors | ||
991 | public key(string s) | ||
992 | { | ||
993 | value = s; | ||
994 | } | ||
995 | |||
996 | #endregion | ||
997 | |||
998 | #region Methods | ||
999 | |||
1000 | static public bool Parse2Key(string s) | ||
1001 | { | ||
1002 | Regex isuuid = new Regex(@"^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$", RegexOptions.Compiled); | ||
1003 | if (isuuid.IsMatch(s)) | ||
1004 | { | ||
1005 | return true; | ||
1006 | } | ||
1007 | else | ||
1008 | { | ||
1009 | return false; | ||
1010 | } | ||
1011 | } | ||
1012 | |||
1013 | #endregion | ||
1014 | |||
1015 | #region Operators | ||
1016 | |||
1017 | static public implicit operator Boolean(key k) | ||
1018 | { | ||
1019 | if (k.value.Length == 0) | ||
1020 | { | ||
1021 | return false; | ||
1022 | } | ||
1023 | |||
1024 | if (k.value == "00000000-0000-0000-0000-000000000000") | ||
1025 | { | ||
1026 | return false; | ||
1027 | } | ||
1028 | Regex isuuid = new Regex(@"^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$", RegexOptions.Compiled); | ||
1029 | if (isuuid.IsMatch(k.value)) | ||
1030 | { | ||
1031 | return true; | ||
1032 | } | ||
1033 | else | ||
1034 | { | ||
1035 | return false; | ||
1036 | } | ||
1037 | } | ||
1038 | |||
1039 | static public implicit operator key(string s) | ||
1040 | { | ||
1041 | return new key(s); | ||
1042 | } | ||
1043 | |||
1044 | static public implicit operator String(key k) | ||
1045 | { | ||
1046 | return k.value; | ||
1047 | } | ||
1048 | |||
1049 | public static bool operator ==(key k1, key k2) | ||
1050 | { | ||
1051 | return k1.value == k2.value; | ||
1052 | } | ||
1053 | public static bool operator !=(key k1, key k2) | ||
1054 | { | ||
1055 | return k1.value != k2.value; | ||
1056 | } | ||
1057 | |||
1058 | #endregion | ||
1059 | |||
1060 | #region Overriders | ||
1061 | |||
1062 | public override bool Equals(object o) | ||
1063 | { | ||
1064 | return o.ToString() == value; | ||
1065 | } | ||
1066 | |||
1067 | public override int GetHashCode() | ||
1068 | { | ||
1069 | return value.GetHashCode(); | ||
1070 | } | ||
1071 | |||
1072 | #endregion | ||
1073 | } | ||
1074 | |||
1075 | [Serializable] | ||
1076 | public struct LSLString | ||
1077 | { | ||
1078 | public string m_string; | ||
1079 | #region Constructors | ||
1080 | public LSLString(string s) | ||
1081 | { | ||
1082 | m_string = s; | ||
1083 | } | ||
1084 | |||
1085 | public LSLString(int i) | ||
1086 | { | ||
1087 | m_string=i.ToString(); | ||
1088 | } | ||
1089 | |||
1090 | public LSLString(double d) | ||
1091 | { | ||
1092 | string s=String.Format("{0:0.000000}", d); | ||
1093 | m_string=s; | ||
1094 | } | ||
1095 | |||
1096 | #endregion | ||
1097 | |||
1098 | #region Operators | ||
1099 | static public implicit operator Boolean(LSLString s) | ||
1100 | { | ||
1101 | if (s.m_string.Length == 0) | ||
1102 | { | ||
1103 | return false; | ||
1104 | } | ||
1105 | else | ||
1106 | { | ||
1107 | return true; | ||
1108 | } | ||
1109 | } | ||
1110 | |||
1111 | |||
1112 | |||
1113 | static public implicit operator String(LSLString s) | ||
1114 | { | ||
1115 | return s.m_string; | ||
1116 | } | ||
1117 | |||
1118 | static public implicit operator LSLString(string s) | ||
1119 | { | ||
1120 | return new LSLString(s); | ||
1121 | } | ||
1122 | |||
1123 | public static string ToString(LSLString s) | ||
1124 | { | ||
1125 | return s.m_string; | ||
1126 | } | ||
1127 | |||
1128 | public override string ToString() | ||
1129 | { | ||
1130 | return m_string; | ||
1131 | } | ||
1132 | |||
1133 | public static bool operator ==(LSLString s1, string s2) | ||
1134 | { | ||
1135 | return s1.m_string == s2; | ||
1136 | } | ||
1137 | |||
1138 | public static bool operator !=(LSLString s1, string s2) | ||
1139 | { | ||
1140 | return s1.m_string != s2; | ||
1141 | } | ||
1142 | |||
1143 | public static explicit operator double(LSLString s) | ||
1144 | { | ||
1145 | return Convert.ToDouble(s.m_string); | ||
1146 | } | ||
1147 | |||
1148 | public static explicit operator LSLInteger(LSLString s) | ||
1149 | { | ||
1150 | return new LSLInteger(Convert.ToInt32(s.m_string)); | ||
1151 | } | ||
1152 | |||
1153 | public static explicit operator LSLString(int i) | ||
1154 | { | ||
1155 | return new LSLString(i); | ||
1156 | } | ||
1157 | |||
1158 | public static explicit operator LSLString(double d) | ||
1159 | { | ||
1160 | return new LSLString(d); | ||
1161 | } | ||
1162 | |||
1163 | public static implicit operator Vector3(LSLString s) | ||
1164 | { | ||
1165 | return new Vector3(s.m_string); | ||
1166 | } | ||
1167 | |||
1168 | #endregion | ||
1169 | |||
1170 | #region Overriders | ||
1171 | public override bool Equals(object o) | ||
1172 | { | ||
1173 | return m_string == o.ToString(); | ||
1174 | } | ||
1175 | |||
1176 | public override int GetHashCode() | ||
1177 | { | ||
1178 | return m_string.GetHashCode(); | ||
1179 | } | ||
1180 | |||
1181 | #endregion | ||
1182 | |||
1183 | #region " Standard string functions " | ||
1184 | //Clone,CompareTo,Contains | ||
1185 | //CopyTo,EndsWith,Equals,GetEnumerator,GetHashCode,GetType,GetTypeCode | ||
1186 | //IndexOf,IndexOfAny,Insert,IsNormalized,LastIndexOf,LastIndexOfAny | ||
1187 | //Length,Normalize,PadLeft,PadRight,Remove,Replace,Split,StartsWith,Substring,ToCharArray,ToLowerInvariant | ||
1188 | //ToString,ToUpper,ToUpperInvariant,Trim,TrimEnd,TrimStart | ||
1189 | public bool Contains(string value) { return m_string.Contains(value); } | ||
1190 | public int IndexOf(string value) { return m_string.IndexOf(value); } | ||
1191 | public int Length { get { return m_string.Length; } } | ||
1192 | |||
1193 | |||
1194 | #endregion | ||
1195 | } | ||
1196 | |||
1197 | [Serializable] | ||
1198 | public struct LSLInteger | ||
1199 | { | ||
1200 | public int value; | ||
1201 | |||
1202 | #region Constructors | ||
1203 | public LSLInteger(int i) | ||
1204 | { | ||
1205 | value = i; | ||
1206 | } | ||
1207 | |||
1208 | public LSLInteger(double d) | ||
1209 | { | ||
1210 | value = (int)d; | ||
1211 | } | ||
1212 | |||
1213 | public LSLInteger(Object o) | ||
1214 | { | ||
1215 | if(!(o is Int32)) | ||
1216 | value=0; | ||
1217 | else | ||
1218 | value = (int)o; | ||
1219 | } | ||
1220 | |||
1221 | public LSLInteger(string s) | ||
1222 | { | ||
1223 | value = int.Parse(s); | ||
1224 | } | ||
1225 | |||
1226 | #endregion | ||
1227 | |||
1228 | static public implicit operator int(LSLInteger i) | ||
1229 | { | ||
1230 | return i.value; | ||
1231 | } | ||
1232 | |||
1233 | static public implicit operator uint(LSLInteger i) | ||
1234 | { | ||
1235 | return (uint)i.value; | ||
1236 | } | ||
1237 | |||
1238 | static public explicit operator LSLString(LSLInteger i) | ||
1239 | { | ||
1240 | return new LSLString(i.ToString()); | ||
1241 | } | ||
1242 | |||
1243 | static public explicit operator string(LSLInteger i) | ||
1244 | { | ||
1245 | return i.ToString(); | ||
1246 | } | ||
1247 | |||
1248 | static public implicit operator Boolean(LSLInteger i) | ||
1249 | { | ||
1250 | if (i.value == 0) | ||
1251 | { | ||
1252 | return false; | ||
1253 | } | ||
1254 | else | ||
1255 | { | ||
1256 | return true; | ||
1257 | } | ||
1258 | } | ||
1259 | |||
1260 | static public implicit operator LSLInteger(int i) | ||
1261 | { | ||
1262 | return new LSLInteger(i); | ||
1263 | } | ||
1264 | |||
1265 | static public explicit operator LSLInteger(string s) | ||
1266 | { | ||
1267 | return new LSLInteger(int.Parse(s)); | ||
1268 | } | ||
1269 | |||
1270 | static public implicit operator LSLInteger(double d) | ||
1271 | { | ||
1272 | return new LSLInteger(d); | ||
1273 | } | ||
1274 | |||
1275 | static public bool operator ==(LSLInteger i1, LSLInteger i2) | ||
1276 | { | ||
1277 | bool ret = i1.value == i2.value; | ||
1278 | return ret; | ||
1279 | } | ||
1280 | |||
1281 | static public bool operator !=(LSLInteger i1, LSLInteger i2) | ||
1282 | { | ||
1283 | bool ret = i1.value != i2.value; | ||
1284 | return ret; | ||
1285 | } | ||
1286 | |||
1287 | static public LSLInteger operator &(LSLInteger i1, LSLInteger i2) | ||
1288 | { | ||
1289 | int ret = i1.value & i2.value; | ||
1290 | return ret; | ||
1291 | } | ||
1292 | |||
1293 | public static LSLInteger operator ++(LSLInteger i) | ||
1294 | { | ||
1295 | i.value++; | ||
1296 | return i; | ||
1297 | } | ||
1298 | |||
1299 | |||
1300 | public static LSLInteger operator --(LSLInteger i) | ||
1301 | { | ||
1302 | i.value--; | ||
1303 | return i; | ||
1304 | } | ||
1305 | |||
1306 | static public implicit operator System.Double(LSLInteger i) | ||
1307 | { | ||
1308 | return (double)i.value; | ||
1309 | } | ||
1310 | |||
1311 | public static bool operator true(LSLInteger i) | ||
1312 | { | ||
1313 | return i.value != 0; | ||
1314 | } | ||
1315 | |||
1316 | public static bool operator false(LSLInteger i) | ||
1317 | { | ||
1318 | return i.value == 0; | ||
1319 | } | ||
1320 | |||
1321 | #region Overriders | ||
1322 | |||
1323 | public override string ToString() | ||
1324 | { | ||
1325 | return this.value.ToString(); | ||
1326 | } | ||
1327 | |||
1328 | public override bool Equals(object o) | ||
1329 | { | ||
1330 | if(o is Int32) | ||
1331 | { | ||
1332 | return value == (Int32)o; | ||
1333 | } | ||
1334 | if(o is LSLInteger) | ||
1335 | { | ||
1336 | return value == ((LSLInteger)o).value; | ||
1337 | } | ||
1338 | return false; | ||
1339 | } | ||
1340 | |||
1341 | public override int GetHashCode() | ||
1342 | { | ||
1343 | return value.GetHashCode(); | ||
1344 | } | ||
1345 | |||
1346 | #endregion | ||
1347 | } | ||
1348 | |||
1349 | [Serializable] | ||
1350 | public struct LSLFloat | ||
1351 | { | ||
1352 | public double value; | ||
1353 | |||
1354 | #region Constructors | ||
1355 | public LSLFloat(int i) | ||
1356 | { | ||
1357 | this.value = (double)i; | ||
1358 | } | ||
1359 | |||
1360 | public LSLFloat(double d) | ||
1361 | { | ||
1362 | this.value = d; | ||
1363 | } | ||
1364 | |||
1365 | #endregion | ||
1366 | |||
1367 | #region Operators | ||
1368 | |||
1369 | static public implicit operator Double(LSLFloat f) | ||
1370 | { | ||
1371 | return f.value; | ||
1372 | } | ||
1373 | |||
1374 | //static public implicit operator System.Int32(LSLFloat f) | ||
1375 | //{ | ||
1376 | // return (int)f.value; | ||
1377 | //} | ||
1378 | |||
1379 | |||
1380 | static public implicit operator Boolean(LSLFloat f) | ||
1381 | { | ||
1382 | if (f.value == 0) | ||
1383 | { | ||
1384 | return false; | ||
1385 | } | ||
1386 | else | ||
1387 | { | ||
1388 | return true; | ||
1389 | } | ||
1390 | } | ||
1391 | |||
1392 | static public implicit operator LSLFloat(int i) | ||
1393 | { | ||
1394 | return new LSLFloat(i); | ||
1395 | } | ||
1396 | |||
1397 | static public implicit operator LSLFloat(double d) | ||
1398 | { | ||
1399 | return new LSLFloat(d); | ||
1400 | } | ||
1401 | #endregion | ||
1402 | |||
1403 | #region Overriders | ||
1404 | public override string ToString() | ||
1405 | { | ||
1406 | return this.value.ToString(); | ||
1407 | } | ||
1408 | #endregion | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||