public DecompressStrokeLeg ( string data ) : int[] | ||
data | string | |
return | int[] |
public int[] DecompressStrokeLeg(string data)
{
List<int> leg = new List<int>();
List<int> cell = new List<int>();
int polarity = 1;
foreach (char c in data)
{
if (charmap_tail.ContainsKey(c))
{
// this is a char that indicates continuation of a number that started a earlier number.
cell.Add(charmap_tail[c]);
}
else
{
// This is a start of new number (or, in case of + or - an end of previous number)
// We can now convert the parts we piled up in cell array into an int.
if (cell.Count != 0) {
// yep, we have some number parts in there.
leg.Add(FromBase30(cell) * polarity);
}
// When i say "we start a new number" I mean it!
cell.Clear();
if (c == MINUS){
polarity = -1;
} else if (c == PLUS){
polarity = 1;
} else {
// now, let's start collecting parts for the new number:
cell.Add(charmap[c]);
}
}
}
// we will alway have one number stuck in cell array because no "new number starts" follows it.
leg.Add(FromBase30(cell) * polarity);
return leg.ToArray();
}
public void id001_decompressleg() { int[] leg1x = new int[] {236, 233, 231, 229, 226, 224, 222, 216, 213, 210, 205, 202, 200, 198, 195, 193, 191, 189, 186, 183, 180, 178, 174, 172}; int[] leg1xVectorized = new int[leg1x.Length]; int last = 0; for (int i = 0; i < leg1x.Length; i++) { leg1xVectorized[i] = leg1x[i] - last; last = leg1x[i]; } var c = new jSignature.Tools.Base30Converter(); Assert.AreEqual( leg1xVectorized , c.DecompressStrokeLeg("7UZ32232263353223222333242") ); }