Example #1
0
            static void Index1dTo2d_VS_PointToIndex2d(float2 position, float2 gridWorldSize, int gridWidth, int gridHeight)
            {
                int  Ai  = NativeGrid.PointToIndex(position, gridWorldSize, gridWidth, gridHeight);
                int2 Ai2 = NativeGrid.Index1dTo2d(Ai, gridWidth);
                int2 Bi2 = NativeGrid.PointToIndex2d(position, gridWorldSize, gridWidth, gridHeight);

                Assert.AreEqual(Ai2, Bi2, $"\tNativeGrid.Index1dTo2d(NativeGrid.PointToIndex(params)) returned: {Ai2}\n\tNativeGrid.PointToIndex2d returned: {Bi2}");
            }
Example #2
0
        [Test] public static void Index2dTo1d()
        {
            RectInt R = new RectInt {
                width = 6, height = 6
            };

            Assert.AreEqual(13, NativeGrid.Index2dTo1d(1, 2, R.width));
        }
Example #3
0
        [Test] public static void Index1dTo2d()
        {
            RectInt R = new RectInt {
                width = 6, height = 6
            };

            Assert.AreEqual(new int2 {
                x = 1, y = 2
            }, NativeGrid.Index1dTo2d(13, R.width));
        }
Example #4
0
            static void PointToIndex2d_Test(float2 a, float2 b)
            {
                float2    worldSize = new float2(3000f, 3000f);
                float2    gridOrigin = new float2(-1500f, -1500f);
                const int width = 1500, height = 1500;
                INT2      A = NativeGrid.PointToIndex2d(a - gridOrigin, worldSize, width, height);
                INT2      B = NativeGrid.PointToIndex2d(b - gridOrigin, worldSize, width, height);

                // Debug.Log( $"a:{GetPositionInsideCell_GetDebugString(a,width,height,worldSize)}\nb:{GetPositionInsideCell_GetDebugString(b,width,height,worldSize)}" );
                Assert.AreEqual(A, B);
            }
Example #5
0
            public static void PointToIndex2d_Test_1x1(float2 a, float2 b)
            {
                float2 worldSize = new float2 {
                    x = 2f, y = 1f
                }; const int width = 1, height = 1;
                INT2         A = NativeGrid.PointToIndex2d(a, worldSize, width, height);
                INT2         B = NativeGrid.PointToIndex2d(b, worldSize, width, height);

                // Debug.Log( $"a:{GetPositionInsideCell_GetDebugString(a,width,height,worldSize)}\nb:{GetPositionInsideCell_GetDebugString(b,width,height,worldSize)}" );
                Assert.AreEqual(A, B);
            }
Example #6
0
        [Test] public static void IndexTranslate()
        {
            RectInt R = new RectInt {
                width = 6, height = 6
            };
            RectInt r = new RectInt {
                x = 1, y = 1, width = 3, height = 3
            };

            Assert.AreEqual(new int2(1, 2), NativeGrid.IndexTranslate(r, new int2(0, 1)));
            Assert.AreEqual(20, NativeGrid.IndexTranslate(r, 1, 2, R.width));
        }
Example #7
0
            public static void PointToIndex2d_Test_2x2(float2 a, float2 b, bool equalityTest = true)
            {
                float2 worldSize = new float2(2f, 2f); const int width = 2, height = 2;
                INT2   A = NativeGrid.PointToIndex2d(a, worldSize, width, height);
                INT2   B = NativeGrid.PointToIndex2d(b, worldSize, width, height);

                // Debug.Log( $"a:{GetPositionInsideCell_GetDebugString(a,width,height,worldSize)}\nb:{GetPositionInsideCell_GetDebugString(b,width,height,worldSize)}" );
                if (equalityTest)
                {
                    Assert.AreEqual(A, B);
                }
                else
                {
                    Assert.AreNotEqual(A, B);
                }
            }
    public static JobHandle Copy <T>
    (
        NativeGrid <T> source,
        RectInt region,
        out NativeGrid <T> copy,
        JobHandle dependency = default(JobHandle)
    ) where T : unmanaged
    {
        copy = new NativeGrid <T>(region.width, region.height, Allocator.TempJob);
        var job = new CopyRegionJob <T>(
            src: source.Array,
            dst: copy.Array,
            src_region: region,
            src_width: source.Width
            );

        return(job.Schedule(
                   region.width * region.height, 1024,
                   JobHandle.CombineDependencies(source.Dependency, dependency)
                   ));
    }
