public static bool Contains(this IReadOnlyRectangle rectangle, Vector2 location) { var outsideX = (location.X < rectangle.Min.X) || (rectangle.Max.X < location.X); var outsideY = (location.Y < rectangle.Min.Y) || (rectangle.Max.Y < location.Y); return(!(outsideX || outsideY)); }
public static bool Contains(this IReadOnlyRectangle rectangle, IReadOnlyRectangle rectangleB) { var outsideX = (rectangleB.Min.X < rectangle.Min.X) || (rectangle.Max.X < rectangleB.Max.X); var outsideY = (rectangleB.Min.Y < rectangle.Min.Y) || (rectangle.Max.Y < rectangleB.Max.Y); return(!(outsideX || outsideY)); }
public static bool Intersects(this IReadOnlyRectangle rectangleA, IReadOnlyRectangle rectangleB) { bool noXintersect = (rectangleA.Max.X <= rectangleB.Min.X) || (rectangleA.Min.X >= rectangleB.Max.X); bool noYintersect = (rectangleA.Max.Y <= rectangleB.Min.Y) || (rectangleA.Min.Y >= rectangleB.Max.Y); return(!(noXintersect || noYintersect)); }
/// <summary> /// Draws a rectangle using the provided texture coordinates. /// </summary> /// <param name="rectangle">The rectangle.</param> /// <param name="texCoords">The texture coordinates of the rectangle.</param> public static void Draw(this IReadOnlyRectangle rectangle, IReadOnlyRectangle texCoords) { //TODO: draw a rectangle with geometrical coordinates taken from rectangle and texture coordinates taken from texCoords GL.Begin(PrimitiveType.Quads); GL.Vertex2(rectangle.Min); GL.Vertex2(rectangle.Max.X, rectangle.Min.Y); GL.Vertex2(rectangle.Max); GL.Vertex2(rectangle.Min.X, rectangle.Max.Y); GL.End(); }
internal static void DrawRect(IReadOnlyRectangle rectangle, IReadOnlyRectangle texCoords) { GL.Begin(PrimitiveType.Quads); GL.TexCoord2(texCoords.MinX, texCoords.MinY); GL.Vertex2(rectangle.MinX, rectangle.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MinY); GL.Vertex2(rectangle.MaxX, rectangle.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rectangle.MaxX, rectangle.MaxY); GL.TexCoord2(texCoords.MinX, texCoords.MaxY); GL.Vertex2(rectangle.MinX, rectangle.MaxY); GL.End(); }
private static void DrawRectangleTexture(IReadOnlyRectangle rectangle, IReadOnlyRectangle texCoords) { GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Texture2D); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(texCoords.MinX, texCoords.MinY); GL.Vertex2(rectangle.MinX, rectangle.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MinY); GL.Vertex2(rectangle.MaxX, rectangle.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rectangle.MaxX, rectangle.MaxY); GL.TexCoord2(texCoords.MinX, texCoords.MaxY); GL.Vertex2(rectangle.MinX, rectangle.MaxY); GL.End(); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Blend); }
private static void DrawCircleTexture(IReadOnlyCircle circle, IReadOnlyRectangle texCoords) { GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.Begin(PrimitiveType.Quads); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.TexCoord2(texCoords.MinX, texCoords.MinY); GL.Vertex2(circle.Center.X - circle.Radius, circle.Center.Y - circle.Radius); GL.TexCoord2(texCoords.MaxX, texCoords.MinY); GL.Vertex2(circle.Center.X + circle.Radius, circle.Center.Y - circle.Radius); GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(circle.Center.X + circle.Radius, circle.Center.Y + circle.Radius); GL.TexCoord2(texCoords.MinX, texCoords.MaxY); GL.Vertex2(circle.Center.X - circle.Radius, circle.Center.Y + circle.Radius); GL.End(); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Texture2D); }
public Rectangle(IReadOnlyRectangle rectangle) { Min = rectangle.Min; Size = rectangle.Size; }