Table of Contents

Struct RectF

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

A rectangle in float pixels, y down: the left edge at X, the top at Y. A width or height of 0 or less makes it empty. Pixel (0, 0) covers the square from (0, 0) to (1, 1), so a rectangle with whole-number edges covers whole pixels.

public readonly record struct RectF : IEquatable<RectF>
Implements
Inherited Members

Examples

canvas.FillRect(new RectF(10, 10, 80, 40), Rgba8.Red);
canvas.FillRoundRect(new RoundRect(new RectF(100, 10, 80, 40), 12), new Rgba8(0, 128, 0, 255));

// Each corner can have its own radii; radii that would overlap are scaled down together, as CSS does.
CornerRadii tab = new(topLeft: 16, topRight: 16, bottomRight: 0, bottomLeft: 0);
canvas.FillRoundRect(new RoundRect(new RectF(190, 10, 100, 40), tab), Rgba8.Black);

canvas.FillOval(new RectF(10, 60, 120, 60), new Rgba8(255, 200, 0, 255));
canvas.FillCircle(new Vector2(170, 90), 30, new Rgba8(80, 80, 200, 255));
canvas.FillArc(new RectF(210, 60, 60, 60), startDegrees: -90, sweepDegrees: 120, Rgba8.Red);
canvas.FillRing(new RoundRect(new RectF(10, 130, 60, 60), 30), new RoundRect(new RectF(25, 145, 30, 30), 15), Rgba8.Black);

// The same shapes as paths, to build on or to reuse.
Path hexagon = Path.RegularPolygon(new Vector2(120, 160), 30, sides: 6);
Path star = Path.Star(new Vector2(200, 160), outerRadius: 30, innerRadius: 12, points: 5);
canvas.FillPath(hexagon, new Rgba8(0, 150, 150, 255));
canvas.FillPath(star, new Rgba8(220, 160, 0, 255));

Constructors

RectF(float, float, float, float)

A rectangle in float pixels, y down: the left edge at X, the top at Y. A width or height of 0 or less makes it empty. Pixel (0, 0) covers the square from (0, 0) to (1, 1), so a rectangle with whole-number edges covers whole pixels.

public RectF(float X, float Y, float Width, float Height)

Parameters

X float

The left edge.

Y float

The top edge.

Width float

The width; empty when 0 or less.

Height float

The height; empty when 0 or less.

Examples

canvas.FillRect(new RectF(10, 10, 80, 40), Rgba8.Red);
canvas.FillRoundRect(new RoundRect(new RectF(100, 10, 80, 40), 12), new Rgba8(0, 128, 0, 255));

// Each corner can have its own radii; radii that would overlap are scaled down together, as CSS does.
CornerRadii tab = new(topLeft: 16, topRight: 16, bottomRight: 0, bottomLeft: 0);
canvas.FillRoundRect(new RoundRect(new RectF(190, 10, 100, 40), tab), Rgba8.Black);

canvas.FillOval(new RectF(10, 60, 120, 60), new Rgba8(255, 200, 0, 255));
canvas.FillCircle(new Vector2(170, 90), 30, new Rgba8(80, 80, 200, 255));
canvas.FillArc(new RectF(210, 60, 60, 60), startDegrees: -90, sweepDegrees: 120, Rgba8.Red);
canvas.FillRing(new RoundRect(new RectF(10, 130, 60, 60), 30), new RoundRect(new RectF(25, 145, 30, 30), 15), Rgba8.Black);

// The same shapes as paths, to build on or to reuse.
Path hexagon = Path.RegularPolygon(new Vector2(120, 160), 30, sides: 6);
Path star = Path.Star(new Vector2(200, 160), outerRadius: 30, innerRadius: 12, points: 5);
canvas.FillPath(hexagon, new Rgba8(0, 150, 150, 255));
canvas.FillPath(star, new Rgba8(220, 160, 0, 255));

Properties

Bottom

Gets the bottom edge, Y + Height.

public float Bottom { get; }

Property Value

float

Center

Gets the center.

