TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Rectangle Struct Reference

A rectangle representing an area in 2D space. More...

Inheritance diagram for TriDevs.TriEngine.Rectangle:
[legend]
Collaboration diagram for TriDevs.TriEngine.Rectangle:
[legend]

Public Member Functions

 Rectangle (Point< int > position, Point< int > size, Color?color=null)
 Initializes a new Rectangle with position and size based on two point objects. More...
 
 Rectangle (int x, int y, int width, int height, Color?color=null)
 Initializes a new rectangle with specified position and size. More...
 
bool Intersects (Rectangle other)
 Returns whether this rectangle is intersecting with another rectangle. More...
 
bool Equals (Rectangle other)
 

Public Attributes

readonly int X
 The X position of this rectangle, in screen pixels. More...
 
readonly int Y
 The Y position of this rectangle, in screen pixels. More...
 
readonly int Width
 The width of this rectangle in pixels. More...
 
readonly int Height
 The height of this rectangle in pixels. More...
 
readonly Color Color
 Optional color of this rectangle, if it is to be drawn onto the screen. More...
 

Detailed Description

A rectangle representing an area in 2D space.

Constructor & Destructor Documentation

TriDevs.TriEngine.Rectangle.Rectangle ( Point< int >  position,
Point< int >  size,
Color color = null 
)

Initializes a new Rectangle with position and size based on two point objects.

Parameters
positionThe point to get position from.
sizeThe point to get width and height from.
colorColor of this rectangle, set to null for default color of black.
66  : this(position.X, position.Y, size.X, size.Y, color)
67  {
68 
69  }
TriDevs.TriEngine.Rectangle.Rectangle ( int  x,
int  y,
int  width,
int  height,
Color color = null 
)

Initializes a new rectangle with specified position and size.

Parameters
xX-position of this rectangle, in screen pixels.
yY-position of this rectangle, in screen pixels.
widthWidth of this rectangle, in pixels.
heightHeight of this rectangle, in pixels.
colorColor of this rectangle, set to null for default color of black.
80  {
81  X = x;
82  Y = y;
83  Width = width;
84  Height = height;
85  Color = color.HasValue ? color.Value : Color.Black;
86  }

Member Function Documentation

bool TriDevs.TriEngine.Rectangle.Equals ( Rectangle  other)
114  {
115  return X == other.X && Y == other.Y && Width == other.Width && Height == other.Height;
116  }
bool TriDevs.TriEngine.Rectangle.Intersects ( Rectangle  other)

Returns whether this rectangle is intersecting with another rectangle.

Parameters
otherRectangle to check against.
Returns
True if this rectangle is intersecting with the other rectangle, false otherwise.
94  {
95  if (Equals(other))
96  return true;
97 
98  if (X >= other.X && (X + Width) <= (other.X + other.Width))
99  return true;
100 
101  if (X < other.X && (X + Width) >= other.X)
102  return true;
103 
104  if (Y >= other.Y && (Y + Height) <= (other.Y + other.Height))
105  return true;
106 
107  if (Y < other.Y && (Y + Height) >= other.Y)
108  return true;
109 
110  return false;
111  }

Member Data Documentation

readonly Color TriDevs.TriEngine.Rectangle.Color

Optional color of this rectangle, if it is to be drawn onto the screen.

readonly int TriDevs.TriEngine.Rectangle.Height

The height of this rectangle in pixels.

readonly int TriDevs.TriEngine.Rectangle.Width

The width of this rectangle in pixels.

readonly int TriDevs.TriEngine.Rectangle.X

The X position of this rectangle, in screen pixels.

readonly int TriDevs.TriEngine.Rectangle.Y

The Y position of this rectangle, in screen pixels.


The documentation for this struct was generated from the following file: