geometry

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

CornerRadiusUnspecified represents an unspecified corner radius.

View Source
var CornerRadiusZero = NewCornerRadius(0, 0)

CornerRadiusZero is a CornerRadius with both x and y radii equal to zero (sharp corners).

OffsetInfinite is an offset with infinite x and y components.

Sentinel Values OffsetUnspecified Represents an unspecified Offset value, usually a replacement for `null` when a primitive value is desired.

View Source
var OffsetZero = NewOffset(0, 0)

OffsetZero is an offset with zero magnitude.

View Source
var RectZero = Rect{Left: 0, Top: 0, Right: 0, Bottom: 0}

RectZero is a rectangle with left, top, right, and bottom edges all at zero.

SizeUnspecified Represents an unspecified Size value, usually a replacement for `null` when a primitive value is desired.

View Source
var SizeZero = NewSize(0, 0)

SizeZero is an empty size, one with a zero width and a zero height.

Functions

This section is empty.

Types

type CornerRadius

type CornerRadius int64

CornerRadius represents the radii for corners of a rounded rectangle. It is a packed value where the x radius is in the high 32 bits and the y radius is in the low 32 bits. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/CornerRadius.kt

func LerpCornerRadius

func LerpCornerRadius(start, stop CornerRadius, fraction float32) CornerRadius

LerpCornerRadius linearly interpolates between two corner radii.

func NewCircularCornerRadius

func NewCircularCornerRadius(radius float32) CornerRadius

NewCircularCornerRadius creates a CornerRadius with equal x and y radii (circular corners).

func NewCornerRadius

func NewCornerRadius(x, y float32) CornerRadius

NewCornerRadius creates a CornerRadius from the given x and y radii. x is the radius of the corners along the x-axis. y is the radius of the corners along the y-axis (defaults to x if you want circular corners).

func (CornerRadius) Div

func (c CornerRadius) Div(operand float32) CornerRadius

Div returns a CornerRadius with radii divided by the given factor.

func (CornerRadius) Equal

func (c CornerRadius) Equal(other CornerRadius) bool

Equal checks equality with another CornerRadius.

func (CornerRadius) IsSpecified

func (c CornerRadius) IsSpecified() bool

IsSpecified returns true if this is not CornerRadius.Unspecified.

func (CornerRadius) IsUnspecified

func (c CornerRadius) IsUnspecified() bool

IsUnspecified returns true if this is CornerRadius.Unspecified.

func (CornerRadius) Minus

func (c CornerRadius) Minus(other CornerRadius) CornerRadius

Minus returns a CornerRadius with radii that are the difference of both corner radii.

func (CornerRadius) Plus

func (c CornerRadius) Plus(other CornerRadius) CornerRadius

Plus returns a CornerRadius with radii that are the sum of both corner radii.

func (CornerRadius) String

func (c CornerRadius) String() string

String returns a string representation of the CornerRadius.

func (CornerRadius) TakeOrElse

func (c CornerRadius) TakeOrElse(fallback CornerRadius) CornerRadius

TakeOrElse returns this corner radius if Specified, otherwise returns the fallback.

func (CornerRadius) Times

func (c CornerRadius) Times(operand float32) CornerRadius

Times returns a CornerRadius with radii scaled by the given factor.

func (CornerRadius) X

func (c CornerRadius) X() float32

X returns the x component of the corner radius.

func (CornerRadius) Y

func (c CornerRadius) Y() float32

Y returns the y component of the corner radius.

type Offset

type Offset int64

Offset is an immutable 2D floating-point offset. It is a packed value where the x coordinate is in the high 32 bits and the y coordinate is in the low 32 bits.

func LerpOffset

func LerpOffset(start, stop Offset, fraction float32) Offset

LerpOffset linearly interpolates between two offsets.

func NewOffset

func NewOffset(x, y float32) Offset

NewOffset constructs an Offset from the given x and y values.

func (Offset) Div

func (o Offset) Div(operand float32) Offset

Div returns an offset whose coordinates are the coordinates of the left-hand-side operand (an Offset) divided by the scalar right-hand-side operand (a Float).

func (Offset) Equal

func (o Offset) Equal(other Offset) bool

Equal checks equality with another Offset.

func (Offset) GetDistance

func (o Offset) GetDistance() float32

GetDistance returns the magnitude of the offset.

func (Offset) GetDistanceSquared

func (o Offset) GetDistanceSquared() float32

GetDistanceSquared returns the square of the magnitude of the offset.

func (Offset) IsFinite

func (o Offset) IsFinite() bool