public Vector2 Center { get; }

Property Value

Vector2

Empty

Gets the empty rectangle at the origin.

public static RectF Empty { get; }

Property Value

RectF

Height

The height; empty when 0 or less.

public float Height { get; init; }

Property Value

float

IsEmpty

Gets a value indicating whether the rectangle covers no area: its width or height is 0 or less, or not a number.

public bool IsEmpty { get; }

Property Value

bool

IsFinite

Gets a value indicating whether every coordinate is a finite number.

public bool IsFinite { get; }

Property Value

bool

Left

Gets the left edge, X.

public float Left { get; }

Property Value

float

Position

Gets the top-left corner.

public Vector2 Position { get; }

Property Value

Vector2

Right

Gets the right edge, X + Width.

public float Right { get; }

Property Value

float

Size

Gets the width and height.

public Vector2 Size { get; }

Property Value

Vector2

Top

Gets the top edge, Y.

public float Top { get; }

Property Value

float

Width

The width; empty when 0 or less.

public float Width { get; init; }

Property Value

float

X

The left edge.

public float X { get; init; }

Property Value

float

Y

The top edge.

public float Y { get; init; }

Property Value

float

Methods

Contains(RectF)

Returns whether another rectangle lies wholly inside this one. An empty rectangle is inside none.

public bool Contains(RectF other)

Parameters

other RectF

The other rectangle.

Returns

bool

true if other is inside.

Contains(Vector2)

Returns whether a point lies inside: left and top edges included, right and bottom excluded.

public bool Contains(Vector2 point)

Parameters

point Vector2

The point.

Returns

bool

true if the point is inside.

FromEdges(float, float, float, float)

Creates a rectangle from its four edges.

public static RectF FromEdges(float left, float top, float right, float bottom)

Parameters

left float

The left edge.

top float

The top edge.

right float

The right edge.

bottom float

The bottom edge.

Returns

RectF

The rectangle; empty when right is not past left or bottom not below top.

FromPoints(ReadOnlySpan<Vector2>)

Creates the smallest rectangle holding every point.

public static RectF FromPoints(ReadOnlySpan<Vector2> points)

Parameters

points ReadOnlySpan<Vector2>

The points.

Returns

RectF

The bounds, or Empty when there are no points.

FromPosition(Vector2, Vector2)

Creates a rectangle from a corner and a size.

public static RectF FromPosition(Vector2 position, Vector2 size)

Parameters

position Vector2

The top-left corner.

size Vector2

The width and height.

Returns

RectF

The rectangle.

Inflate(float, float)

Returns the rectangle grown by dx on the left and right and dy on the top and bottom; negative values shrink it.

public RectF Inflate(float dx, float dy)

Parameters

dx float

The horizontal growth per side.

dy float

The vertical growth per side.

Returns

RectF

The grown rectangle.

Intersect(RectF)

Returns the area both rectangles cover.

public RectF Intersect(RectF other)

Parameters

other RectF

The other rectangle.

Returns

RectF

The overlap, or Empty when there is none.

IntersectsWith(RectF)

Returns whether the two rectangles share any area.

public bool IntersectsWith(RectF other)

Parameters

other RectF

The other rectangle.

Returns

bool

true if they overlap.

Offset(Vector2)

Returns the rectangle moved by an offset.

public RectF Offset(Vector2 offset)

Parameters

offset Vector2

The distance to move.

Returns

RectF

The moved rectangle.

RoundOut()

Returns the smallest integer rectangle holding this one: edges rounded outwards.

public Rect RoundOut()

Returns

Rect

The covering pixel rectangle; empty when this one is empty.

Union(RectF)

Returns the smallest rectangle holding both. An empty rectangle adds nothing.

public RectF Union(RectF other)

Parameters

other RectF

The other rectangle.

Returns

RectF

The union.

Operators

implicit operator RectF(Rect)

Converts an integer rectangle.

public static implicit operator RectF(Rect rect)

Parameters

rect Rect

The rectangle in whole pixels.

Returns

RectF