fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace UltraTerrain.Common.Morton
  8. {
  9. public static class MortonHelper
  10. {
  11. public static uint GetLeftMostBit(uint value)
  12. {
  13. uint pos = 0;
  14.  
  15. while (value > 0)
  16. {
  17. value >>= 1;
  18. pos++;
  19. }
  20. return pos;
  21. }
  22.  
  23. public static uint Part1By2(uint n)
  24. {
  25. n &= 0x000003ff;
  26. n = (n ^ (n << 16)) & 0xff0000ff;
  27. n = (n ^ (n << 8)) & 0x0300f00f;
  28. n = (n ^ (n << 4)) & 0x030c30c3;
  29. n = (n ^ (n << 2)) & 0x09249249;
  30. return n;
  31. }
  32.  
  33. public static uint Unpart1By2(uint n)
  34. {
  35. n &= 0x09249249;
  36. n = (n ^ (n >> 2)) & 0x030c30c3;
  37. n = (n ^ (n >> 4)) & 0x0300f00f;
  38. n = (n ^ (n >> 8)) & 0xff0000ff;
  39. n = (n ^ (n >> 16)) & 0x000003ff;
  40. return n;
  41. }
  42.  
  43. public static uint ToMorton(uint x, uint y, uint z)
  44. {
  45. return MortonHelper.Part1By2(x) | (MortonHelper.Part1By2(y) << 1) | (MortonHelper.Part1By2(z) << 2);
  46. }
  47.  
  48. public static uint FromBinary(this string binary)
  49. {
  50. binary = binary.Replace(".", "").PadLeft(32, '0');
  51. uint value = 0;
  52. for (int i = 31; i >= 0; --i)
  53. {
  54. if (binary[i] == '1')
  55. {
  56. value |= 1u << (31 - i);
  57. }
  58. }
  59. return value;
  60. }
  61.  
  62. public static uint ToMorton(this Integer3 that)
  63. {
  64. return MortonHelper.Part1By2((uint)that.X) | (MortonHelper.Part1By2((uint)that.Y) << 1) | (MortonHelper.Part1By2((uint)that.Z) << 2);
  65. }
  66.  
  67. public static Integer3 ToInteger3(this uint morton)
  68. {
  69. return new Integer3((int)MortonHelper.Unpart1By2(morton), (int)MortonHelper.Unpart1By2(morton >> 1), (int)MortonHelper.Unpart1By2(morton >> 2));
  70. }
  71.  
  72. public static Vector3 ToVector3(this uint morton)
  73. {
  74. return new Vector3((float)MortonHelper.Unpart1By2(morton), (float)MortonHelper.Unpart1By2(morton >> 1), (float)MortonHelper.Unpart1By2(morton >> 2));
  75. }
  76. }
  77. }
  78.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(62,42): error CS0246: The type or namespace name `Integer3' could not be found. Are you missing an assembly reference?
prog.cs(67,23): error CS0246: The type or namespace name `Integer3' could not be found. Are you missing an assembly reference?
prog.cs(72,23): error CS0246: The type or namespace name `Vector3' could not be found. Are you missing an assembly reference?
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty