Skip to content

Commit

Permalink
Another tidy of CSharp_TestApp (Clipper2 DLL demo)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusJohnson committed Oct 29, 2023
1 parent c5a0cda commit 5fda66d
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions DLL/CSharp_TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,50 @@ public class Application

static T[]? CreateCPath<T>(T[] coords)
{
int pathLen = coords.Count() / 2;
int pathLen = coords.Length / 2;
if (pathLen == 0) return null;
int arrayLen = pathLen * 2 + 2;
T[] result = new T[arrayLen];
result[0] = (T)Convert.ChangeType(pathLen, typeof(T));
result[1] = (T)Convert.ChangeType(0, typeof(T));
int idx = 2;
for (int i = 0; i < pathLen; i++)
{
result[idx++] = coords[i * 2];
result[idx++] = coords[i * 2 + 1];
}
coords.CopyTo(result, 2);
return result;
}
static void AppendCPath<T>(ref T[] cpaths, ref int idx, T[] cpath)
{
int pathLen = cpath.Count() / 2 - 1;
if (pathLen <= 0) return;
cpaths[idx++] = (T)Convert.ChangeType(pathLen, typeof(T));
cpaths[idx++] = (T)Convert.ChangeType(0, typeof(T));
for (int i = 1; i <= pathLen; i++)
{
cpaths[idx++] = cpath[i * 2];
cpaths[idx++] = cpath[i * 2 + 1];
}
}

static T[] CreateCPaths<T>(List<T[]> listOfCPath)
{
int pathCount = listOfCPath.Count();
int arrayLen = 2;
foreach (T[] path in listOfCPath)
arrayLen += path.Count();
arrayLen += path.Length;
T[] result = new T[arrayLen];

result[0] = (T)Convert.ChangeType(arrayLen, typeof(T));
result[1] = (T)Convert.ChangeType(pathCount, typeof(T));

int idx = 2;
foreach (T[] path in listOfCPath)
AppendCPath(ref result, ref idx, path);
foreach (T[] cpath in listOfCPath)
{
cpath.CopyTo(result, idx);
idx += cpath.Length;
}
return result;
}

// and to create cpaths that will contain just 1 path ...
// or create a cpaths array that contains just 1 path
static T[] CreateCPaths<T>(T[] coords)
{
int pathLen = coords.Count() / 2, arrayLen = pathLen *2 + 2 + 2;
int pathLen = coords.Length / 2;
int arrayLen = pathLen *2 + 2 + 2;
T[] result = new T[arrayLen];

result[0] = (T)Convert.ChangeType(arrayLen, typeof(T));
result[1] = (T)Convert.ChangeType(1, typeof(T));
result[1] = (T)Convert.ChangeType(1, typeof(T)); // 1 path

result[2] = (T)Convert.ChangeType(pathLen, typeof(T));
result[3] = (T)Convert.ChangeType(0, typeof(T));

int idx = 4;
for (int i = 0; i < pathLen; i++)
{
result[idx++] = coords[i * 2];
result[idx++] = coords[i * 2 + 1];
}
coords.CopyTo(result, 4);
return result;
}

Expand Down

0 comments on commit 5fda66d

Please sign in to comment.