Table of Contents

Struct RoundRect

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

A rectangle with an x and y radius per corner. Radii that would overlap are scaled down together, as CSS and Skia do: every radius is multiplied by the smallest ratio of a side's length to the sum of the two radii along it, when that ratio is below 1. A radius below 0 counts as 0, and a corner with either radius 0 is square.

public readonly record struct RoundRect : IEquatable<RoundRect>
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

RoundRect(RectF, CornerRadii)

Initializes a new instance of the RoundRect struct.

public RoundRect(RectF bounds, CornerRadii radii)

Parameters

bounds RectF

The rectangle.

radii CornerRadii

The corner radii, scaled down when they overlap.

Exceptions

ArgumentException

A coordinate or radius is not a finite number.

RoundRect(RectF, float)

Initializes a new instance of the RoundRect struct with one circular radius for every corner.

public RoundRect(RectF bounds, float radius)

Parameters

bounds RectF

The rectangle.

radius float

The radius of every corner.

RoundRect(RectF, float, float)

Initializes a new instance of the RoundRect struct with one elliptical radius for every corner.

public RoundRect(RectF bounds, float radiusX, float radiusY)

Parameters

bounds RectF

The rectangle.

radiusX float

The x radius of every corner.

radiusY float

The y radius of every corner.

Properties

Bounds

Gets the rectangle.

public RectF Bounds { get; }

Property Value

RectF

IsEmpty

Gets a value indicating whether the shape covers no area.

public bool IsEmpty { get; }

Property Value

bool

Kind

Gets what the shape reduces to.

public RoundRectKind Kind { get; }

Property Value

RoundRectKind

Radii

Gets the corner radii, after scaling.

public CornerRadii Radii { get; }

Property Value

CornerRadii

Methods

Contains(Vector2)

Returns whether a point lies inside the shape: inside the rectangle and not outside a corner's ellipse.

public bool Contains(Vector2 point)

Parameters

point Vector2

The point.

Returns

bool

true if the point is inside.

Inflate(float)

Returns the shape grown by delta on every side, with each radius grown by the same amount (shrunk when negative), as Skia's outset does.

public RoundRect Inflate(float delta)

Parameters

delta float

The growth per side.

Returns

RoundRect

The grown shape.

Offset(Vector2)

Returns the shape moved by an offset.

public RoundRect Offset(Vector2 offset)

Parameters

offset Vector2

The distance to move.

Returns

RoundRect

The moved shape.

Oval(RectF)

Creates the ellipse that fills a rectangle.

public static RoundRect Oval(RectF bounds)

Parameters

bounds RectF

The rectangle.

Returns

RoundRect

The oval as a round rectangle.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.