Example #1
0
        public void DListRemoveAtTest()
        {
            int[]       arr  = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            DList <int> list = new DList <int>(arr);

            list.RemoveAt(0);
            Assert.AreEqual(9, list.Count);
            Assert.AreEqual(2, list[0]);
            list.RemoveAt(8);
            Assert.AreEqual(8, list.Count);
            Assert.AreEqual(9, list[7]);
        }
Example #2
0
        public static IListSource <Point> ComputeConvexHull(List <Point> points, bool sortInPlace)
        {
            if (points.Count < 2)
            {
                return(new DList <Point>((IReadOnlyList <Point>)points));
            }
            if (!sortInPlace)
            {
                points = new List <Point>(points);
            }
            points.Sort((a, b) =>
                        a.X == b.X ? a.Y.CompareTo(b.Y) : a.X > b.X ? 1 : -1);

            // Importantly, DList provides O(1) insertion at beginning and end
            DList <Point> hull = new DList <Point>();
            int           L = 0, U = 0;   // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                // right turn (clockwise) => negative cross product (for Y-up coords)
                Point p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count - 2]).Cross(p.Sub(p1)) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0)                 // when U == 0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
                Debug.Assert(U + L == hull.Count + 1);
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull);
        }
        public static PointF[] ComputeConvexHull(List<PointF> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
                points = new List<PointF>(points);
            points.Sort((a, b) =>
              a.X == b.X ? a.Y.CompareTo(b.Y) : (a.X > b.X ? 1 : -1));

            DList<PointF> hull = new DList<PointF>();
            int L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                PointF p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && cross((p1 = hull.Last),hull[hull.Count - 2], points[i]) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && cross((p1 = hull.First), (hull[1]), points[i]) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                    hull.PushFirst(p);
                U++;
            }

            try {

                hull.RemoveAt(hull.Count - 1);

            } catch (System.Exception) {

            }

            return hull.ToArray();
        }
Example #4
0
        public static IListSource <double[]> ComputeConvexHull(List <double[]> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
            {
                points = new List <double[]>(points);
            }
            points.Sort((a, b) =>
                        a[0] == b[0] ? a[1].CompareTo(b[1]) : (a[0] > b[0] ? 1 : -1));

            // Importantly, DList provides O(1) insertion at beginning and end
            DList <double[]> hull = new DList <double[]>();
            int L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                double[] p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count - 2]).Cross(p.Sub(p1)) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
                Debug.Assert(U + L == hull.Count + 1);
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull);
        }
        public static PointF[] ComputeConvexHull(List <PointF> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
            {
                points = new List <PointF>(points);
            }
            points.Sort((a, b) =>
                        a.X == b.X ? a.Y.CompareTo(b.Y) : (a.X > b.X ? 1 : -1));

            DList <PointF> hull = new DList <PointF>();
            int            L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                PointF p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && cross((p1 = hull.Last), hull[hull.Count - 2], points[i]) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && cross((p1 = hull.First), (hull[1]), points[i]) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull.ToArray());
        }
Example #6
0
		protected override VList<LNode> AttachTriviaTo(ref LNode node, IListSource<Token> trivia, TriviaLocation loc, LNode parent, int indexInParent)
		{
			int nli;
			if (loc == TriviaLocation.Trailing && indexInParent == 1 && parent != null && parent.Calls(CodeSymbols.If, 3) && 
				(nli = trivia.LastIndexWhere(t => t.Type() == TokenType.Newline)) != -1) {
				// The 'else' keyword is invisible here, but it often appears on a line by 
				// itself; remove a newline to avoid creating a blank line when printing.
				var triviaSans = new DList<Token>(trivia);
				triviaSans.RemoveAt(nli);
				trivia = triviaSans;
			}
			return base.AttachTriviaTo(ref node, trivia, loc, parent, indexInParent);
		}
Example #7
0
        protected override VList <LNode> AttachTriviaTo(ref LNode node, IListSource <Token> trivia, TriviaLocation loc, LNode parent, int indexInParent)
        {
            int nli;

            if (loc == TriviaLocation.Trailing && indexInParent == 1 && parent != null && parent.Calls(CodeSymbols.If, 3) &&
                (nli = trivia.LastIndexWhere(t => t.Type() == TokenType.Newline)) != -1)
            {
                // The 'else' keyword is invisible here, but it often appears on a line by
                // itself; remove a newline to avoid creating a blank line when printing.
                var triviaSans = new DList <Token>(trivia);
                triviaSans.RemoveAt(nli);
                trivia = triviaSans;
            }
            return(base.AttachTriviaTo(ref node, trivia, loc, parent, indexInParent));
        }
