geo

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package geo defines the fundamental geometry types used throughout Bellui: Size, Position, and Delta.

These types have no dependencies on the rest of the Bellui framework, making them safe to import from any package without circular dependency concerns.

import "github.com/belluikit/bellui/geo"

size := geo.NewSize(200, 100)
pos := geo.NewPos(10, 20)
delta := geo.NewDelta(5, 5)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Max

func Max(x, y float32) float32

Max returns the larger of the passed values.

func Min

func Min(x, y float32) float32

Min returns the smaller of the passed values.

Types

type Delta

type Delta struct {
	DX, DY float32
}

Delta is a generic X, Y movement or offset representation.

func NewDelta

func NewDelta(dx float32, dy float32) Delta

NewDelta returns a newly allocated Delta representing a movement in the X and Y axis.

func (Delta) Components

func (v Delta) Components() (float32, float32)

func (Delta) IsZero

func (v Delta) IsZero() bool

type Matrix

type Matrix struct {
	A, B, C, D, TX, TY float32
}

Matrix represents a 2D affine transformation matrix.

The matrix is stored as 6 float32 values in row-major order:

| A  C  TX |
| B  D  TY |
| 0  0  1  |

The zero value is NOT identity — use Identity to create an identity matrix. However, [canvas.baseObject.Transform] treats the zero value as identity for ergonomics (objects with no transform set behave as untransformed).

func Identity

func Identity() Matrix

Identity returns the identity matrix (no transformation).

func NewRotation

func NewRotation(radians float32) Matrix

NewRotation returns a matrix that rotates counter-clockwise by the given angle in radians around the origin.

func NewRotationAround

func NewRotationAround(radians, px, py float32) Matrix

NewRotationAround returns a matrix that rotates counter-clockwise by the given angle in radians around the point (px, py).

func NewScale

func NewScale(sx, sy float32) Matrix

NewScale returns a matrix that scales by (sx, sy).

func NewSkew

func NewSkew(kx, ky float32) Matrix

NewSkew returns a matrix that skews by (kx, ky) radians.

func NewTranslation

func NewTranslation(tx, ty float32) Matrix

NewTranslation returns a matrix that translates by (tx, ty).

func (Matrix) AABB

func (m Matrix) AABB(w, h float32) (minX, minY, maxX, maxY float32)

AABB computes the axis-aligned bounding box of the rectangle (0,0)-(w,h) after applying this transform. Returns (minX, minY, maxX, maxY).

func (Matrix) Determinant

func (m Matrix) Determinant() float32

Determinant returns the determinant of the linear part of the matrix.

func (Matrix) Inverse

func (m Matrix) Inverse() (Matrix, bool)

Inverse returns the inverse of m and true, or the zero matrix and false if m is not invertible (determinant is zero).

func (Matrix) IsIdentity

func (m Matrix) IsIdentity() bool

IsIdentity reports whether m is the identity matrix.

func (Matrix) IsZeroOrIdentity

func (m Matrix) IsZeroOrIdentity() bool

IsZeroOrIdentity reports whether m is the zero value or the identity matrix. This is useful for checking if a transform has been set on an object where the zero value of Matrix is used as "no transform".

func (Matrix) Multiply

func (m Matrix) Multiply(n Matrix) Matrix

Multiply returns the matrix product m * n. This applies n first, then m. For example, to translate then rotate:

rotate.Multiply(translate)

func (Matrix) ToGL

func (m Matrix) ToGL() [9]float32

ToGL returns the matrix as a 9-element column-major array suitable for uploading to an OpenGL mat3 uniform via glUniformMatrix3fv.

Column-major layout:

[A, B, 0, C, D, 0, TX, TY, 1]

func (Matrix) TransformPoint

func (m Matrix) TransformPoint(x, y float32) (float32, float32)

TransformPoint applies the full affine transform (including translation) to the point (x, y) and returns the transformed coordinates.

func (Matrix) TransformVector

func (m Matrix) TransformVector(x, y float32) (float32, float32)

TransformVector applies only the linear part of the transform (no translation) to the vector (x, y). Useful for transforming directions and sizes.

type Position

type Position struct {
	X float32 // The position from the parent's left edge
	Y float32 // The position from the parent's top edge
}

Position describes a generic X, Y coordinate relative to a parent canvas or object.

func NewPos

func NewPos(x float32, y float32) Position

NewPos returns a newly allocated Position.

func NewSquareOffsetPos

func NewSquareOffsetPos(length float32) Position

NewSquareOffsetPos returns a Position with the same x and y.

func (Position) Add

func (p Position) Add(v Vector2) Position

func (Position) AddXY

func (p Position) AddXY(x, y float32) Position

func (Position) Components

func (p Position) Components() (float32, float32)

func (Position) IsZero

func (p Position) IsZero() bool

func (Position) Subtract

func (p Position) Subtract(v Vector2) Position

func (Position) SubtractXY

func (p Position) SubtractXY(x, y float32) Position

type Rectangle

type Rectangle struct {
	Pos  Position
	Size Size
}

Rectangle describes an axis-aligned rectangle by its top-left position and its size. The zero Rectangle (zero Pos and zero Size) is used by callers to signal "no/invalid rectangle" — e.g. a caret position that is out of range or scrolled out of view.

Since: 1.0

func NewRectangle

func NewRectangle(x, y, w, h float32) Rectangle

NewRectangle returns a Rectangle at (x, y) with the given width and height.

Since: 1.0

func (Rectangle) IsZero

func (r Rectangle) IsZero() bool

IsZero reports whether the rectangle has both a zero position and zero size, the conventional "no rectangle" sentinel.

Since: 1.0

type Size

type Size struct {
	Width  float32 // The number of units along the X axis.
	Height float32 // The number of units along the Y axis.
}

Size describes something with width and height.

func NewSize

func NewSize(w float32, h float32) Size

NewSize returns a newly allocated Size of the specified dimensions.

func NewSquareSize

func NewSquareSize(side float32) Size

NewSquareSize returns a Size with the same width and height.

func (Size) Add

func (s Size) Add(v Vector2) Size

func (Size) AddWidthHeight

func (s Size) AddWidthHeight(width, height float32) Size

func (Size) Components

func (s Size) Components() (float32, float32)

func (Size) IsZero

func (s Size) IsZero() bool

func (Size) Max

func (s Size) Max(v Vector2) Size

func (Size) Min

func (s Size) Min(v Vector2) Size

func (Size) Subtract

func (s Size) Subtract(v Vector2) Size

func (Size) SubtractWidthHeight

func (s Size) SubtractWidthHeight(width, height float32) Size

type Vector2

type Vector2 interface {
	Components() (float32, float32)
	IsZero() bool
}

Vector2 marks geometry types that can operate as a coordinate vector.

Jump to

Keyboard shortcuts

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