private int InterpolateCorner(Vector2 position, Color[] colors, bool[] validFlags)
        {
            var result = 0;

            var xIndex = Array.BinarySearch <float>(xThresholds, position.x);
            var yIndex = Array.BinarySearch <float>(yThresholds, position.y);
            var index  = xIndex + yIndex * xThresholds.Length;

            if (!validFlags[index])
            {
                var nearestKey = material.keys.OrderBy(x => (x.position - position).sqrMagnitude)
                                 .First();
                var nearestXIndex = Array.BinarySearch <float>(xThresholds, nearestKey.position.x);
                var nearestYIndex = Array.BinarySearch <float>(yThresholds, nearestKey.position.y);

                for (int y = Mathf.Min(yIndex, nearestYIndex), yMax = Mathf.Max(yIndex, nearestYIndex) + 1; y < yMax; ++y)
                {
                    for (int x = Mathf.Min(xIndex, nearestXIndex), xMax = Mathf.Max(xIndex, nearestXIndex) + 1; x < xMax; ++x)
                    {
                        var i = x + y * xThresholds.Length;
                        if (!validFlags[i])
                        {
                            colors[i]     = nearestKey.color;
                            validFlags[i] = true;
                            ++result;
                        }
                    }
                }
            }

            return(result);
        }
示例#2
0
    private void ModifyTriangle(VertexHelper vh, List <UIVertex> vertices, int[] triangleIndices, GradationMaterial.Grid grid, Vector3[] localCorners)
    {
        var triangleVertices           = triangleIndices.Select(x => vertices[x]).ToArray();
        var triangleNormalizePositions = new Vector2[triangleVertices.Length];

        for (int i = 0, iMax = triangleVertices.Length; i < iMax; ++i)
        {
            triangleNormalizePositions[i] = new Vector2(Mathf.InverseLerp(localCorners[(int)RectangleIndex.UpperLeft].x, localCorners[(int)RectangleIndex.LowerRight].x, triangleVertices[i].position.x)
                                                        , Mathf.InverseLerp(localCorners[(int)RectangleIndex.LowerRight].y, localCorners[(int)RectangleIndex.UpperLeft].y, triangleVertices[i].position.y)
                                                        );
        }

        var xMin = Array.BinarySearch <float>(grid.xThresholds, triangleNormalizePositions.Min(x => x.x));

        if (xMin < 0)
        {
            xMin = ~xMin - 1;
        }
        var xMax = Array.BinarySearch <float>(grid.xThresholds, triangleNormalizePositions.Max(x => x.x));

        if (xMax < 0)
        {
            xMax = ~xMax;
        }
        var yMin = Array.BinarySearch <float>(grid.yThresholds, triangleNormalizePositions.Min(x => x.y));

        if (yMin < 0)
        {
            yMin = ~yMin - 1;
        }
        var yMax = Array.BinarySearch <float>(grid.yThresholds, triangleNormalizePositions.Max(x => x.y));

        if (yMax < 0)
        {
            yMax = ~yMax;
        }

        for (int y = yMin; y < yMax; ++y)
        {
            for (int x = xMin; x < xMax; ++x)
            {
                ModifyTriangleGrid(vh, triangleVertices, grid, x, y, triangleNormalizePositions);
            }
        }
    }
        private Color[] GetColors()
        {
            var keysCount = xThresholds.Length * yThresholds.Length;

            if (material.keys.Count == 0)
            {
                //有点キーが無いなら
                return(Enumerable.Repeat(Color.white, keysCount).ToArray());
            }

            var validFlags = new bool[keysCount];
            var emptyCount = keysCount;
            var result     = new Color[keysCount];

            //有点キー設定
            foreach (var key in material.keys)
            {
                var xIndex = Array.BinarySearch <float>(xThresholds, key.position.x);
                var yIndex = Array.BinarySearch <float>(yThresholds, key.position.y);
                var index  = xIndex + yIndex * xThresholds.Length;
                result[index]     = key.color;
                validFlags[index] = true;
                --emptyCount;
            }

            if (emptyCount == 0)
            {
                return(result);
            }

            //角の無点キー補間
            emptyCount -= InterpolateCorner(new Vector2(0.0f, 0.0f), result, validFlags);
            emptyCount -= InterpolateCorner(new Vector2(1.0f, 0.0f), result, validFlags);
            emptyCount -= InterpolateCorner(new Vector2(1.0f, 1.0f), result, validFlags);
            emptyCount -= InterpolateCorner(new Vector2(0.0f, 1.0f), result, validFlags);

            if (emptyCount == 0)
            {
                return(result);
            }

            //外周の無点キー補間
            emptyCount -= InterpolateLine(0
                                          , xThresholds.Length
                                          , 1
                                          , x => xThresholds[x % xThresholds.Length]
                                          , result
                                          , validFlags
                                          );
            emptyCount -= InterpolateLine(xThresholds.Length * (yThresholds.Length - 1)
                                          , keysCount
                                          , 1
                                          , x => xThresholds[x % xThresholds.Length]
                                          , result
                                          , validFlags
                                          );
            emptyCount -= InterpolateLine(0
                                          , keysCount
                                          , xThresholds.Length
                                          , y => yThresholds[y / xThresholds.Length]
                                          , result
                                          , validFlags
                                          );
            emptyCount -= InterpolateLine(xThresholds.Length - 1
                                          , keysCount
                                          , xThresholds.Length
                                          , y => yThresholds[y / xThresholds.Length]
                                          , result
                                          , validFlags
                                          );

            if (emptyCount == 0)
            {
                return(result);
            }

            //無点キー補間
            for (int i = 0, iMax = keysCount; i < iMax; ++i)
            {
                emptyCount -= InterpolateCross(i, result, validFlags);
            }

            return(result);
        }
