public DynamicBody GenerateDynamicBody(Vector2 center, float radius)
        {
            DynamicBody       body = new DynamicBody(new Circle(center, radius), this);
            List <Vector2Int> list = new List <Vector2Int>();

            bodies.Add(body, list);

            SetUniformGrid(body);

            return(body);
        }
        public Vector2 MoveTo(DynamicBody body, Vector2 position)
        {
            Circle destCircle = new Circle(position, ((Circle)body.Shape).Radius);

            List <Body> overlapBodies = new List <Body>();

            foreach (Vector2Int coordinate in destCircle.GetGrid())
            {
                if (IsInside(coordinate.X, coordinate.Y))
                {
                    foreach (Body overlapBody in uniformGrid[coordinate.X, coordinate.Y])
                    {
                        if (overlapBody != body)
                        {
                            overlapBodies.Add(overlapBody);
                        }
                    }
                }
            }

            overlapBodies = overlapBodies.Distinct().ToList();

            if (overlapBodies.Count == 0)
            {
                body.SetCircle(destCircle);
                SetUniformGrid(body);
                return(((Circle)body.Shape).Center);
            }

            Vector2 max      = Vector2.Zero;
            bool    isStatic = false;

            foreach (Body overlapBody in overlapBodies)
            {
                Vector2 notOverlap = overlapBody.Shape.GetNotOverlapVector(destCircle.Center, destCircle.Radius);
                if (notOverlap != Vector2.Zero)
                {
                    if (overlapBody.IsStatic && !isStatic)
                    {
                        max      = notOverlap;
                        isStatic = true;
                    }
                    else if (overlapBody.IsStatic == isStatic && notOverlap.LengthSquared() > max.LengthSquared())
                    {
                        max = notOverlap;
                    }
                }
            }

            if (max != Vector2.Zero)
            {
                Circle finalCircle = new Circle(position + max, ((Circle)body.Shape).Radius);
                body.SetCircle(finalCircle);
                SetUniformGrid(body);
                return(((Circle)body.Shape).Center);
            }
            else
            {
                body.SetCircle(destCircle);
                SetUniformGrid(body);
                return(((Circle)body.Shape).Center);
            }
        }