Exemple #1
0
 public void UnseqequalityComparerViaBuilder2()
 {
     SCG.IEqualityComparer <C5.HashSet <int> > h = C5.EqualityComparer <C5.HashSet <int> > .Default;
     C5.HashSet <int> s = new C5.HashSet <int>();
     s.Add(1); s.Add(2); s.Add(3);
     Assert.AreEqual(CHC.unsequencedhashcode(1, 2, 3), h.GetHashCode(s));
 }
Exemple #2
0
        private void CheckIntersection(EventPoint ep1, EventPoint ep2) // Sprawdza czy istnieje przecięcie pomiędzy dwoma zdarzeniami
        {
            if (CurrentSweepPoint == null)
            {
                return;
            }
            var currentSweepPoint = (PointFr)CurrentSweepPoint;

            if (ep1 == null || ep2 == null || ep1.Type == EventPointType.Intersection || ep2.Type == EventPointType.Intersection) // Zatrzymaj jeżeli conajmniej jedno ze zdarzeń jest puste lub jest przecięciem
            {
                return;
            }
            if (ep2.Segment == null || ep1.Segment == null)
            {
                throw new ArgumentException("Wartość ep1.Segment i ep2.Segment nie może być pusta");
            }

            var pNullable = ((LineSegmentFr)ep1.Segment).Intersection((LineSegmentFr)ep2.Segment); // Znajdź punkt przecięcia pomiędzy liniami zdarzeń

            if (pNullable == null)
            {
                return;
            }
            var p = (PointFr)pNullable;

            var existing = new C5.HashSet <EventPoint>();

            if (_intersections.ContainsKey(p))
            {
                existing = _intersections[p]; // Dodaj przecięcie do słownika
                _intersections.Remove(p);
            }

            existing.Add(ep1);
            existing.Add(ep2);
            _intersections.Add(p, existing);

            if (SweepLineValue == null)
            {
                throw new ArgumentException("Wartość miotły nie może być pusta");
            }

            var sweepLineValue = (LineFr)SweepLineValue;

            if (p.IsRightOf(sweepLineValue) || (sweepLineValue.Contains(p) && p.Y > currentSweepPoint.Y)) // Jeśli przecięcie jest po prawej stronie miotły lub na miotle i powyzej obecnego zdarzenia, dodaj do kolejki
            {
                var intersection = new EventPoint(p, EventPointType.Intersection, (LineSegmentFr?)null, this);
                EventQueue.Insert(p, intersection);
            }
        }
Exemple #3
0
 public void Add(CompositeFactor cf)
 {
     if (hashes.Add(cf.GetLongHashCode()))
     {
         items.Add(cf);
     }
 }
Exemple #4
0
        static void Main(string[] args)
        {
            var cfs      = new CompositeFactors();
            var cfHashes = new C5.HashSet <int>();
            var b        = ImmutableSortedDictionary.CreateBuilder <int, int>();

            b.Add(0, Limit);
            CompositeFactor initial = new CompositeFactor(b);

            cfs.Add(initial);
            cfHashes.Add(initial.GetHashCode());

            for (int i = 0; i < Limit - 1; i++)
            {
                if (i % 100 == 0)
                {
                    Console.Write($"{(double)i / Limit:P1}, count = {cfs.Count} / {cfs.HashCount}\r");
                }
                var firstUnexpanded = cfs.DeleteMin();
                var expansions      = firstUnexpanded.Expand();
                foreach (var e in expansions)
                {
                    cfs.Add(e);
                }
                cfs.Add(new CompositeFactor(firstUnexpanded.Factors.ToBuilder().Increase(0)));
            }
            Console.Out.WriteLine($"\nFound {Limit}th factor");
            var   answerFactor = cfs.DeleteMin();
            mpz_t result       = answerFactor.Factors.Aggregate(new mpz_t(1), (res, f) => res * new mpz_t(Primes.Values[f.Key]).Power(f.Value)).Mod(123454321);

            Console.WriteLine(result);
        }
 /// <summary>
 /// Adds triangle. If his Vectors should align with another triangles vectors, they need to be the same instances
 /// </summary>
 /// <param name="trngls"></param>
 public void AddTriangleByReference(Triangle trngls)
 {
     C5.HashSet <Triangle> incidence = new C5.HashSet <Triangle>();
     triangleIncidence.Add(trngls, new ArrayList <Triangle>());
     //register each vertex
     foreach (Vector3 vertex in trngls.vertices)
     {
         if (!vertex2Triangle.ContainsKey(vertex))
         {
             vertex2Triangle[vertex] = new ArrayList <Triangle>();
         }
         else
         {
             foreach (Triangle triangle in vertex2Triangle[vertex])
             {
                 if (incidence.Contains(triangle))  //already found a common vertex
                 {
                     triangleIncidence[triangle].Add(trngls);
                     triangleIncidence[trngls].Add(triangle);
                 }
                 else
                 {
                     incidence.Add(triangle);  //first common vertex found -> remember it
                 }
             }
         }
         vertex2Triangle[vertex].Add(trngls);
     }
 }
Exemple #6
0
        public Nav2dNode findClosestAccessibleNodeInGrid(Vector3Int cellPos, Vector3 targetPos)
        {
            Nav2dNode node = null;

            C5.HashSet <Vector3Int> explored = new C5.HashSet <Vector3Int>();
            Queue <Vector3Int>      opened   = new Queue <Vector3Int>();

            opened.Enqueue(cellPos);

            // dont try to long
            for (int i = 0; i < 20; i++)
            {
                Vector3Int current = opened.Dequeue();
                Nav2dCell  cell    = FindNavCellAtPosition(current);

                node = cell?.findClosestAccessibleNodeInCell(targetPos);

                if (node != null)
                {
                    break;
                }

                explored.Add(current);

                Vector3Int[] neighbors =
                {
                    current + new Vector3Int(0,   1, 0),
                    current + new Vector3Int(0,  -1, 0),
                    current + new Vector3Int(-1,  0, 0),
                    current + new Vector3Int(1,   0, 0)
                };

                foreach (var n in neighbors)
                {
                    if (!explored.Contains(n))
                    {
                        opened.Enqueue(n);
                    }
                }
            }
            return(node);
        }