示例#4
0
 public static int BinarySearch(Array array, object value, IComparer comparer) =>
 Array.BinarySearch(array, 0, array?.Length ?? -1, value, comparer);
示例#5
0
        public byte[] GetTimeZoneData(string id)
        {
            int i = Array.BinarySearch(ids, id, StringComparer.Ordinal);

            if (i < 0)
                return(null); }
示例#6
0
 public static int BinarySearch(Array array, int index, int length, object value, IComparer comparer) =>
 Array.BinarySearch(array, index, length, value, comparer);
示例#7
0
 public static int BinarySearch(Array array, object value) =>
 Array.BinarySearch(array, value);
示例#8
0
 public static int BinarySearch <T>(T[] array, int index, int length, T value, IComparer <T> comparer) =>
 Array.BinarySearch(array, index, length, value, comparer);
示例#9
0
 public static int BinarySearch(Array array, int index, int length, object value) =>
 Array.BinarySearch(array, index, length, value, null);
示例#10
0
 public static int BinarySearch <T>(T[] array, int index, int length, T value) =>
 Array.BinarySearch(array, index, length, value);
示例#11
0
 public static int BinarySearch <T>(T[] array, T value, IComparer <T> comparer) =>
 Array.BinarySearch(array, value, comparer);
示例#12
0
 public static int BinarySearch <T>(T[] array, T value) =>
 Array.BinarySearch(array, value);
示例#13
0
 /// <summary>
 ///     Searches a range of elements in a one-dimensional sorted  for a value, using the specified  interface.
 /// </summary>
 /// <param name="array">The sorted one-dimensional  to search.</param>
 /// <param name="index">The starting index of the range to search.</param>
 /// <param name="length">The length of the range to search.</param>
 /// <param name="value">The object to search for.</param>
 /// <param name="comparer">
 ///     The  implementation to use when comparing elements.-or- null to use the  implementation
 ///     of each element.
 /// </param>
 /// <returns>
 ///     The index of the specified  in the specified , if  is found. If  is not found and  is less than one or more
 ///     elements in , a negative number which is the bitwise complement of the index of the first element that is
 ///     larger than . If  is not found and  is greater than any of the elements in , a negative number which is the
 ///     bitwise complement of (the index of the last element plus 1).
 /// </returns>
 public static int BinarySearch([NotNull] this Array array, int index, int length, object value, IComparer comparer)
 {
     return(Array.BinarySearch(array, index, length, value, comparer));
 }
示例#14
0
 /// <summary>
 ///     Searches an entire one-dimensional sorted  for a specific element, using the  interface implemented by each
 ///     element of the  and by the specified object.
 /// </summary>
 /// <param name="array">The sorted one-dimensional  to search.</param>
 /// <param name="value">The object to search for.</param>
 /// <returns>
 ///     The index of the specified  in the specified , if  is found. If  is not found and  is less than one or more
 ///     elements in , a negative number which is the bitwise complement of the index of the first element that is
 ///     larger than . If  is not found and  is greater than any of the elements in , a negative number which is the
 ///     bitwise complement of (the index of the last element plus 1).
 /// </returns>
 public static int BinarySearch([NotNull] this Array array, object value)
 {
     return(Array.BinarySearch(array, value));
 }