Ejemplo n.º 1
0
 public static TOutput[] ConvertAll <TInput, TOutput>(this TInput[] a, System.Converter <TInput, TOutput> c)
 {
     if (a.IsNull())
     {
         throw new System.NullReferenceException();
     }
     return((a.Length > 0) ? System.Array.ConvertAll(a, c) : new TOutput[0]);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Convert an array of elements
 /// </summary>
 /// <typeparam name="TInput">The input array type</typeparam>
 /// <typeparam name="TOutput">The output array type</typeparam>
 /// <param name="array">The array to be converted</param>
 /// <param name="converter">The converter</param>
 /// <returns>The converted array</returns>
 public static TOutput[] ConvertAll <TInput, TOutput>(TInput[] array, System.Converter <TInput, TOutput> converter)
 {
     TOutput[] result = new TOutput[array.Length];
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = converter(array[i]);
     }
     return(result);
 }
        public static List <TOutput> ConvertIListItems <TInput, TOutput>(IList list, System.Converter <TInput, TOutput> function)
        {
            var outputList = new List <TOutput>();

            foreach (var input in list)
            {
                outputList.Add(function((TInput)input));
            }
            return(outputList);
        }
Ejemplo n.º 4
0
        /** Update and return old, new and side result
         * NO GUARANTEE THAT update_meth IS ONLY CALLED ONCE!!!!
         * update_meth should return a pair that has the new state, and a side
         * result
         * the returned value gives the old state, new state and that side value
         */
        public Triple <T, T, R> Update <R>(System.Converter <T, Pair <T, R> > update_meth)
        {
            T           old_state = _state;
            T           state;
            Pair <T, R> res;

            do
            {
                state     = old_state;
                res       = update_meth(state);
                old_state = Interlocked.CompareExchange(ref _state, res.First, state);
            } while(old_state != state);
            return(new Triple <T, T, R>(state, res.First, res.Second));
        }
Ejemplo n.º 5
0
        /** Update and return old and new state
         * NO GUARANTEE THAT update_meth IS ONLY CALLED ONCE!!!!
         * update_meth should return a new state based on the old state
         */
        public Pair <T, T> Update(System.Converter <T, T> update_meth)
        {
            T old_state = _state;
            T state;
            T new_state;

            do
            {
                state     = old_state;
                new_state = update_meth(state);
                old_state = Interlocked.CompareExchange <T>(ref _state, new_state, state);
            } while(old_state != state);
            return(new Pair <T, T>(state, new_state));
        }
Ejemplo n.º 6
0
        // -----------------------------------------------------------------------------------
        public void RedrawPath(int x, int y)
        {
            Clear();

            PathBuilder          pb       = new PathBuilder();
            List <List <Point> > segments = pb.GetSegments(playArea.mask, x, y, pathValue);

            // add play area edges, if needed
            if (type == Type.Safe)
            {
                AddPlayAreaEdges(segments);
            }

            System.Converter <Point, Vector3> Point2Vec3 = (Point pt) => { return((Vector2)pt); };
            System.Converter <Point, Vector2> Point2Vec2 = (Point pt) => { return(pt); };

            foreach (List <Point> segment in segments)
            {
                // create a new line renderer for the segment
                LineRenderer newLine = CreateLineRenderer();
                lineRenderers.Add(newLine);

                newLine.positionCount = segment.Count;
                newLine.SetPositions(segment.ConvertAll(Point2Vec3).ToArray());

                // check if the segment is looping (first and last position are 1 px apart)
                if (Vector2.Distance(segment[0], segment[segment.Count - 1]) == 1)
                {
                    newLine.loop = true;
                }

                // add a collider for the segment
                if (segment.Count >= 2)
                {
                    EdgeCollider2D col = gameObject.AddComponent <EdgeCollider2D>();
                    col.edgeRadius = 1;
                    col.points     = segment.ConvertAll(Point2Vec2).ToArray();
                    col.isTrigger  = type == Type.Cut && !isShielded;
                    colliders.Add(col);
                }
            }
        }
Ejemplo n.º 7
0
 private void FunctionToPoints(System.Drawing.PointF[] points, System.Converter <double, double> func)
 {
     for (int x = 0; x < points.Length; x++)
     {
         double y = this.originY - this.scaleX * func((x - this.originX) / this.scaleY);
         if (y < 0)
         {
             y = -1;
         }
         else if (double.IsNaN(y))
         {
             y = 0;
         }
         else if (y > this.Height)
         {
             y = this.Height + 1;
         }
         points[x] = new System.Drawing.PointF(x, (float)y);
     }
 }
