C# translation of IainNZ's SimplexJS