コード例 #1
0
        /// <summary>
        /// Adding Circles inside given frame
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        public bool DrawShapeInsideFrame(IShape shape)
        {
            if (shape as Circle != null)
            {
                var circle = shape as Circle;

                //Only If same circle is present we can resize
                if (Circles.ContainsValue(circle))
                {
                    circle.DrawShape();
                    return(true);
                }
            }

            else if (shape as Rectangle != null)
            {
                var rectangle = shape as Rectangle;

                //Only If same circle is present we can resize
                if (Rectangles.ContainsValue(rectangle))
                {
                    rectangle.DrawShape();
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Adding Circles inside given frame
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        public bool MoveShapeInsideFrame(IShape shape, ResizeFactor resizeFactor)
        {
            if (shape as Circle != null)
            {
                var circle = shape as Circle;

                //Only If same circle is present we can resize
                if (Circles.ContainsValue(circle))
                {
                    var circleTobeMoved = new Circle(resizeFactor.NewValue, circle.Radius);

                    //check new radious fits inside frame then resize
                    if (IsValidPosition(circleTobeMoved))
                    {
                        var newCircle = Circles.FirstOrDefault(x => x.Value == circle).Value;
                        newCircle.MoveShape(resizeFactor.NewValue);
                        return(true);
                    }
                }
            }

            else if (shape as Rectangle != null)
            {
                var rectangle = shape as Rectangle;

                //Only If same circle is present we can resize
                if (Rectangles.ContainsValue(rectangle))
                {
                    var rectangleTobeMoved = new Rectangle(resizeFactor.NewValue, rectangle.Width, rectangle.Height);

                    //check new radious fits inside frame then resize
                    if (IsValidPosition(rectangleTobeMoved))
                    {
                        var newCircle = Rectangles.FirstOrDefault(x => x.Value == rectangle).Value;
                        newCircle.MoveShape(resizeFactor.NewValue);
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Adding Circles inside given frame
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        ///
        ///
        public bool AddShapeInsideFrame(IShape shape)
        {
            if (shape as Circle != null)
            {
                var circle = shape as Circle;
                if (Circles.ContainsValue(circle))
                {
                    return(false);
                }
                //If circle has valid cords and falls inside frame then only add it
                if (IsValidPosition(circle))
                {
                    Circles.Add(Circles.Count, circle);
                    return(true);
                }

                return(false);
            }

            else if (shape as Rectangle != null)
            {
                var rectangle = shape as Rectangle;
                if (Rectangles.ContainsValue(rectangle))
                {
                    return(false);
                }
                //If circle has valid cords and falls inside frame then only add it
                if (IsValidPosition(rectangle))
                {
                    Rectangles.Add(Rectangles.Count, rectangle);
                    return(true);
                }

                return(false);
            }

            return(false);
        }