Ejemplo n.º 8
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Find the difference between the safe path before and after cutting,
        /// then returning the center of that difference plus the difference path
        /// </summary>
        static public bool FindDifference(Vector3 [] pointsBefore, Vector3 [] pointsAfter, out Vector3 [] result, out Vector3 centroid)
        {
            result   = null;
            centroid = Vector3.zero;

            System.Converter <Vector3, IntPoint> converter = (pt) => { return(new IntPoint(pt.x, pt.y)); };
            List <IntPoint>         before   = new List <IntPoint>(System.Array.ConvertAll(pointsBefore, converter));
            List <IntPoint>         after    = new List <IntPoint>(System.Array.ConvertAll(pointsAfter, converter));
            List <List <IntPoint> > solution = new List <List <IntPoint> >();

            Clipper clipper = new Clipper();

            clipper.AddPath(before, PolyType.ptClip, true);
            clipper.AddPath(after, PolyType.ptSubject, true);
            if (!clipper.Execute(ClipType.ctDifference, solution))
            {
                return(false);
            }

            result   = System.Array.ConvertAll(solution[0].ToArray(), (pt) => { return(new Vector3(pt.X, pt.Y, 0)); });
            centroid = FindCentroid(result);
            return(true);
        }
Ejemplo n.º 9
0
        public static void DrawSelector <T>(string title, Color elementColor, T[] variants, System.Converter <T, string> converter, System.Action <T> selectionCallback, params GUILayoutOption[] options)
        {
            var values = new[] { title }.Concat(variants.ConvertAll(converter));
            var color = GUI.backgroundColor;

            GUI.backgroundColor = elementColor;
            var newIndex = EditorGUILayout.Popup(0, values, options);

            if (newIndex > 0)
            {
                selectionCallback.SafeInvoke(variants[newIndex - 1]);
            }
            GUI.backgroundColor = color;
        }
Ejemplo n.º 10
0
        public static TOutput[] FindAndConvert <TInput, TOutput>(this System.Collections.Generic.IEnumerable <TInput> e, System.Predicate <TInput> m, System.Converter <TInput, TOutput> c)
        {
            if (e.IsNull())
            {
                throw new System.NullReferenceException();
            }
            if (m.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var list      = new System.Collections.Generic.List <TInput>(e);
            var finded    = list.FindAll(m);
            var converted = finded.ConvertAll(c);
            var result    = converted.ToArray();

            list.Clear();
            finded.Clear();
            converted.Clear();
            return(result);
        }
Ejemplo n.º 11
0
 public WrappedArray <U> ConvertAll <U>(System.Converter <T, U> converter)
 {
     return(new WrappedArray <U>((array.Length > 0) ? System.Array.ConvertAll(array, converter) : new U[0]));
 }
Ejemplo n.º 12
0
        static List <tOutput> ConvertToList <t, tOutput>(this IEnumerable <t> thisEnumerable, System.Converter <t, tOutput> converter)
        {
            Throw <System.ArgumentNullException> .If(thisEnumerable == null, "IndexOfLast cannot be executed against a null enumerable list.");

            Throw <System.ArgumentNullException> .If(converter == null, "IndexOfLast cannot be executed with a null converter.");

            List <tOutput> returnList = new List <tOutput>();

            foreach (t item in thisEnumerable)
            {
                returnList.Add(converter(item));
            }
            return(returnList);
        }
Ejemplo n.º 13
0
 public bool tryFetch <T>(int pos, System.Converter <JSONNode, T> converter, out T resp)
 {
     resp = converter(this[pos]);
     return(resp != null);
 }
Ejemplo n.º 14
0
 public CommandSet(string suite, System.IO.TextWriter output, System.IO.TextWriter error, System.Converter <string, string> localizer = null)
 {
 }
Ejemplo n.º 15
0
 public CommandSet(string suite, System.Converter <string, string> localizer = null)
 {
 }
Ejemplo n.º 16
0
 public OptionSet(System.Converter <string, string> localizer)
 {
 }
Ejemplo n.º 17
0
 public OptionSet(System.Converter <string, string> localizer, System.StringComparer comparer)
 {
 }
Ejemplo n.º 18
0
 public T[] ConvertAll <T>(System.Converter <ValueStream, T> converter)
 {
     return(System.Array.ConvertAll(_items, converter));
 }
Ejemplo n.º 19
0
 public Function(System.Converter <double, double> func, System.Drawing.Pen pen)
 {
     this.Calculate = func;
     this.pen       = pen;
 }
Ejemplo n.º 20
0
 public void AddFunction(System.Converter <double, double> func, System.Drawing.Pen pen)
 {
     this.funcs.Add(new Function(func, pen));
 }