Table of Contents

Class RectangleOfPixels

Namespace
VirtualLabAPI.Core.Numerics
Assembly
VirtualLabAPI.dll

Special rectangle of integer values using to store a rectangular or range selection. In contrast to the System.Drawing.Rectangle class its point of origin is in the lower left corner and the y-axis points upwards. Furthermore its Width is (Right - Left + 1) and its Height is (Bottom - Top + 1). That's because if the rectangle contains two pixels in x-direction its Left property may be "0" while its "Right" property is "1". But then the width should be "2", as two pixels are in the rectangle.

[Serializable]
public class RectangleOfPixels : SerializableObjectBase, IEquatable<IObjectBase>, ICloneable
Inheritance
ObjectBase
SerializableObjectBase
RectangleOfPixels
Implements
IEquatable<IObjectBase>
Inherited Members

Constructors

RectangleOfPixels(long, long)

Special constructor for a one-dimensional rectangle of pixels. Top and Bottom property are set to "0".

public RectangleOfPixels(long left, long right)

Parameters

left long

The start index of the selection, i.e. the left-most selected pixel.

right long

The end index of the selection, i.e. the right-most selected pixel.

RectangleOfPixels(long, long, long, long)

Constructor for a two-dimensional rectangle of pixels.

public RectangleOfPixels(long left, long bottom, long numberOfPixelsX, long numberOfPixelsY)

Parameters

left long

The smallest x-coordinate, i.e. the left-most pixel.

bottom long

The smallest y-coordinate, i.e. the bottom-most pixel.

numberOfPixelsX long

The width of the rectangle in pixels.

numberOfPixelsY long

The height of the rectangle in pixels.

RectangleOfPixels(RectangleOfPixels)

Copy constructor which initializes a new instance of the RectangleOfPixels class.

public RectangleOfPixels(RectangleOfPixels copyObject)

Parameters

copyObject RectangleOfPixels

The object to copy.

RectangleOfPixels(VectorL, VectorL)

Constructor for a two-dimensional rectangle of pixels.

public RectangleOfPixels(VectorL lowerLeftIndices, VectorL upperRightIndices)

Parameters

lowerLeftIndices VectorL

The indices of the lower left pixel.

upperRightIndices VectorL

The indices of the upper right pixel.

Fields

Empty

An empty rectangle.

public static readonly RectangleOfPixels Empty

Field Value

RectangleOfPixels

Properties

Bottom

Gets and sets the index of the bottom-most selected row of pixels. Must be smaller than Top.

public long Bottom { get; set; }

Property Value

long

Left

Gets and sets the index of the left-most selected column of pixels. Must be smaller than Right.

public long Left { get; set; }

Property Value

long

NumberOfPixels

Gets the number of pixels in both x- and y-direction.

public VectorL NumberOfPixels { get; }

Property Value

VectorL

NumberOfPixelsOneD

Gets the number of pixels for one-dimensional rectangles.

public long NumberOfPixelsOneD { get; }

Property Value

long

NumberOfPixelsTotal

Gets the total number of pixels, i.e. the number of pixels in x-direction times the number of pixels in y-direction.

public long NumberOfPixelsTotal { get; }

Property Value

long

Origin

Gets the point of origin, i.e. the left-bottom pixel.

public VectorL Origin { get; }

Property Value

VectorL

Right

Gets and sets the index of the right-most selected column of pixels. Must be larger than Left.

public long Right { get; set; }

Property Value

long

Top

Gets and sets the index of the top-most selected row of pixels. Must be larger than Bottom.

public long Top { get; set; }

Property Value

long

Methods

Clone()

Creates a new object that is a copy of the current instance.

public override object Clone()

Returns

object

A new object that is a copy of this instance.

Equals(object, EqualityIntent)

Determines whether the specified object is equal to this instance.

public override bool Equals(object otherObject, EqualityIntent equality)

Parameters

otherObject object

The object to compare with this instance.

equality EqualityIntent

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

FromCoordinates(long, long, long, long)

Constructor for a two-dimensional rectangle of pixels.

public static RectangleOfPixels FromCoordinates(long left, long right, long bottom, long top)

Parameters

left long

The smallest x-coordinate, i.e. the left-most pixel.

right long

The largest x-coordinate, i.e. the right-most pixel.

bottom long

The smallest y-coordinate, i.e. the bottom-most pixel.

top long

The largest y-coordinate, i.e. the top-most pixel.

Returns

RectangleOfPixels

Inflate(RectangleOfPixels, long, long)

Enlarges the given RectangleOfPixels by the specified amount.

public static RectangleOfPixels Inflate(RectangleOfPixels rectangle, long incrementX, long incrementY)

Parameters

rectangle RectangleOfPixels

The original rectangle.

incrementX long

The increment in x-direction (subtracted from the left and added to the right).

incrementY long

The increment in y-direction (subtracted from the bottom and added to the top).

Returns

RectangleOfPixels

The inflated rectangle.

Intersect(RectangleOfPixels, RectangleOfPixels)

Returns a third RectangleOfPixels that represents the intersection of two other RectangleOfPixels objects. If there is no intersection, an empty RectangleOfPixels is returned.

public static RectangleOfPixels Intersect(RectangleOfPixels a, RectangleOfPixels b)

Parameters

a RectangleOfPixels

First rectangle to intersect.

b RectangleOfPixels

Second rectangle to intersect.

Returns

RectangleOfPixels

A RectangleOfPixels that represents the intersection of a and b.

IntersectsWith(RectangleOfPixels)

Determines if this rectangle intersects with otherRectangle.

public bool IntersectsWith(RectangleOfPixels otherRectangle)

Parameters

otherRectangle RectangleOfPixels

The other rectangle.

Returns

bool

This method returns true if there is any intersection, otherwise false.

Operators

explicit operator Rectangle?(RectangleOfPixels)

Converts this rectangle of a pixels to a System.Drawing.Rectangle object.

public static explicit operator Rectangle?(RectangleOfPixels rectangleOfPixels)

Parameters

rectangleOfPixels RectangleOfPixels

The rectangle of pixels to convert.

Returns

Rectangle?

The converted rectangle. It has the same size and location (= origin) as this RectangleOfPixels. But the right and top/bottom coordinate differs.