Ejemplo n.º 1
0
 public bool InsideRectangle(Rectangle rect)
 {
     return rect.ContainsPoint(this);
 }
Ejemplo n.º 2
0
        public void GenerateAABB()
        {
            float minX = float.MaxValue, minY = float.MaxValue, maxX = float.MinValue, maxY = float.MinValue;
            for (var node = filledPolygons.First; node != null; node = node.Next)
            {
                for (int i = 0; i < node.Value.Points.Count; ++i)
                {
                    var point = node.Value.Points[i];
                    if (point.X < minX) minX = point.X;
                    if (point.Y < minY) minY = point.Y;
                    if (point.X > maxX) maxX = point.X;
                    if (point.Y > maxY) maxY = point.Y;
                }
            }

            for (var node = outlinePolygons.First; node != null; node = node.Next)
            {
                for (int i = 0; i < node.Value.Points.Count; ++i)
                {
                    var point = node.Value.Points[i];
                    if (point.X < minX) minX = point.X;
                    if (point.Y < minY) minY = point.Y;
                    if (point.X > maxX) maxX = point.X;
                    if (point.Y > maxY) maxY = point.Y;
                }
            }
            AABB = new Rectangle(minX, minY, maxX - minX, maxY - minY);
        }
Ejemplo n.º 3
0
        private Rectangle Combine(Rectangle first, Rectangle second)
        {
            if (first == Rectangle.Zero && second == Rectangle.Zero) return Rectangle.Zero;
            if (first == Rectangle.Zero) return second;
            if (second == Rectangle.Zero) return first;

            float left = first.X;
            float top = first.Y;
            float right = first.X + first.Width;
            float bottom = first.Y + first.Height;

            if (second.X < left) left = second.X;
            if (second.Y < top) top = second.Y;
            if (second.X + second.Width > right) right = second.X + second.Width;
            if (second.Y + second.Height > bottom) bottom = second.Y + second.Height;

            return new Rectangle(left, top, right - left, bottom - top);
        }