public static bool CheckOverlap(Shape2D shape1, Shape2D shape2)
        {
            ShapeTypes2D type1 = shape1.ShapeType;
            ShapeTypes2D type2 = shape2.ShapeType;

            // TODO: Handle point-point intersections.
            if (type1 == ShapeTypes2D.Point)
            {
                return(shape2.Contains(shape1.Position));
            }

            if (type2 == ShapeTypes2D.Point)
            {
                return(shape1.Contains(shape2.Position));
            }

            // By ensuring that the second shape sorts after the first (as far as shape type), the total number of
            // switch cases can be lowered.
            if ((int)type1 > (int)type2)
            {
                Shape2D temp = shape1;
                shape1 = shape2;
                shape2 = temp;
            }

            switch (type1)
            {
            case ShapeTypes2D.Arc: return(CheckOverlap((Arc)shape1, shape2));

            case ShapeTypes2D.Circle: return(CheckOverlap((Circle)shape1, shape2));

            case ShapeTypes2D.Rectangle: return(CheckOverlap((Rectangle)shape1, (Rectangle)shape2));
            }

            return(false);
        }
Exemple #2
0
 protected Shape2D(ShapeTypes2D shapeType)
 {
     ShapeType = shapeType;
 }