Example #9
0
 [Test] public static void IsPointBetweenCells___2f_2___1fPlusEpsilon_IS_0() => Assert.AreEqual(0, NativeGrid.IsPointBetweenCells(1f + float.Epsilon, 2, 2f));
Example #10
0
 static string GetPositionInsideCell_GetDebugString(float2 p, int width, int height, float2 worldSize)
 {
     NativeGrid.GetPositionInsideCell(p.x, width, worldSize.x, out int xlo, out int xhi, out float xf);
     NativeGrid.GetPositionInsideCell(p.y, height, worldSize.y, out int ylo, out int yhi, out float yf);
     return($"\n	x: {xlo}... {xf:R} ...{xhi}\n	y: {ylo}... {yf:R} ...{yhi}");
 }
Example #11
0
 [Test] public static void IsPointBetweenCells___3000f_1500___1f_IS_0() => Assert.AreEqual(0, NativeGrid.IsPointBetweenCells(1f, 1500, 3000f));
 public static int IndexTranslate(RectInt r, INT ri, INT R_width) => NativeGrid.IndexTranslate(r, ri, R_width);
 public static int2 IndexTranslate(RectInt r, INT2 rxy) => NativeGrid.IndexTranslate(r, rxy);
 public static float2 Index2dToPoint(INT2 i2, FLOAT stepX, FLOAT stepY) => NativeGrid.Index2dToPoint(i2, stepX, stepY);
 public static bool IsIndex2dValid(INT x, INT y, INT w, INT h) => NativeGrid.IsIndex2dValid(x, y, w, h);
 public static int2 ClampIndex2d(INT x, INT y, INT width, INT height) => NativeGrid.ClampIndex2d(x, y, width, height);
 public static int2 MidpointRoundingAwayFromZero(FLOAT2 value) => NativeGrid.MidpointRoundingAwayFromZero(value);
 public static bool IsIndex1dValid(INT i, INT len) => NativeGrid.IsIndex1dValid(i, len);
 public static bool IsIndex2dValid(INT2 i2, INT w, INT h) => NativeGrid.IsIndex2dValid(i2, w, h);
 public static int2 PointToIndex2d(FLOAT2 point, FLOAT2 worldSize, INT width, INT height) => NativeGrid.PointToIndex2d(point, worldSize, width, height);
 public static T PointToValue <T> (FLOAT2 point, FLOAT2 worldSize, NativeArray <T> array, INT width, INT height) where T : unmanaged => NativeGrid.PointToValue <T>(point, worldSize, array, width, height);
 public static float2 Index2dToPoint(INT2 i2, FLOAT2 step) => NativeGrid.Index2dToPoint(i2, step);
 public static int2 ClampIndex2d(INT2 i2, INT width, INT height) => NativeGrid.ClampIndex2d(i2, width, height);
 public static float2 MidpointRoundingAwayFromZero(FLOAT2 value, FLOAT2 step) => NativeGrid.MidpointRoundingAwayFromZero(value, step);
 public static void GetPositionInsideCell(FLOAT2 point, INT2 numCells, FLOAT2 worldSize, out int2 lowerCell, out int2 upperCell, out float2 normalizedPositionBetweenThoseTwoPoints) => NativeGrid.GetPositionInsideCell(point, numCells, worldSize, out lowerCell, out upperCell, out normalizedPositionBetweenThoseTwoPoints);
 public static float2 Index2dToPoint(INT x, INT y, FLOAT stepX, FLOAT stepY) => NativeGrid.Index2dToPoint(x, y, stepX, stepY);
Example #27
0
 [Test] public static void MidpointRoundingAwayFromZero()
 {
     for (float range = 2.1f, value = -range; value < range; value += 0.001f)
     {
         Assert.AreEqual(System.Math.Round(value, System.MidpointRounding.AwayFromZero), NativeGrid.MidpointRoundingAwayFromZero(value));
     }
 }
 public static int IsPointBetweenCells(FLOAT point, INT width, FLOAT worldSize) => NativeGrid.IsPointBetweenCells(point, width, worldSize);
 public static bool AboutEqual(double x, double y) => NativeGrid.AboutEqual(x, y);
 public static int ClampIndex(INT i, INT length) => NativeGrid.ClampIndex(i, length);