public static double integrate(func f, System.Collections.Generic.IReadOnlyList <double> init_ticks, double eps1)
        {
            var points = new System.Collections.Generic.Stack <Point>();
            var areas  = new System.Collections.Generic.List <double>();

            foreach (var x in init_ticks)
            {
                points.Push(new Point(x, f(x)));
            }

            var    full_width = init_ticks.Last() - init_ticks.First();
            Point  right;
            double eps = eps1 * 4.0 / full_width;

            while (points.Count > 1)
            {
                //Console.WriteLine(points.Count);
                right = points.Pop();
                var left = points.Peek();
                var mid  = Integration.midpoint(ref left, ref right, f);
                if (Math.Abs(left.f + right.f - mid.f * 2.0) <= eps)
                {
                    areas.Add((left.f + right.f + mid.f * 2.0) * (right.x - left.x) / 4.0);
                }
                else
                {
                    points.Push(mid);
                    points.Push(right);
                }
            }
            areas.Sort(delegate(double x, double y){
                return(Math.Abs(x).CompareTo(Math.Abs(y)));
            });
            return(areas.Sum());
        }
Esempio n. 2
0
        private void DrawingCanvas_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            System.Collections.Generic.IReadOnlyList <InkStroke> strokes = sender.StrokeContainer.GetStrokes();
            StrokeSampleBuilder sampleBuilder = new StrokeSampleBuilder((uint)strokes.Count);

            foreach (InkStroke stroke in strokes)
            {
                System.Collections.Generic.IReadOnlyList <InkPoint> points = stroke.GetInkPoints();
                StrokeBuilder strokeBuilder = new StrokeBuilder((uint)points.Count);

                foreach (InkPoint point in points)
                {
                    strokeBuilder.AddPoint(point.Position.X, point.Position.Y);
                }

                sampleBuilder.AddStroke(strokeBuilder.build());
            }

            StrokeSample sample = sampleBuilder.build();
            Scores       scores = classifier.classify(sample);

            ResultsList.Items.Clear();

            foreach (Score score in scores)
            {
                ResultsList.Items.Add(new SymbolListItem(score.Symbol, score.Value));
            }
        }
Esempio n. 3
0
        private static byte GetLRC(System.Collections.Generic.IReadOnlyList <byte> data)
        {
            var checksum = data[1];

            for (var i = 2; i <= data.Count - 1; i++)
            {
                checksum ^= data[i];
            }
            return(checksum);
        }
Esempio n. 4
0
        public static Page GetPreviousPage(Page currentPage, System.Collections.Generic.IReadOnlyList<Page> navStack)
        {
            Page previousPage = null;

            int currentPageIndex = GetCurrentPageIndex(currentPage, navStack);
            int previousPageIndex = currentPageIndex - 1;
            if (navStack.Count >= 0 && previousPageIndex >= 0)
                previousPage = navStack[previousPageIndex];

            return previousPage;
        }
        /**
         * Return true if the given loops form a valid polygon. Assumes that that all
         * of the given loops have already been validated.
         */

        public static bool IsValidPolygon(System.Collections.Generic.IReadOnlyList <S2Loop> loops)
        {
            // If a loop contains an edge AB, then no other loop may contain AB or BA.
            // We only need this test if there are at least two loops, assuming that
            // each loop has already been validated.
            if (loops.Count > 1)
            {
                System.Collections.Generic.IDictionary <UndirectedEdge, LoopVertexIndexPair> edges = new Dictionary <UndirectedEdge, LoopVertexIndexPair>();
                for (var i = 0; i < loops.Count; ++i)
                {
                    var lp = loops[i];
                    for (var j = 0; j < lp.NumVertices; ++j)
                    {
                        var key   = new UndirectedEdge(lp.Vertex(j), lp.Vertex(j + 1));
                        var value = new LoopVertexIndexPair(i, j);
                        if (edges.ContainsKey(key))
                        {
                            var other = edges[key];
                            Debug.WriteLine(
                                "Duplicate edge: loop " + i + ", edge " + j + " and loop " + other.LoopIndex
                                + ", edge " + other.VertexIndex);
                            return(false);
                        }
                        else
                        {
                            edges[key] = value;
                        }
                    }
                }
            }

            // Verify that no loop covers more than half of the sphere, and that no
            // two loops cross.
            for (var i = 0; i < loops.Count; ++i)
            {
                if (!loops[i].IsNormalized)
                {
                    Debug.WriteLine("Loop " + i + " encloses more than half the sphere");
                    return(false);
                }
                for (var j = i + 1; j < loops.Count; ++j)
                {
                    // This test not only checks for edge crossings, it also detects
                    // cases where the two boundaries cross at a shared vertex.
                    if (loops[i].ContainsOrCrosses(loops[j]) < 0)
                    {
                        Debug.WriteLine("Loop " + i + " crosses loop " + j);
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 6
0
        public static int GetCurrentPageIndex(Page currentPage, System.Collections.Generic.IReadOnlyList<Page> navStack)
        {
            int stackCount = navStack.Count;
            for (int x = 0; x < stackCount; x++)
            {
                var view = navStack[x];
                if (view == currentPage)
                    return x;
            }

            return stackCount - 1;
        }
Esempio n. 7
0
        private async void BtnDescriptorsClicked(object sender, EventArgs e)
        {
            if (Characteristic != null)
            {
                descriptors = await Characteristic.GetDescriptorsAsync();

                descriptor = (IDescriptor)Characteristic.GetDescriptorAsync(Guid.Parse("guid"));
                this.RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "Descriptors: " + descriptors + "Descriptor: " + descriptor, ToastLength.Long).Show();
                });
            }
            else
            {
                Toast.MakeText(this, "Characteristic is Empty", ToastLength.Long).Show();
            }
        }
 public void ValuesToObjects_UnitTest()
 {
     Newtonsoft.Json.Linq.JObject jObject = default(Newtonsoft.Json.Linq.JObject);
     System.Func <Newtonsoft.Json.Linq.JToken, T> creator = default(System.Func <Newtonsoft.Json.Linq.JToken, T>);
     System.Collections.Generic.IReadOnlyList <T> _retVal = default(System.Collections.Generic.IReadOnlyList <T>);
     ExecuteMethod(
         () =>
     {
         jObject = new Newtonsoft.Json.Linq.JObject();
         creator = default(System.Func <Newtonsoft.Json.Linq.JToken, T>); //No Constructor
         ValuesToObjects_PreCondition(ref jObject, ref creator);
     },
         () =>
     {
         _retVal = DynCon.OSI.VSO.ReSTClient.JsonParsers.ValuesToObjects <object>(jObject, creator);
     },
         () =>
     {
         ValuesToObjects_PostValidate(jObject, creator, _retVal);
     });
 }
Esempio n. 9
0
        private double PercentageOfExpectedQuotesFound(System.Collections.Generic.IReadOnlyList <BookScript> books)
        {
            var totalExpectedQuotesInIncludedChapters = 0;
            var totalVersesWithExpectedQuotes         = 0;

            var expectedQuotes = ControlCharacterVerseData.Singleton.ExpectedQuotes;

            foreach (var book in expectedQuotes.Keys)
            {
                var bookScript = books.FirstOrDefault(b => BCVRef.BookToNumber(b.BookId) == book);
                if (bookScript == null)
                {
                    continue;
                }
                foreach (var chapter in expectedQuotes[book])
                {
                    var chapterCounted = false;
                    foreach (var verseWithExpectedQuote in chapter.Value)
                    {
                        var referenceForExpectedQuote = new VerseRef(book, chapter.Key, verseWithExpectedQuote, ScrVers.English);
                        referenceForExpectedQuote.ChangeVersification(m_project.Versification);
                        var blocks =
                            bookScript.GetBlocksForVerse(referenceForExpectedQuote.ChapterNum, referenceForExpectedQuote.VerseNum).ToList();
                        if (!chapterCounted && blocks.Any())
                        {
                            totalExpectedQuotesInIncludedChapters += chapter.Value.Count;
                            chapterCounted = true;
                        }
                        if (blocks.Any(b => b.IsQuote))
                        {
                            totalVersesWithExpectedQuotes++;
                        }
                    }
                }
            }

            return(totalVersesWithExpectedQuotes * 100.0 / totalExpectedQuotesInIncludedChapters);
        }
Esempio n. 10
0
        public static double integrate(func f, System.Collections.Generic.IReadOnlyList <double> init_ticks, double eps1)
        {
            var points = new System.Collections.Generic.Stack <Point>();
            //var areas=new System.Collections.Generic.List<double>();
            double total_area = 0;
            double comp       = 0;

            foreach (var x in init_ticks)
            {
                points.Push(new Point(x, f(x)));
            }

            var    full_width = init_ticks.Last() - init_ticks.First();
            Point  right      = points.Pop();
            double eps        = eps1 * 4.0 / full_width;

            while (points.Count > 0)
            {
                //Console.WriteLine(points.Count);
                var left = points.Peek();
                var mid  = Integration.midpoint(ref left, ref right, f);
                if (Math.Abs(left.f + right.f - mid.f * 2.0) <= eps)
                {
                    //areas.Add((left.f+right.f+mid.f*2.0)*(right.x-left.x)/4.0);
                    double area = (left.f + right.f + mid.f * 2.0) * (right.x - left.x) / 4.0;
                    (total_area, comp) = neumaier_sum(total_area, area, comp);

                    right = points.Pop();
                }
                else
                {
                    points.Push(mid);
                }
            }
            return(total_area + comp);
        }
 public PSNetworkSecurityGroupRule(int priority, Microsoft.Azure.Batch.Common.NetworkSecurityGroupRuleAccess access, string sourceAddressPrefix, System.Collections.Generic.IReadOnlyList <string> sourcePortRanges = null)
 {
     this.omObject = new Microsoft.Azure.Batch.NetworkSecurityGroupRule(priority, access, sourceAddressPrefix, sourcePortRanges);
 }
Esempio n. 12
0
 public abstract Task Method2Async(string text, System.Collections.Generic.IReadOnlyList <string> names, CancellationToken cancellationToken);
Esempio n. 13
0
 public abstract Task Method2Async(string text, System.Collections.Generic.IReadOnlyList <string> names);
 partial void ValuesToObjects_PostValidate(Newtonsoft.Json.Linq.JObject jObject, System.Func <Newtonsoft.Json.Linq.JToken, T> creator, System.Collections.Generic.IReadOnlyList <T> _retVal);
Esempio n. 15
0
 public override void Method2(string text, System.Collections.Generic.IReadOnlyList <string> names)
 {
 }