IsFinite returns true if both x and y values of the Offset are finite. NaN values are not considered finite.

func (Offset) IsInfinite

func (o Offset) IsInfinite() bool

IsInfinite returns true if either x or y value of the Offset is infinite.

func (Offset) IsOffset

func (o Offset) IsOffset() bool

IsOffset returns true if this is not Offset.Unspecified.

func (Offset) IsUnspecified

func (o Offset) IsUnspecified() bool

IsUnspecified returns true if this is Offset.Unspecified.

func (Offset) IsValid

func (o Offset) IsValid() bool

IsValid returns true if x and y are not NaN.

func (Offset) Minus

func (o Offset) Minus(other Offset) Offset

Minus returns an offset whose x value is the left-hand-side operand's x minus the right-hand-side operand's x and whose y value is the left-hand-side operand's y minus the right-hand-side operand's y.

func (Offset) Plus

func (o Offset) Plus(other Offset) Offset

Plus returns an offset whose x value is the sum of the x values of the two operands, and whose y value is the sum of the y values of the two operands.

func (Offset) Rem

func (o Offset) Rem(operand float32) Offset

Rem returns an offset whose coordinates are the remainder of dividing the coordinates of the left-hand-side operand (an Offset) by the scalar right-hand-side operand (a Float).

func (Offset) String

func (o Offset) String() string

String returns a string representation of the object.

func (Offset) TakeOrElse

func (o Offset) TakeOrElse(block Offset) Offset

TakeOrElse returns this offset if Specified, otherwise executes the block and returns its result.

func (Offset) Times

func (o Offset) Times(operand float32) Offset

Times returns an offset whose coordinates are the coordinates of the left-hand-side operand (an Offset) multiplied by the scalar right-hand-side operand (a Float).

func (Offset) UnaryMinus

func (o Offset) UnaryMinus() Offset

UnaryMinus returns an offset with the coordinates negated.

func (Offset) X

func (o Offset) X() float32

X returns the x component of the offset.

func (Offset) Y

func (o Offset) Y() float32

Y returns the y component of the offset.

type Rect

type Rect struct {
	Left   float32
	Top    float32
	Right  float32
	Bottom float32
}

Rect is an immutable, 2D, axis-aligned, floating-point rectangle whose coordinates are relative to a given origin.

func LerpRect

func LerpRect(start, stop Rect, fraction float32) Rect

LerpRect linearly interpolates between two rectangles.

func NewRect

func NewRect(left, top, right, bottom float32) Rect

NewRect constructs a Rect from the given left, top, right, and bottom values.

func RectFromCircle

func RectFromCircle(center Offset, radius float32) Rect

RectFromCircle constructs a rectangle that bounds the given circle.

func RectFromOffsetSize

func RectFromOffsetSize(offset Offset, size Size) Rect

RectFromOffsetSize constructs a rectangle from its left and top edges as well as its width and height.

func RectFromTwoOffsets

func RectFromTwoOffsets(topLeft, bottomRight Offset) Rect

RectFromTwoOffsets constructs the smallest rectangle that encloses the given offsets, treating them as vectors from the origin.

func (Rect) BottomCenter

func (r Rect) BottomCenter() Offset

BottomCenter returns the offset to the center of the bottom edge of this rectangle.

func (Rect) BottomLeft

func (r Rect) BottomLeft() Offset

BottomLeft returns the offset to the intersection of the bottom and left edges of this rectangle.

func (Rect) BottomRight

func (r Rect) BottomRight() Offset

BottomRight returns the offset to the intersection of the bottom and right edges of this rectangle.

func (Rect) Center

func (r Rect) Center() Offset

Center returns the offset to the point halfway between the left and right and the top and bottom edges.

func (Rect) CenterLeft

func (r Rect) CenterLeft() Offset

CenterLeft returns the offset to the center of the left edge of this rectangle.

func (Rect) CenterRight

func (r Rect) CenterRight() Offset

CenterRight returns the offset to the center of the right edge of this rectangle.

func (Rect) Contains

func (r Rect) Contains(offset Offset) bool

Contains returns whether the point specified by the given offset lies between the left and right and the top and bottom edges. Rectangles include their top and left edges but exclude their bottom and right edges.

func (Rect) Deflate

func (r Rect) Deflate(delta float32) Rect

Deflate returns a new rectangle with edges moved inwards by the given delta.

func (Rect) Equal

func (r Rect) Equal(other Rect) bool

Equal checks equality with another Rect.

func (Rect) Height

func (r Rect) Height() float32