Example #8
0
        public override void HoldStyle(Player player)
        {
            //int dust3 = Dust.NewDust(player.Top+new Vector2(player.direction*-10, 0), 0, 0, 87, 0f, 0f, 25, Color.Goldenrod, 1.5f);
            //Main.dust[dust3].noGravity = true;
            //Main.dust[dust3].velocity = new Vector2(0, 0);
            reloading = Math.Max(reloading, 0);
            //altfire = Math.Min(altfire, reloadspeed-1);
            if (reloading > 0)
            {
                reloading           = reloading = Math.Max(reloading + (reloadspeed - (altfire)), 0);
                player.itemRotation = (reloading / 7.5f) * -player.direction;
                item.holdStyle      = 1;
                int d = Dust.NewDust(player.itemLocation, 1, 1, 159, 0, 0, 0, Color.Goldenrod, 0.5f);
                Main.dust[d].noGravity = true;
                /*item.Center*/ player.itemLocation = ((player.direction > 0?player.Right:player.Left) - new Vector2(16, 8)) - (new Vector2(24, 2).RotatedBy(player.itemRotation) * player.direction);     //player.itemLocation-new Vector2(player.direction>0?16:0,0);
                if (RoundsLeft > 0 && -Math.Abs(player.itemRotation) % 1 <= 0.2f)
                {
                    //int a = (int)(item.damage*1.5f);
                    //GetWeaponDamage(player, ref a);

                    int b = Projectile.NewProjectile(player.itemLocation, new Vector2(4).RotatedBy(player.itemRotation), bullets[0].id == 14?160:bullets[0].id, player.GetWeaponDamage(item), item.knockBack, item.owner);                  //8,
                    if (bullets[0].id != 14)
                    {
                        Main.projectile[b].GetGlobalProjectile <ElementalGlobalProjectile>().extraAI = 8;
                    }
                    if (bullets[0].id == 14)
                    {
                        Main.projectile[b].aiStyle = 8;
                    }
                    RoundsLeft--;
                    if (bullets.Count > 0)
                    {
                        //if(bullets[0].id!=14)Main.projectile[b].aiStyle = bullets[0].id;
                        bullets.RemoveAt(0);
                    }
                }
            }
            if (reloading >= 100)
            {
                item.useAmmo = AmmoID.Bullet;
                for (int i = 0; i < RoundsMax; i++)
                {
                    bool            canShoot = false;
                    ProjectileStats p        = new ProjectileStats();
                    player.PickAmmo(item, ref p.id, ref p.speed, ref canShoot, ref p.damage, ref p.knockback);
                    if (canShoot)
                    {
                        bullets.Add(p);
                        RoundsLeft++;
                    }
                    else
                    {
                        break;
                    }
                    //RoundsLeft = RoundsMax;
                }
                item.useAmmo   = 0;
                reloading      = 0;
                item.holdStyle = 0;
                altfire        = 0;
            }
        }
Example #9
0
		public static IListSource<Point> ComputeConvexHull(List<Point> points, bool sortInPlace)
		{
			if (!sortInPlace)
				points = new List<Point>(points);
			points.Sort((a, b) => 
				a.X == b.X ? a.Y.CompareTo(b.Y) : a.X > b.X ? 1 : -1);

			// Importantly, DList provides O(1) insertion at beginning and end
			DList<Point> hull = new DList<Point>();
			int L = 0, U = 0; // size of lower and upper hulls

			// Builds a hull such that the output polygon starts at the leftmost point.
			for (int i = points.Count - 1; i >= 0 ; i--)
			{
				// right turn (clockwise) => negative cross product (for Y-up coords)
				Point p = points[i], p1;

				// build lower hull (at end of output list)
				while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count-2]).Cross(p.Sub(p1)) >= 0) {
					hull.RemoveAt(hull.Count-1);
					L--;
				}
				hull.PushLast(p);
				L++;

				// build upper hull (at beginning of output list)
				while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0) {
					hull.RemoveAt(0);
					U--;
				}
				if (U != 0) // when U == 0, share the point added above
					hull.PushFirst(p);
				U++;
				Debug.Assert(U + L == hull.Count + 1);
			}
			hull.RemoveAt(hull.Count - 1);
			return hull;
		}