logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Struct ViewportRect

    Immutable, normalized viewport rectangle (all components in the 0..1 range), matching the engine convention where a camera's rect is expressed as a fraction of the screen (e.g. Unity's Camera.rect). The constructor clamps every component into 0..1 so that a rect built from untrusted or computed values can never describe an out-of-bounds viewport.

    Inherited Members
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Serenity.GameCamera.Domain.ValueObjects
    Assembly: Serenity.GameCamera.Domain.dll
    Syntax
    public readonly struct ViewportRect

    Constructors

    ViewportRect(float, float, float, float)

    Initializes a new instance of the ViewportRect struct, clamping every component into the 0..1 range.

    Declaration
    public ViewportRect(float x, float y, float width, float height)
    Parameters
    Type Name Description
    float x

    Normalized left edge; clamped to 0..1.

    float y

    Normalized bottom edge; clamped to 0..1.

    float width

    Normalized width; clamped to 0..1.

    float height

    Normalized height; clamped to 0..1.

    Fields

    Height

    Declaration
    public readonly float Height
    Field Value
    Type Description
    float

    Normalized height of the viewport (0..1).

    Width

    Declaration
    public readonly float Width
    Field Value
    Type Description
    float

    Normalized width of the viewport (0..1).

    X

    Declaration
    public readonly float X
    Field Value
    Type Description
    float

    Normalized left edge of the viewport (0..1).

    Y

    Declaration
    public readonly float Y
    Field Value
    Type Description
    float

    Normalized bottom edge of the viewport (0..1).

    Properties

    Full

    Declaration
    public static ViewportRect Full { get; }
    Property Value
    Type Description
    ViewportRect

    The full-screen viewport: X=0, Y=0, Width=1, Height=1.

    Methods

    Equals(ViewportRect)

    Determines whether this rect has the same normalized components as another.

    Declaration
    public bool Equals(ViewportRect other)
    Parameters
    Type Name Description
    ViewportRect other

    The rect to compare against.

    Returns
    Type Description
    bool

    True when all four components are equal.

    Equals(object)

    Determines whether this rect equals another object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The object to compare against.

    Returns
    Type Description
    bool

    True when obj is a ViewportRect with equal components.

    Overrides
    ValueType.Equals(object)

    GetHashCode()

    Computes a hash code consistent with Equals(ViewportRect).

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    The hash code.

    Overrides
    ValueType.GetHashCode()

    ToString()

    Returns a string representation of the rect.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    Formatted string with the four normalized components.

    Overrides
    ValueType.ToString()

    Operators

    operator ==(ViewportRect, ViewportRect)

    Determines whether two rects have equal normalized components.

    Declaration
    public static bool operator ==(ViewportRect left, ViewportRect right)
    Parameters
    Type Name Description
    ViewportRect left

    The first rect.

    ViewportRect right

    The second rect.

    Returns
    Type Description
    bool

    True when all four components are equal.

    operator !=(ViewportRect, ViewportRect)

    Determines whether two rects differ in any normalized component.

    Declaration
    public static bool operator !=(ViewportRect left, ViewportRect right)
    Parameters
    Type Name Description
    ViewportRect left

    The first rect.

    ViewportRect right

    The second rect.

    Returns
    Type Description
    bool

    True when any component differs.

    In this article
    © 2026 Serenity. All Rights Reserved