Skip to content

Geometry

Dustin Horne edited this page Mar 5, 2026 · 1 revision

Geometry

Namespace: ParentElement.RichText.Core.Geometry

Platform-agnostic geometry value types used throughout the editor API. All three types provide SkiaSharp conversion helpers and are interchangeable with their SkiaSharp counterparts at rendering boundaries.


Point

A 2D coordinate in pixel space.

public struct Point

Constructor

public Point(float x, float y)

Properties

Property Type Description
X float Horizontal coordinate in pixels
Y float Vertical coordinate in pixels

Methods

Method Returns Description
ToSkia() SKPoint Convert to a SkiaSharp SKPoint
FromView(ViewModifier) Point Transform from view (screen) space into document space

Coordinate Transform

FromView applies the inverse of the viewport's scale and offset to map a screen-space pointer coordinate to a document-space coordinate:

documentX = screenX / view.Scale.X + view.ScaledOffset.X
documentY = screenY / view.Scale.X + view.ScaledOffset.Y
var screen   = new Point(pointerX, pointerY);
var document = screen.FromView(viewModifier);
editor.Click(document);

Rectangle

An immutable axis-aligned rectangle defined by its origin and size.

public struct Rectangle

Constructors

Signature Description
Rectangle(float x, float y, float width, float height) Explicit position and size
Rectangle(float width, float height) Positioned at the origin (0, 0)
Rectangle(Rectangle other) Copy constructor

Properties

Property Type Description
X float X-coordinate of the left edge
Y float Y-coordinate of the top edge
Width float Width in pixels
Height float Height in pixels
Top float Alias for Y
Bottom float Y + Height
Left float Alias for X
Right float X + Width
TopLeft Point Top-left corner
TopRight Point Top-right corner
BottomLeft Point Bottom-left corner
BottomRight Point Bottom-right corner
Center Point Center point

Methods

Method Returns Description
Inflate(float) Rectangle Expand width and height uniformly; position unchanged
Inflate(float, float) Rectangle Expand width and height independently; position unchanged
Deflate(float) Rectangle Shrink width and height uniformly; position unchanged
Deflate(float, float) Rectangle Shrink width and height independently; position unchanged
ToSkia() SKRect Convert to a SkiaSharp SKRect

Note: Inflate and Deflate do not move the origin — they grow or shrink the rectangle by adjusting Width and Height only.

Example

var viewport = new Rectangle(0, 0, 800, 600);

// Set visible bounds with a 4px inset
editor.VisibleBounds = viewport.Deflate(4);

// Check if a point is within bounds
bool inside = point.X >= viewport.Left && point.X <= viewport.Right
           && point.Y >= viewport.Top  && point.Y <= viewport.Bottom;

// Convert for Skia clipping
canvas.ClipRect(viewport.ToSkia());

Size

A width/height pair in pixels.

public struct Size

Constructor

public Size(float width, float height)

Properties

Property Type Description
Width float Width component in pixels
Height float Height component in pixels

Example

var pageSize = new Size(816, 1056);  // US Letter at 96 dpi

See also: Data-Structures · IDocumentController

Clone this wiki locally