/**
         *  Indexing structure to efficiently clipEdge() of a polygon. This is an
         * abstract class because we need to use if for both polygons (for
         * initToIntersection() and friends) and for sets of lists of points (for
         * initToSimplified()).
         *
         *  Usage -- in your subclass, create an array of vertex counts for each loop
         * in the loop sequence and pass it to this constructor. Overwrite
         * edgeFromTo(), calling decodeIndex() and use the resulting two indices to
         * access your accessing vertices.
         */

        private static void AddIntersection(S2Point a0,
                                            S2Point a1,
                                            S2Point b0,
                                            S2Point b1,
                                            bool addSharedEdges,
                                            int crossing, System.Collections.Generic.ICollection <ParametrizedS2Point> intersections)
        {
            if (crossing > 0)
            {
                // There is a proper edge crossing.
                var x = S2EdgeUtil.GetIntersection(a0, a1, b0, b1);
                var t = S2EdgeUtil.GetDistanceFraction(x, a0, a1);
                intersections.Add(new ParametrizedS2Point(t, x));
            }
            else if (S2EdgeUtil.VertexCrossing(a0, a1, b0, b1))
            {
                // There is a crossing at one of the vertices. The basic rule is simple:
                // if a0 equals one of the "b" vertices, the crossing occurs at t=0;
                // otherwise, it occurs at t=1.
                //
                // This has the effect that when two symmetric edges are encountered (an
                // edge an its reverse), neither one is included in the output. When two
                // duplicate edges are encountered, both are included in the output. The
                // "addSharedEdges" flag allows one of these two copies to be removed by
                // changing its intersection parameter from 0 to 1.
                double t = (a0 == b0 || a0 == b1) ? 0 : 1;
                if (!addSharedEdges && a1 == b1)
                {
                    t = 1;
                }
                intersections.Add(new ParametrizedS2Point(t, t == 0 ? a0 : a1));
            }
        }
示例#2
0
 public static void AddRange <T>(this System.Collections.Generic.ICollection <T> collection, IEnumerable <T> items)
 {
     foreach (var item in items)
     {
         collection.Add(item);
     }
 }
            /**
             * Return the set the unmarked points whose distance to "center" is less
             * than search_radius_, and mark these points. By construction, these points
             * will be contained by one of the vertex neighbors of "center".
             */

            public void Query(S2Point center, System.Collections.Generic.ICollection <S2Point> output)
            {
                output.Clear();

                var neighbors = new List <S2CellId>();

                S2CellId.FromPoint(center).GetVertexNeighbors(_level, neighbors);
                foreach (var id in neighbors)
                {
                    // Iterate over the points contained by each vertex neighbor.
                    foreach (var mp in _delegate[id])
                    {
                        if (mp.IsMarked)
                        {
                            continue;
                        }
                        var p = mp.Point;

                        if (center.Angle(p) <= _searchRadius)
                        {
                            output.Add(p);
                            mp.Mark();
                        }
                    }
                }
            }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="coll"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool Add <T>(System.Collections.Generic.ICollection <T> coll, object obj)
        {
            int count = coll.Count;

            coll.Add((T)obj);
            return(count != coll.Count);
        }
示例#5
0
        //
        // Add
        //

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="coll"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool Add <T, U>(System.Collections.Generic.ICollection <T> coll, U obj) where U : T
        {
            int count = coll.Count;

            coll.Add(obj);
            return(count != coll.Count);
        }
