Table of Contents

Class Region

Namespace
SixLabors.ImageSharp.Drawing
Assembly
SixLabors.ImageSharp.Drawing.dll

Represents an integer region composed from axis-aligned rectangles.

public sealed class Region
Inheritance
Region
Inherited Members

Remarks

The region stores exact integer coverage using a normalized rect-set model: horizontal Y bands contain sorted X intervals. Region operations preserve the covered area as a union of rectangles; ToPath() exports that area as boundary geometry.

Constructors

Region()

Initializes a new instance of the Region class.

public Region()

Region(Region)

Initializes a new instance of the Region class containing the same area as the specified region.

public Region(Region region)

Parameters

region Region

The region to copy.

Region(Rectangle)

Initializes a new instance of the Region class containing the specified rectangle.

public Region(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle to add to the region.

Properties

Bounds

Gets the bounding rectangle of the region.

public Rectangle Bounds { get; }

Property Value

Rectangle

Remarks

Returns Empty when the region is empty.

IsEmpty

Gets a value indicating whether the region contains no area.

public bool IsEmpty { get; }

Property Value

bool

Rectangles

Gets the non-overlapping rectangles that describe the region.

public IReadOnlyList<Rectangle> Rectangles { get; }

Property Value

IReadOnlyList<Rectangle>

Remarks

The rectangles are an exported view of the region area. They preserve the region shape as a rect-set and are not collapsed to Bounds.

Methods

Add(Rectangle)

Adds a rectangle to the region.

public void Add(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle to add.

Remarks

Rectangles with non-positive width or height do not change the region. The rectangle is unioned with the existing rect-set.

Clear()

Removes all rectangles from the region.

public void Clear()

Contains(Point)

Returns a value indicating whether the region contains the specified point.

public bool Contains(Point point)

Parameters

point Point

The point to test.

Returns

bool

true if the region contains the point; otherwise, false.

Contains(int, int)

Returns a value indicating whether the region contains the specified point.

public bool Contains(int x, int y)

Parameters

x int

The x-coordinate to test.

y int

The y-coordinate to test.

Returns

bool

true if the region contains the point; otherwise, false.

Intersect(Region)

Intersects this region with the specified region.

public bool Intersect(Region region)

Parameters

region Region

The region to intersect with this region.

Returns

bool

true when the resulting region is not empty; otherwise, false.

Remarks

The operation intersects every overlapping X interval pair in every overlapping Y band and unions the results. This is the rect-set form of region intersection.

Intersect(Rectangle)

Intersects this region with the specified rectangle.

public bool Intersect(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle to intersect with this region.

Returns

bool

true when the resulting region is not empty; otherwise, false.

Remarks

This operation clips the existing rect-set to the rectangle. It does not replace the result with one bounding rectangle.

Intersects(Rectangle)

Returns a value indicating whether the region intersects the specified rectangle.

public bool Intersects(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle to test.

Returns

bool

true if the region intersects the rectangle; otherwise, false.

ToPath()

Creates a path representing the region.

public IPath ToPath()

Returns

IPath

The path representing the region.

Remarks

The returned path describes the exact boundary of the region. Complex regions may produce multiple closed figures. Returns ClosedPath when the region is empty.