Esempio n. 1
0
    public bool IntersectsWithCircle(ICircle aCircle)
    {
        float testX = aCircle.GetCenterX();
        float testY = aCircle.GetCenterY();

        if (aCircle.GetCenterX() < this.GetX())
        {
            testX = this.GetX();
        }
        else if (aCircle.GetCenterX() > this.GetX() + this.GetWidth())
        {
            testX = this.GetX() + this.GetWidth();
        }
        if (aCircle.GetCenterY() < this.GetY())
        {
            testY = this.GetY();
        }
        else if (aCircle.GetCenterY() > this.GetY() + this.GetHeight())
        {
            testY = this.GetY() + this.GetHeight();
        }

        float distanceX = aCircle.GetCenterX() - testX;
        float distanceY = aCircle.GetCenterY() - testY;
        float distance  = (int)Math.Sqrt((distanceX * distanceX) + (distanceY * distanceY));

        return(distance <= aCircle.GetRadius());
    }
Esempio n. 2
0
        private void Builder(object sender, RoutedEventArgs e)
        {
            Builder builder = new ComplexObjectBuilder();

            builder.CreateComplexObject();
            builder.SetCircle();
            builder.SetSquare();

            ICircle circle = builder.ComplexObject.Circle;
            ISquare square = builder.ComplexObject.Square;

            Rectangle rect = new Rectangle()
            {
                Fill = new SolidColorBrush(square.GetSqureColor()), Height = square.GetSideSize(), Width = square.GetSideSize()
            };
            Ellipse el = new Ellipse()
            {
                Fill = new SolidColorBrush(circle.GetCirleColor()), Height = circle.GetRadius() * 2, Width = circle.GetRadius() * 2
            };

            Grid grid = new Grid();

            grid.Children.Add(rect);
            grid.Children.Add(el);

            Canvas.SetLeft(grid, 10);
            Canvas.SetTop(grid, y);
            canvas.Children.Add(grid);
            y += rect.Height + 5;
        }
        private IRectangle CalculateTargetBoundary(IShape aShape)
        {
            IRectangle targetBoundary;

            if (typeof(ICircle).IsAssignableFrom(aShape.GetType()))
            {
                ICircle circleUserObject = (ICircle)aShape;
                float   width            = circleUserObject.GetRadius() * 2;
                targetBoundary = new Rectangle(circleUserObject.GetCenterX() - circleUserObject.GetRadius(), circleUserObject.GetCenterY() - circleUserObject.GetRadius(), width,
                                               width);
            }
            else
            {
                targetBoundary = (IRectangle)aShape;
            }
            return(targetBoundary);
        }
Esempio n. 4
0
    public bool IntersectsWithCircle(ICircle aCircle)
    {
        float distanceX = this.GetCenterX() - aCircle.GetCenterX();
        float distanceY = this.GetCenterY() - aCircle.GetCenterY();
        float distance  = (int)Math.Sqrt(distanceX * distanceX + distanceY * distanceY);

        return(distance <= this.GetRadius() + aCircle.GetRadius());
    }
Esempio n. 5
0
 private void DrawCircle(ICircle aCircle)
 {
     UnityEditor.Handles.DrawWireDisc(new Vector3(aCircle.GetCenterX(), aCircle.GetCenterY(), 0), new Vector3(0, 0, 0.1f), aCircle.GetRadius());
 }