Height returns the distance between the top and bottom edges of this rectangle.

func (Rect) Inflate

func (r Rect) Inflate(delta float32) Rect

Inflate returns a new rectangle with edges moved outwards by the given delta.

func (Rect) Intersect

func (r Rect) Intersect(other Rect) Rect

Intersect returns a new rectangle that is the intersection of the given rectangle and this rectangle.

func (Rect) IntersectCoords

func (r Rect) IntersectCoords(otherLeft, otherTop, otherRight, otherBottom float32) Rect

IntersectCoords returns a new rectangle that is the intersection of the given rectangle coordinates and this rectangle.

func (Rect) IsEmpty

func (r Rect) IsEmpty() bool

IsEmpty returns true if this rectangle encloses a non-zero area. Negative areas are considered empty.

func (Rect) IsFinite

func (r Rect) IsFinite() bool

IsFinite returns true if all coordinates of this rectangle are finite.

func (Rect) IsInfinite

func (r Rect) IsInfinite() bool

IsInfinite returns true if any of the coordinates of this rectangle are equal to positive infinity.

func (Rect) MaxDimension

func (r Rect) MaxDimension() float32

MaxDimension returns the greater of the magnitudes of the width and the height of this rectangle.

func (Rect) MinDimension

func (r Rect) MinDimension() float32

MinDimension returns the lesser of the magnitudes of the width and the height of this rectangle.

func (Rect) Overlaps

func (r Rect) Overlaps(other Rect) bool

Overlaps returns whether `other` has a nonzero area of overlap with this rectangle.

func (Rect) Size

func (r Rect) Size() Size

Size returns the distance between the upper-left corner and the lower-right corner of this rectangle.

func (Rect) String

func (r Rect) String() string

String returns a string representation of the object.

func (Rect) TopCenter

func (r Rect) TopCenter() Offset

TopCenter returns the offset to the center of the top edge of this rectangle.

func (Rect) TopLeft

func (r Rect) TopLeft() Offset

TopLeft returns the offset to the intersection of the top and left edges of this rectangle.

func (Rect) TopRight

func (r Rect) TopRight() Offset

TopRight returns the offset to the intersection of the top and right edges of this rectangle.

func (Rect) Translate

func (r Rect) Translate(offset Offset) Rect

Translate returns a new rectangle translated by the given offset.

func (Rect) TranslateXY

func (r Rect) TranslateXY(translateX, translateY float32) Rect

TranslateXY returns a new rectangle with translateX added to the x components and translateY added to the y components.

func (Rect) Width

func (r Rect) Width() float32

Width returns the distance between the left and right edges of this rectangle.

type Size

type Size int64

Size represents a 2D floating-point size. You can think of this as an Offset from the origin. It is a packed value where the width is in the high 32 bits and the height is in the low 32 bits.

func LerpSize

func LerpSize(start, stop Size, fraction float32) Size

LerpSize linearly interpolates between two sizes.

func NewSize

func NewSize(width, height float32) Size

NewSize constructs a Size from the given width and height.

func (Size) Center

func (s Size) Center() Offset

Center returns the Offset of the center of the rect from the point of [0, 0] with this Size.

func (Size) Div

func (s Size) Div(operand float32) Size

Div returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) divided by the scalar right-hand-side operand (a Float).

func (Size) Equal

func (s Size) Equal(other Size) bool

Equal checks equality with another Size.

func (Size) Height

func (s Size) Height() float32

Height returns the height component of the size.

func (Size) IsEmpty

func (s Size) IsEmpty() bool

IsEmpty returns true if the Size is empty (width <= 0 or height <= 0).

func (Size) IsSpecified

func (s Size) IsSpecified() bool

IsSpecified returns false when this is Size.Unspecified.

func (Size) IsUnspecified

func (s Size) IsUnspecified() bool

IsUnspecified returns true when this is Size.Unspecified.

func (Size) MaxDimension

func (s Size) MaxDimension() float32

MaxDimension returns the greater of the magnitudes of the width and the height.

func (Size) MinDimension

func (s Size) MinDimension() float32

MinDimension returns the lesser of the magnitudes of the width and the height.

func (Size) String

func (s Size) String() string

String returns a string representation of the object.

func (Size) TakeOrElse

func (s Size) TakeOrElse(block Size) Size

func (Size) Times

func (s Size) Times(operand float32) Size

Times returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) multiplied by the scalar right-hand-side operand (a Float).

func (Size) Width

func (s Size) Width() float32

Width returns the width component of the size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL