source: xmlTools/trunk/posUpdate/XmlNumberValue.cs@ 1042

Last change on this file since 1042 was 710, checked in by s10k, 12 years ago
File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5
6namespace xmlTools
7{
8 /// <summary>
9 /// This class represents a xmlNumberValue. It supports various dimensions separated by spaces. For example a quaternion: 1 -1 1 -1
10 /// It also includes various functions to work with multi dimensional number xml values
11 /// </summary>
12 public class XmlNumberValue
13 {
14 public List<double> myValues = new List<double>(); //include all dimensions of the value
15
16 public XmlNumberValue(String myString)
17 {
18 String[] values = myString.Split(' ');
19
20 foreach (string value in values)
21 {
22 this.myValues.Add(XmlConvert.ToDouble(value));
23 }
24 }
25
26 public XmlNumberValue(List<double> myDimensions)
27 {
28 this.myValues = myDimensions;
29 }
30
31 public static XmlNumberValue difference(XmlNumberValue first, XmlNumberValue second)
32 {
33 List<double> result = new List<double>();
34
35 for (int i = 0; i < first.myValues.Count; i++)
36 {
37 result.Add(first.myValues[i] - second.myValues[i]);
38 }
39
40 return new XmlNumberValue(result);
41 }
42
43 public static XmlNumberValue sum(XmlNumberValue first, XmlNumberValue second)
44 {
45 List<double> result = new List<double>();
46
47 for (int i = 0; i < first.myValues.Count; i++)
48 {
49 result.Add(first.myValues[i] + second.myValues[i]);
50 }
51
52 return new XmlNumberValue(result);
53 }
54
55 public override string ToString()
56 {
57 String result = "";
58
59 for (int i = 0; i < this.myValues.Count - 1; i++)
60 {
61 result += XmlConvert.ToString(this.myValues[i]) + " ";
62 }
63 result += XmlConvert.ToString(this.myValues[this.myValues.Count - 1]);
64
65 return result;
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.