示例#1
0
        private static bool CheckOverlap(Circle circle, Shape2D other)
        {
            switch (other.ShapeType)
            {
            case ShapeTypes2D.Circle: return(CheckOverlap(circle, (Circle)other));

            case ShapeTypes2D.Rectangle: return(CheckOverlap(circle, (Rectangle)other));
            }

            return(false);
        }
示例#2
0
        private static bool CheckOverlap(Arc arc, Shape2D other)
        {
            switch (other.Type)
            {
            case ShapeTypes2D.Arc: return(CheckOverlap(arc, (Arc)other));

            case ShapeTypes2D.Circle: return(CheckOverlap(arc, (Circle)other));

            case ShapeTypes2D.Rectangle: return(CheckOverlap(arc, (Rectangle)other));
            }

            return(false);
        }
示例#3
0
        public static bool CheckOverlap(Shape2D shape1, Shape2D shape2)
        {
            // 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)shape1.ShapeType > (int)shape2.ShapeType)
            {
                Shape2D temp = shape1;
                shape1 = shape2;
                shape2 = temp;
            }

            switch (shape1.ShapeType)
            {
            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);
        }
示例#4
0
        public static bool CheckOverlap(Shape2D shape1, Shape2D shape2)
        {
            var type1 = shape1.Type;
            var type2 = shape2.Type;

            if (type1 == ShapeTypes2D.Point)
            {
                return(shape2.Contains(shape1.Position, Coordinates.Absolute));
            }

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

            // 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)
            {
                var temp = shape1;
                shape1 = shape2;
                shape2 = temp;
                type1  = type2;
            }

            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);
        }
示例#5
0
        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);
        }