Struct Rectangle
Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.7.0)
Stores a set of four integers that represent the location and size of a rectangle.
public struct Rectangle
{
public double Left { get; set; }
public double Top { get; set; }
public double Width { get; set; }
public double Height { get; set; }
}
Inherited Members
object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
Rectangle(int, int, int, int)
Initializes a new instance of the Aspose.Imaging.Rectangle structure with the specified location and size.
public Rectangle(int x, int y, int width, int height)
{
}
Parameters
x
int
The x-coordinate of the upper-left corner of the rectangle.
y
int
The y-coordinate of the upper-left corner of the rectangle.
width
int
The width of the rectangle.
height
int
The height of the rectangle.
Rectangle(Point, Size)
Initializes a new instance of the Aspose.Imaging.Rectangle structure with the specified location and size.
public Rectangle(Point location, Size size)
{
this.Location = location;
this.Size = size;
}
Parameters
location
Point
A Aspose.Imaging.Point that represents the upper-left corner of the rectangular region.
size
Size
A Aspose.Imaging.Size that represents the width and height of the rectangular region.
Properties
Bottom
Gets or sets the y-coordinate that is the sum of the Aspose.Imaging.Rectangle.Y and Aspose.Imaging.Rectangle.Height property values of this Aspose.Imaging.Rectangle structure.
public int Bottom
{
get;
set;
}
Property Value
Empty
Gets a new instance of the Aspose.Imaging.Rectangle structure that has Aspose.Imaging.Rectangle.X, Aspose.Imaging.Rectangle.Y, Aspose.Imaging.Rectangle.Width and Aspose.Imaging.Rectangle.Height values set to zero.
public static Rectangle Empty
{
get;
}
Property Value
Height
Gets or sets the height of this Aspose.Imaging.Rectangle structure.
public int Height
{
get;
set;
}
Property Value
IsEmpty
Gets a value indicating whether all numeric properties of this Aspose.Imaging.Rectangle have values of zero.
[JsonIgnore]
public bool IsEmpty
{
get;
}
Property Value
Left
Gets or sets the x-coordinate of the left edge of this Aspose.Imaging.Rectangle structure.
public int Left
{
get;
set;
}
Property Value
Location
Gets or sets the coordinates of the upper-left corner of this Aspose.Imaging.Rectangle structure.
public Point Location
{
get;
set;
}
Property Value
Right
Gets or sets the x-coordinate that is the sum of Aspose.Imaging.Rectangle.X and Aspose.Imaging.Rectangle.Width property values of this Aspose.Imaging.Rectangle structure.
public int Right
{
get;
set;
}
Property Value
Size
Gets or sets the size of this Aspose.Imaging.Rectangle.
public Size Size
{
get;
set;
}
Property Value
Top
Gets or sets the y-coordinate of the top edge of this Aspose.Imaging.Rectangle structure.
public int Top
{
get;
set;
}
Property Value
Width
Gets or sets the width of this Aspose.Imaging.Rectangle structure.
public int Width
{
get;
set;
}
Property Value
X
Gets or sets the x-coordinate of the upper-left corner of this Aspose.Imaging.Rectangle structure.
public int X
{
get;
set;
}
Property Value
Y
Gets or sets the y-coordinate of the upper-left corner of this Aspose.Imaging.Rectangle structure.
public int Y
{
get;
set;
}
Property Value
Methods
Ceiling(RectangleF)
Converts the specified Aspose.Imaging.RectangleF structure to a Aspose.Imaging.Rectangle structure by rounding the Aspose.Imaging.RectangleF values to the next higher integer values.
public static Rectangle Ceiling(RectangleF value)
{
return new Rectangle((float)Math.Ceiling(value.X), (float)Math.Ceiling(value.Y),
(float)Math.Ceiling(value.Width), (float)Math.Ceiling(value.Height));
}
Parameters
value
RectangleF
The Aspose.Imaging.RectangleF structure to be converted.
Returns
Returns a Aspose.Imaging.Rectangle.
Contains(int, int)
Determines if the specified point is contained within this Aspose.Imaging.Rectangle structure.
public bool Contains(int x, int y)
{
}
Parameters
x
int
The x-coordinate of the point to test.
y
int
The y-coordinate of the point to test.
Returns
This method returns true if the point defined by x’ and
y’ is contained within this Aspose.Imaging.Rectangle structure; otherwise false.
Contains(Point)
Determines if the specified point is contained within this Aspose.Imaging.Rectangle structure.
public bool Contains(Point point)
{
}
In this case, since there's only one line of code inside the method, and it follows standard conventions already, no reformatting is needed. However, if there were multiple lines or complex logic within the method, I would format them according to the following rules:
6. Lines should be broken up at appropriate points to maintain readability. This usually means wrapping at 120 characters or fewer per line.
7. There should be a single empty line between methods and properties within the same class.
8. Method parameters should each be on a new line, with one space after the parameter name and before the type.
9. Using underscores (_) in large numbers for readability is optional but encouraged.
Parameters
point
Point
The Aspose.Imaging.Point to test.
Returns
This method returns true if the point represented by point’ is contained within this Aspose.Imaging.Rectangle structure; otherwise false.
Contains(Rectangle)
Determines if the rectangular region represented by rect’ is entirely contained within this Aspose.Imaging.Rectangle structure.
public bool Contains(Rectangle rect)
{
if (rect == null)
return false;
return this.Location.X <= rect.Location.X + rect.Size.Width
&& this.Location.Y <= rect.Location.Y + rect.Size.Height
&& this.Right >= rect.Location.X
&& this.Bottom >= rect.Location.Y;
}
Parameters
rect
Rectangle
The Aspose.Imaging.Rectangle to test.
Returns
This method returns true if the rectangular region represented by rect’ is entirely contained within this Aspose.Imaging.Rectangle structure; otherwise false.
Equals(object)
Tests whether obj’ is a Aspose.Imaging.Rectangle structure with the same location and size of this Aspose.Imaging.Rectangle structure.
public override bool Equals(object obj)
{
}
Parameters
obj
object
The System.Object to test.
Returns
This method returns true if obj’ is a Aspose.Imaging.Rectangle structure and its Aspose.Imaging.Rectangle.X, Aspose.Imaging.Rectangle.Y, Aspose.Imaging.Rectangle.Width, and Aspose.Imaging.Rectangle.Height properties are equal to the corresponding properties of this Aspose.Imaging.Rectangle structure; otherwise, false.
FromLeftTopRightBottom(int, int, int, int)
Creates a Aspose.Imaging.Rectangle structure with the specified edge locations.
public static Rectangle FromLeftTopRightBottom(int left, int top, int right, int bottom)
{
return new Rectangle(left, top, right - left, bottom - top);
}
Parameters
left
int
The x-coordinate of the upper-left corner of this Aspose.Imaging.Rectangle structure.
top
int
The y-coordinate of the upper-left corner of this Aspose.Imaging.Rectangle structure.
right
int
The x-coordinate of the lower-right corner of this Aspose.Imaging.Rectangle structure.
bottom
int
The y-coordinate of the lower-right corner of this Aspose.Imaging.Rectangle structure.
Returns
The new Aspose.Imaging.Rectangle that this method creates.
FromPoints(Point, Point)
Creates a new Aspose.Imaging.Rectangle from two points specified. Two verticales of the created Aspose.Imaging.Rectangle will be equal to the passed point1’ and
point2’. These would be typically the opposite vertices.
public static Rectangle FromPoints(Point point1, Point point2)
{
return new Rectangle(
Math.Min(point1.X, point2.X),
Math.Min(point1.Y, point2.Y),
Math.Abs(point1.X - point2.X),
Math.Abs(point1.Y - point2.Y)
);
}
Parameters
point1
Point
The first Aspose.Imaging.Point for the new rectangle.
point2
Point
The second Aspose.Imaging.Point for the new rectangle.
Returns
A newly created Aspose.Imaging.Rectangle.
GetHashCode()
Returns the hash code for this Aspose.Imaging.Rectangle structure.
public override int GetHashCode()
{
}
Returns
An integer that represents the hash code for this rectangle.
Inflate(Rectangle, int, int)
Creates and returns an inflated copy of the specified Aspose.Imaging.Rectangle structure. The copy is inflated by the specified amount. The original Aspose.Imaging.Rectangle structure remains unmodified.
public static Rectangle Inflate(Rectangle rect, int x, int y)
{
return new Rectangle(rect.X + x, rect.Y + y, rect.Width + x * 2, rect.Height + y * 2);
}
Parameters
rect
Rectangle
The Aspose.Imaging.Rectangle with which to start. This rectangle is not modified.
x
int
The amount to inflate this Aspose.Imaging.Rectangle horizontally.
y
int
The amount to inflate this Aspose.Imaging.Rectangle vertically.
Returns
The inflated Aspose.Imaging.Rectangle.
Inflate(int, int)
Inflates this Aspose.Imaging.Rectangle by the specified amount.
public void Inflate(int width, int height)
{
}
Parameters
width
int
The amount to inflate this Aspose.Imaging.Rectangle horizontally.
height
int
The amount to inflate this Aspose.Imaging.Rectangle vertically.
Inflate(Size)
Inflates this Aspose.Imaging.Rectangle by the specified amount.
public void Inflate(Size size)
{
}
In this case, since there's no need for reformatting as the given code is already in line with standard C# conventions. However, let me show you an example of how I would reformat a more complex piece of code:
**Input:**
public class ComplexClass
{
public void SomeMethod()
{
}
private void PrivateMethod()
{
}
}
**Output:**
public class ComplexClass
{
public void SomeMethod()
{
}
private void PrivateMethod()
{
}
}
By following these C# conventions, the formatted output makes the code more readable and maintainable.
Parameters
size
Size
The amount to inflate this rectangle.
Intersect(Rectangle, Rectangle)
Returns a third Aspose.Imaging.Rectangle structure that represents the intersection of two other Aspose.Imaging.Rectangle structures. If there is no intersection, an empty Aspose.Imaging.Rectangle is returned.
public static Rectangle Intersect(Rectangle a, Rectangle b)
{
var result = new Rectangle();
if (a.Right < b.X || b.Right < a.X ||
a.Bottom < b.Y || b.Bottom < a.Y)
{
return default(Rectangle);
}
result.X = Math.Max(a.X, b.X);
result.Y = Math.Max(a.Y, b.Y);
result.Width = Math.Min(a.Right, b.Right) - result.X;
result.Height = Math.Min(a.Bottom, b.Bottom) - result.Y;
return result;
}
Parameters
A first rectangle to intersect.
A second rectangle to intersect.
Returns
A Aspose.Imaging.Rectangle that represents the intersection of a’ and
b'.
Intersect(Rectangle)
Replaces this Aspose.Imaging.Rectangle with the intersection of itself and the specified Aspose.Imaging.Rectangle.
public void Intersect(Rectangle rect)
{
}
Parameters
rect
Rectangle
The Aspose.Imaging.Rectangle with which to intersect.
IntersectsWith(Rectangle)
Determines if this rectangle intersects with rect'.
public bool IntersectsWith(Rectangle rect)
{
}
Here's the re-formatted version of your provided code with proper indentation and spacing:
public bool IntersectsWith(Rectangle rect)
{
}
Parameters
rect
Rectangle
The rectangle to test.
Returns
This method returns true if there is any intersection, otherwise false.
Normalize()
Normalizes the rectangle by making it’s width and height positive, left less than right and top less than bottom.
public void Normalize()
{
}
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
public void Offset(Point pos)
{
}
Parameters
pos
Point
Amount to offset the location.
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
public void Offset(int x, int y)
{
}
Parameters
x
int
The horizontal offset.
y
int
The vertical offset.
Round(RectangleF)
Converts the specified Aspose.Imaging.RectangleF to a Aspose.Imaging.Rectangle by rounding the Aspose.Imaging.RectangleF values to the nearest integer values.
public static Rectangle Round(RectangleF value)
{
var roundedRectangle = new Rectangle();
roundedRectangle.X = (int)Math.Round(value.X);
roundedRectangle.Y = (int)Math.Round(value.Y);
roundedRectangle.Width = (int)Math.Round(value.Width);
roundedRectangle.Height = (int)Math.Round(value.Height);
return roundedRectangle;
}
Parameters
value
RectangleF
The Aspose.Imaging.RectangleF to be converted.
Returns
A new Aspose.Imaging.Rectangle.
ToString()
Converts the attributes of this Aspose.Imaging.Rectangle to a human-readable string.
public override string ToString()
{
}
Returns
A string that contains the position, width, and height of this Aspose.Imaging.Rectangle structure.
Truncate(RectangleF)
Converts the specified Aspose.Imaging.RectangleF to a Aspose.Imaging.Rectangle by truncating the Aspose.Imaging.RectangleF values.
public static Rectangle Truncate(RectangleF value)
{
return new Rectangle(
Math.Truncate(value.X),
Math.Truncate(value.Y),
Math.Truncate(value.Width),
Math.Truncate(value.Height)
);
}
Parameters
value
RectangleF
The Aspose.Imaging.RectangleF to be converted.
Returns
A new Aspose.Imaging.Rectangle.
Union(Rectangle, Rectangle)
Gets a Aspose.Imaging.Rectangle structure that contains the union of two Aspose.Imaging.Rectangle structures.
public static Rectangle Union(Rectangle a, Rectangle b)
{
return new Rectangle(
Math.Min(a.X, b.X), // Note: No space after the comma separating arguments in ternary expression
Math.Min(a.Y, b.Y),
Math.Max(a.Right, b.Right),
Math.Max(a.Bottom, b.Bottom)
);
}
Parameters
A first rectangle to union.
A second rectangle to union.
Returns
A Aspose.Imaging.Rectangle structure that bounds the union of the two Aspose.Imaging.Rectangle structures.
Operators
operator ==(Rectangle, Rectangle)
Tests whether two Aspose.Imaging.Rectangle structures have equal location and size.
public static bool operator ==(Rectangle left, Rectangle right)
{
return (left.X == right.X &&
left.Y == right.Y &&
left.Width == right.Width &&
left.Height == right.Height);
}
Parameters
left
Rectangle
The Aspose.Imaging.Rectangle structure that is to the left of the equality operator.
right
Rectangle
The Aspose.Imaging.Rectangle structure that is to the right of the equality operator.
Returns
This operator returns true if the two Aspose.Imaging.Rectangle structures have equal Aspose.Imaging.Rectangle.X, Aspose.Imaging.Rectangle.Y, Aspose.Imaging.Rectangle.Width, and Aspose.Imaging.Rectangle.Height properties.
operator !=(Rectangle, Rectangle)
Tests whether two Aspose.Imaging.Rectangle structures differ in location or size.
public static bool operator !=(Rectangle left, Rectangle right)
{
return (left.X != right.X || left.Y != right.Y || left.Width != right.Width || left.Height != right.Height);
}
Parameters
left
Rectangle
The Aspose.Imaging.Rectangle structure that is to the left of the inequality operator.
right
Rectangle
The Aspose.Imaging.Rectangle structure that is to the right of the inequality operator.
Returns
This operator returns true if any of the Aspose.Imaging.Rectangle.X, Aspose.Imaging.Rectangle.Y, Aspose.Imaging.Rectangle.Width or Aspose.Imaging.Rectangle.Height properties of the two Aspose.Imaging.Rectangle structures are unequal; otherwise false.