示例#6
0
        public static void FindAllCameraControllers(System.Collections.Generic.ICollection <ICamera> coll, System.Func <ICamera, bool> predicate = null)
        {
            if (coll == null)
            {
                throw new System.ArgumentNullException("coll");
            }

            if (predicate == null)
            {
                var e = _cameras.GetEnumerator();
                while (e.MoveNext())
                {
                    coll.Add(e.Current);
                }

                var ucams = Camera.allCameras;
                foreach (var c in ucams)
                {
                    coll.Add(c.AddOrGetComponent <UnityCamera>());
                }
            }
            else
            {
                var e = _cameras.GetEnumerator();
                while (e.MoveNext())
                {
                    if (predicate(e.Current))
                    {
                        coll.Add(e.Current);
                    }
                }

                var ucams = Camera.allCameras;
                foreach (var c in ucams)
                {
                    var uc = c.AddOrGetComponent <UnityCamera>();
                    if (predicate(uc))
                    {
                        coll.Add(uc);
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Removes all but mentioned items (i.e. determined by Linq expression) from the specified collection.
        /// <locDE><para />Entfernt alle außer die angegebenen Elemente (z.B. ermittelt durch Linq Ausdruck) von der angegebenen Collection.</locDE>
        /// </summary>
        /// <typeparam name="T">The type of the T.<locDE><para />Generischer Datentyp T.</locDE></typeparam>
        /// <param name="collection">The collection.<locDE><para />Die Collection.</locDE></param>
        /// <param name="condition">The condition.<locDE><para />Die Bedingung.</locDE></param>
        /// <example>
        /// Removes all elements but those with IsSelected property set to true.
        /// <locDE><para />Entfernt alle Elemente außer jenen, deren Eigenschaft IsSelected = true enthält.</locDE>
        /// <code>
        /// var collection = new ObservableCollection&lt;SelectableItem&gt;();
        /// collection.RemoveAllBut(x =&gt; x.IsSelected);
        /// </code>
        /// </example>
        /// <returns>Number of removed items.<locDE><para />Anzahl der entfernten Elemente.</locDE></returns>
        public static int RemoveAllBut <T>(this System.Collections.Generic.ICollection <T> collection, Func <T, bool> condition)
        {
            if (null == collection)
            {
                return(0);
            }

            // .ToList() saves us from "collection was modified" exception
            // .ToList() bewahrt uns vor einer "Collection wurde verändert" Ausnahme.
            var itemsToKeep = collection.Where(condition).ToList();

            int itemsRemoved = collection.Count - itemsToKeep.Count();

            collection.Clear();
            foreach (var itemToKeep in itemsToKeep)
            {
                collection.Add(itemToKeep);
            }

            return(itemsRemoved);
        }
示例#8
0
        /// <summary>
        /// Adds if collection not already contains the given element.
        /// <locDE><para />Fügt das Element hinzu, falls es noch nicht in der Liste ist.</locDE>
        /// </summary>
        /// <typeparam name="T">The element type of the list.<locDE><para />Elementtyp der Liste.</locDE></typeparam>
        /// <param name="collection">The collection.<locDE><para />Die Liste.</locDE></param>
        /// <param name="value">The value.<locDE><para />Der Wert.</locDE></param>
        /// <param name="comparer">The comparer method (or null).<locDE><para />Die Vergleichsmethode (oder null).</locDE></param>
        /// <returns>True if element was not contained yet.<locDE><para />True falls das Element noch nicht in der Liste war.</locDE></returns>
        public static bool AddIfNotContains <T>(this System.Collections.Generic.ICollection <T> collection, T value,
                                                System.Collections.Generic.IEqualityComparer <T> comparer = null)
        {
            if (null == collection)
            {
                return(false);
            }

            if (IgnoreNullValues && null == value)
            {
                // Don't add null values
                // Null Wert nicht hinzufügen
                return(false);
            }

            if (null == comparer)
            {
                if (collection.Contains(value))
                {
                    // Already contained
                    // Bereits enthalten
                    return(false);
                }
            }
            else
            {
                if (collection.Contains(value, comparer))
                {
                    // Already contained
                    // Bereits enthalten
                    return(false);
                }
            }

            collection.Add(value);
            return(true);
        }
示例#9
0
 internal bool AddAuthor(Account author)
 {
     Authors.Add(author);
     return(true);
 }
示例#10
0
        public TramStatistics Start(int turnAroundTime,
                                    int peakFrequency,
                                    int numberOfTrams,
                                    int latenessThreshold = 60,
                                    bool debug            = false,
                                    IEnumerable <InputRow> stationFrequencies = null)
        {
            LatenessThreshold = latenessThreshold;

            Track = new Terrain(peakFrequency, turnAroundTime, SWITCH_DELAY, stationFrequencies);
            DEBUG = debug;

            TurnaroundTime   = turnAroundTime;
            InitialTrams     = numberOfTrams;
            CurrentFrequency = numberOfTrams;

            TramArrived   += HandleArrival;
            TramDeparture += HandleDeparture;

            TramExpectedArrival   += HandleExpectedArrival;
            TramExpectedDeparture += HandleExpectedDeparture;

            // initialize trams to depot
            for (var i = 0; i < InitialTrams; i++)
            {
                Trams.Add(new Tram
                {
                    Id             = i,
                    CurrentStation = Track.GetPRDepot()
                });
            }

            var pr        = Track.GetPR().Timetable;
            var tramDelay = 0;

            foreach (var nextTram in Trams.Where(x => x.CurrentStation == Track.GetPRDepot()))
            {
                EventQueue.Add(new TransportArgs
                {
                    FromStation = Track.GetPRDepot(),
                    ToStation   = Track.NextStation(Track.GetPRDepot()),
                    Tram        = nextTram,
                    Type        = TransportArgsType.ExpectedArrival,
                    TriggerTime = tramDelay
                                  //normally + part is 0 as its from depot
                });
                tramDelay = Track.GetPR().Timetable.GetNextDepartureTime(tramDelay + 1).Value;
            }

            while (!EventQueue.IsEmpty)
            {
                ///next event
                var next = EventQueue.Min();

                //remove from top
                EventQueue.DeleteMin();

                //used for debug info
                if (DEBUG)
                {
                    WriteState(this, string.Concat($"[{next.TriggerTime}]", BuildState()));
                    DebugLine(this, next);
                }

                if (next.Type == TransportArgsType.ExpectedArrival)
                {
                    TramExpectedArrival(this, next);
                }

                if (next.Type == TransportArgsType.ExpectedDeparture)
                {
                    TramExpectedDeparture(this, next);
                }

                if (next.Type == TransportArgsType.Arrival)
                {
                    TramArrived(this, next);
                }

                if (next.Type == TransportArgsType.Departure)
                {
                    TramDeparture(this, next);
                }
            }

            var totalServedInDay = 0;

            // total served is serviced with every tram
            foreach (var tram in Track.Vertices)
            {
                totalServedInDay += tram.TotalPassengersServiced;
            }

            // return output statistics for the output analysis
            return(new TramStatistics()
            {
                TotalPassengersServiced = totalServedInDay,

                Punctuality = TotalPunctuality,

                TotalDelay = TotalDelay,

                HighLatenessTrams = Trams.Count(x => x.WasLate),

                TotalAverageWaitingTime = Track.Vertices
                                          .Where(wait => wait.TotalPassengersServiced != 0)
                                          .Sum(wait => (double)wait.TotalWaitingTime / wait.TotalPassengersServiced),

                MaximumDepartureLateness = MaxDepartureLateness
            });
        }
示例#11
0
 public bool Join(Account user)
 {
     Members.Add(user);
     return(true);
 }
示例#12
0
        /// <summary>
        /// Determines if contents of both lists are equal ignoring their order.
        /// <locDE><para />Ermittelt ob die beiden Listen den gleichen Inhalt haben (ohne Rücksicht auf die Reihenfolge).</locDE>
        /// </summary>
        /// <typeparam name="T">The element type of the lists.<locDE><para />Elementtyp der Listen.</locDE></typeparam>
        /// <param name="list1">The first list.<locDE><para />Erste Liste.</locDE></param>
        /// <param name="list2">The second list.<locDE><para />Zweite Liste.</locDE></param>
        /// <param name="diff">The found difference between the collections (if any).<locDE><para />Gefundene Unterschiede (falls nicht gleich).</locDE></param>
        /// <returns>True if equal.<locDE><para />True falls identisch.</locDE></returns>
        public static bool EqualContentsIgnoreOrder <T>(this System.Collections.Generic.IEnumerable <T> list1, System.Collections.Generic.IEnumerable <T> list2,
                                                        out System.Collections.Generic.ICollection <T> diff)
        {
            var listType            = typeof(System.Collections.Generic.List <>);
            var constructedListType = listType.MakeGenericType(typeof(T));

            diff = Activator.CreateInstance(constructedListType) as System.Collections.Generic.ICollection <T>;

            #region Handle list(s) being null

            if (null == list1 && null == list2)
            {
                return(true);
            }
            if (null == list1 && null != list2)
            {
                foreach (T s in list2)
                {
                    diff.Add(s);
                }
                return(false);
            }
            if (null != list1 && null == list2)
            {
                foreach (T s in list1)
                {
                    diff.Add(s);
                }
                return(false);
            }

            #endregion Handle list(s) being null

            // https://stackoverflow.com/questions/3669970/compare-two-listt-objects-for-equality-ignoring-order

            var cnt = new System.Collections.Generic.Dictionary <T, int>();
            foreach (T s in list1)
            {
                if (cnt.ContainsKey(s))
                {
                    cnt[s]++;
                }
                else
                {
                    cnt.Add(s, 1);
                }
            }
            foreach (T s in list2)
            {
                if (cnt.ContainsKey(s))
                {
                    cnt[s]--;
                }
                else
                {
                    diff.Add(s);
                }
            }
            //diff.Union(cnt.Where(x => x.Value != 0).Select(x => x.Key));
            System.Collections.Generic.IEnumerable <T> cntsNotZero = cnt.Where(x => x.Value != 0).Select(x => x.Key);
            if (null != cntsNotZero)
            {
                foreach (T cntNoZero in cntsNotZero)
                {
                    diff.AddIfNotContains(cntNoZero);
                }
            }
            return(0 == diff.Count());
        }
        private void initilizeflushTanks()
        {
            if (flushTanks.Count > 0)
            {
                return;
            }

            //the key is Fixture Units
            //the value is Flow (gallon (U.S.) per minute (gpm) (gal/min))
            flushTanks.Add(new KeyValuePair <double, double>(1, 3.0));
            flushTanks.Add(new KeyValuePair <double, double>(2, 5.0));
            flushTanks.Add(new KeyValuePair <double, double>(3, 6.5));
            flushTanks.Add(new KeyValuePair <double, double>(4, 8.0));
            flushTanks.Add(new KeyValuePair <double, double>(5, 9.4));
            flushTanks.Add(new KeyValuePair <double, double>(6, 10.7));
            flushTanks.Add(new KeyValuePair <double, double>(7, 11.8));
            flushTanks.Add(new KeyValuePair <double, double>(8, 12.8));
            flushTanks.Add(new KeyValuePair <double, double>(9, 13.7));
            flushTanks.Add(new KeyValuePair <double, double>(10, 14.6));
            flushTanks.Add(new KeyValuePair <double, double>(11, 15.4));
            flushTanks.Add(new KeyValuePair <double, double>(12, 16.0));
            flushTanks.Add(new KeyValuePair <double, double>(13, 16.5));
            flushTanks.Add(new KeyValuePair <double, double>(14, 17.0));
            flushTanks.Add(new KeyValuePair <double, double>(15, 17.5));
            flushTanks.Add(new KeyValuePair <double, double>(16, 18.0));
            flushTanks.Add(new KeyValuePair <double, double>(17, 18.4));
            flushTanks.Add(new KeyValuePair <double, double>(18, 18.8));
            flushTanks.Add(new KeyValuePair <double, double>(19, 19.2));
            flushTanks.Add(new KeyValuePair <double, double>(20, 19.6));
            flushTanks.Add(new KeyValuePair <double, double>(25, 21.5));
            flushTanks.Add(new KeyValuePair <double, double>(30, 23.3));
            flushTanks.Add(new KeyValuePair <double, double>(35, 24.9));
            flushTanks.Add(new KeyValuePair <double, double>(40, 26.3));
            flushTanks.Add(new KeyValuePair <double, double>(45, 27.7));
            flushTanks.Add(new KeyValuePair <double, double>(50, 29.1));
            flushTanks.Add(new KeyValuePair <double, double>(60, 32.0));
            flushTanks.Add(new KeyValuePair <double, double>(70, 35.0));
            flushTanks.Add(new KeyValuePair <double, double>(80, 38.0));
            flushTanks.Add(new KeyValuePair <double, double>(90, 41.0));
            flushTanks.Add(new KeyValuePair <double, double>(100, 43.5));
            flushTanks.Add(new KeyValuePair <double, double>(120, 48.0));
            flushTanks.Add(new KeyValuePair <double, double>(140, 52.5));
            flushTanks.Add(new KeyValuePair <double, double>(160, 57.0));
            flushTanks.Add(new KeyValuePair <double, double>(180, 61.0));
            flushTanks.Add(new KeyValuePair <double, double>(200, 65.0));
            flushTanks.Add(new KeyValuePair <double, double>(225, 70.0));
            flushTanks.Add(new KeyValuePair <double, double>(250, 75.0));
            flushTanks.Add(new KeyValuePair <double, double>(275, 80.0));
            flushTanks.Add(new KeyValuePair <double, double>(300, 85.0));
            flushTanks.Add(new KeyValuePair <double, double>(400, 105.0));
            flushTanks.Add(new KeyValuePair <double, double>(500, 124.0));
            flushTanks.Add(new KeyValuePair <double, double>(750, 170.0));
            flushTanks.Add(new KeyValuePair <double, double>(1000, 208.0));
            flushTanks.Add(new KeyValuePair <double, double>(1250, 239.0));
            flushTanks.Add(new KeyValuePair <double, double>(1500, 269.0));
            flushTanks.Add(new KeyValuePair <double, double>(1750, 297.0));
            flushTanks.Add(new KeyValuePair <double, double>(2000, 325.0));
            flushTanks.Add(new KeyValuePair <double, double>(2500, 380.0));
            flushTanks.Add(new KeyValuePair <double, double>(3000, 433.0));
            flushTanks.Add(new KeyValuePair <double, double>(4000, 525.0));
            flushTanks.Add(new KeyValuePair <double, double>(5000, 593.0));
        }
        private void initilizeflushValves()
        {
            if (flushValves.Count > 0)
            {
                return;
            }

            //the key is Fixture Units
            //the value is Flow (gallon (U.S.) per minute (gpm) (gal/min))
            flushValves.Add(new KeyValuePair <double, double>(5, 15.0));
            flushValves.Add(new KeyValuePair <double, double>(6, 17.4));
            flushValves.Add(new KeyValuePair <double, double>(7, 19.8));
            flushValves.Add(new KeyValuePair <double, double>(8, 22.2));
            flushValves.Add(new KeyValuePair <double, double>(9, 24.6));
            flushValves.Add(new KeyValuePair <double, double>(10, 27.0));
            flushValves.Add(new KeyValuePair <double, double>(11, 27.8));
            flushValves.Add(new KeyValuePair <double, double>(12, 28.6));
            flushValves.Add(new KeyValuePair <double, double>(13, 29.4));
            flushValves.Add(new KeyValuePair <double, double>(14, 30.2));
            flushValves.Add(new KeyValuePair <double, double>(15, 31.0));
            flushValves.Add(new KeyValuePair <double, double>(16, 31.8));
            flushValves.Add(new KeyValuePair <double, double>(17, 32.6));
            flushValves.Add(new KeyValuePair <double, double>(18, 33.4));
            flushValves.Add(new KeyValuePair <double, double>(19, 34.2));
            flushValves.Add(new KeyValuePair <double, double>(20, 35.0));
            flushValves.Add(new KeyValuePair <double, double>(25, 38.0));
            flushValves.Add(new KeyValuePair <double, double>(30, 42.0));
            flushValves.Add(new KeyValuePair <double, double>(35, 44.0));
            flushValves.Add(new KeyValuePair <double, double>(40, 46.0));
            flushValves.Add(new KeyValuePair <double, double>(45, 48.0));
            flushValves.Add(new KeyValuePair <double, double>(50, 50.0));
            flushValves.Add(new KeyValuePair <double, double>(60, 54.0));
            flushValves.Add(new KeyValuePair <double, double>(70, 58.0));
            flushValves.Add(new KeyValuePair <double, double>(80, 61.2));
            flushValves.Add(new KeyValuePair <double, double>(90, 64.3));
            flushValves.Add(new KeyValuePair <double, double>(100, 67.5));
            flushValves.Add(new KeyValuePair <double, double>(120, 73.0));
            flushValves.Add(new KeyValuePair <double, double>(140, 77.0));
            flushValves.Add(new KeyValuePair <double, double>(160, 81.0));
            flushValves.Add(new KeyValuePair <double, double>(180, 85.5));
            flushValves.Add(new KeyValuePair <double, double>(200, 90.0));
            flushValves.Add(new KeyValuePair <double, double>(225, 95.5));
            flushValves.Add(new KeyValuePair <double, double>(250, 101.0));
            flushValves.Add(new KeyValuePair <double, double>(275, 104.5));
            flushValves.Add(new KeyValuePair <double, double>(300, 108.0));
            flushValves.Add(new KeyValuePair <double, double>(400, 127.0));
            flushValves.Add(new KeyValuePair <double, double>(500, 143.0));
            flushValves.Add(new KeyValuePair <double, double>(750, 177.0));
            flushValves.Add(new KeyValuePair <double, double>(1000, 208.0));
            flushValves.Add(new KeyValuePair <double, double>(1250, 239.0));
            flushValves.Add(new KeyValuePair <double, double>(1500, 269.0));
            flushValves.Add(new KeyValuePair <double, double>(1750, 297.0));
            flushValves.Add(new KeyValuePair <double, double>(2000, 325.0));
            flushValves.Add(new KeyValuePair <double, double>(2500, 380.0));
            flushValves.Add(new KeyValuePair <double, double>(3000, 433.0));
            flushValves.Add(new KeyValuePair <double, double>(4000, 525.0));
            flushValves.Add(new KeyValuePair <double, double>(5000, 593.0));
        }