コード例 #1
0
        /// <summary>
        /// Spočítá kontaktní páry
        /// </summary>
        /// <param name="e1">Bod/hrana</param>
        /// <param name="e2">Bod/hrana</param>
        private void GetContactPairs(object e1, object e2)
        {
            switch (TouchType)
            {
                case ContactType.VertexVertex:
                    Pairs = new ContactPair[1];
                    Pairs[0] = new ContactPair((PointF)e1, (PointF)e2);
                    break;
                case ContactType.VertexEdge:
                    if (e1.GetType() == typeof(PointF[]))
                    {
                        Pairs = new ContactPair[1];
                        Pairs[0] = new ContactPair(ClosestPointOnEdge((PointF[])e1, (PointF)e2), (PointF)e2);
                    }
                    else if (e2.GetType() == typeof(PointF[]))
                    {
                        Pairs = new ContactPair[1];
                        Pairs[0] = new ContactPair((PointF)e1, ClosestPointOnEdge((PointF[])e2, (PointF)e1));
                    }
                    else throw new ArgumentException();
                    break;
                case ContactType.EdgeEdge:
                    Pairs = new ContactPair[4];
                    PointF[] Edge1 = (PointF[])e1, Edge2 = (PointF[])e2;

                    Pairs[0] = new ContactPair(Edge1[0], ClosestPointOnEdge(Edge2, Edge1[0]));
                    Pairs[1] = new ContactPair(Edge1[1], ClosestPointOnEdge(Edge2, Edge1[1]));
                    Pairs[2] = new ContactPair(ClosestPointOnEdge(Edge1, Edge2[0]), Edge2[0]);
                    Pairs[3] = new ContactPair(ClosestPointOnEdge(Edge1, Edge2[1]), Edge2[1]);

                    Array.Sort<ContactPair>(Pairs, new Comparison<ContactPair>(CompareCP));
                    break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Zredukuje kontaktní páry na jeden jediný
        /// </summary>
        private void Reduce()
        {
            ContactPair[] Single = new ContactPair[1];
            Single[0] = new ContactPair(Pairs[0].A, Pairs[0].B);

            int len = Pairs.Length;
            for (int i = 1; i < len; i++)
            {
                Single[0].A.X += Pairs[i].A.X;
                Single[0].A.Y += Pairs[i].A.Y;

                Single[0].B.X += Pairs[i].B.X;
                Single[0].B.Y += Pairs[i].B.Y;
            }

            Single[0].A.X /= len; Single[0].B.X /= len;
            Single[0].A.Y /= len; Single[0].B.Y /= len;
            Pairs = Single;
        }
コード例 #3
0
 /// <summary>
 /// Porovnávač páru dotyku
 /// </summary>
 /// <param name="p1">První pár</param>
 /// <param name="p2">Druhý pár</param>
 /// <returns>Porovnání</returns>
 private static int CompareCP(ContactPair p1, ContactPair p2)
 {
     if (p1.DistanceSquared == p2.DistanceSquared) return 0;
     return (p1.DistanceSquared > p2.DistanceSquared) ? 1 : -1;
 }