Skip to content

geom ​

go
import "github.com/tangoui/tango/ui/geom"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package geom holds the small geometry vocabulary shared by every layer of the Tango self-drawn UI (layout, paint, text, input). All values are in logical pixels unless a doc comment says otherwise; renderers multiply by the window scale factor at the very end.

变量 ​

go
var Inf = float32(math.Inf(1))

Inf is a convenient "unbounded" length.

函数 ​

func IsInf ​

go
func IsInf(v float32) bool

IsInf reports whether v is +Inf.

类型 ​

Affine ​

go
type Affine struct{ A, B, C, D, E, F float32 }

Affine is a 2-D affine transform in the usual

| A C E |
| B D F |
| 0 0 1 |

layout: a point (x, y) maps to (A·x + C·y + E, B·x + D·y + F). The zero value is degenerate; start from Identity or one of the constructors. Angles are radians, positive turns clockwise (y grows downwards).

func Identity ​

go
func Identity() Affine

Identity is the transform that changes nothing.

func Rotate ​

go
func Rotate(angle float64) Affine

Rotate rotates by angle radians (clockwise on screen) about the origin.

func RotateAround ​

go
func RotateAround(angle float64, c Point) Affine

RotateAround rotates by angle radians about c.

func Scale ​

go
func Scale(sx, sy float32) Affine

Scale scales about the origin.

func ScaleAround ​

go
func ScaleAround(sx, sy float32, c Point) Affine

ScaleAround scales by (sx, sy) keeping c fixed.

func Skew ​

go
func Skew(ax, ay float64) Affine

Skew shears by the given angles (radians): x' = x + tan(ax)·y and y' = y + tan(ay)·x, like CSS skew().

func Translate ​

go
func Translate(dx, dy float32) Affine

Translate moves by (dx, dy).

func (Affine) Apply ​

go
func (m Affine) Apply(p Point) Point

Apply maps p.

func (Affine) AxisAligned ​

go
func (m Affine) AxisAligned() bool

AxisAligned reports whether m only scales (by positive factors) and translates, so rectangles stay rectangles with the same orientation.

func (Affine) Bounds ​

go
func (m Affine) Bounds(r Rect) Rect

Bounds returns the axis-aligned bounding box of r after m.

func (Affine) Det ​

go
func (m Affine) Det() float32

Det is the determinant (area scale factor, negative when mirrored).

func (Affine) Invert ​

go
func (m Affine) Invert() (Affine, bool)

Invert returns the inverse transform; ok is false when m is singular.

func (Affine) IsIdentity ​

go
func (m Affine) IsIdentity() bool

IsIdentity reports whether m changes nothing.

func (Affine) MaxScale ​

go
func (m Affine) MaxScale() float32

MaxScale is the largest factor by which m stretches a length.

func (Affine) Mul ​

go
func (m Affine) Mul(n Affine) Affine

Mul returns the matrix product m·n: the result applies n first, then m.

func (Affine) Then ​

go
func (m Affine) Then(n Affine) Affine

Then returns the transform that applies m first, then n.

Insets ​

go
type Insets struct{ Top, Right, Bottom, Left float32 }

Insets are per-edge distances, CSS order.

func All ​

go
func All(v float32) Insets

All returns equal insets on every edge.

func VH ​

go
func VH(v, h float32) Insets

VH returns CSS two-value insets: vertical, horizontal.

func (Insets) Add ​

go
func (i Insets) Add(o Insets) Insets

Add sums two insets.

func (Insets) Horizontal ​

go
func (i Insets) Horizontal() float32

Horizontal returns Left+Right.

func (Insets) Vertical ​

go
func (i Insets) Vertical() float32

Vertical returns Top+Bottom.

Point ​

go
type Point struct{ X, Y float32 }

Point is a position in logical pixels.

func Pt ​

go
func Pt(x, y float32) Point

Pt is shorthand for Point{x, y}.

func (Point) Add ​

go
func (p Point) Add(q Point) Point

Add returns p+q.

func (Point) Sub ​

go
func (p Point) Sub(q Point) Point

Sub returns p-q.

Radii ​

go
type Radii struct{ TL, TR, BR, BL float32 }

Radii are per-corner radii: top-left, top-right, bottom-right, bottom-left.

func Rad ​

go
func Rad(r float32) Radii

Rad returns equal radii.

func (Radii) Clamp ​

go
func (r Radii) Clamp(w, h float32) Radii

Clamp limits each radius so it fits in a w×h box.

func (Radii) Grow ​

go
func (r Radii) Grow(d float32) Radii

Grow adds d to every non-negative radius (used for outlines/shadows).

func (Radii) IsZero ​

go
func (r Radii) IsZero() bool

IsZero reports whether all radii are zero.

Rect ​

go
type Rect struct{ X, Y, W, H float32 }

Rect is an axis-aligned rectangle given by origin and size.

func R ​

go
func R(x, y, w, h float32) Rect

R is shorthand for Rect{x, y, w, h}.

func (Rect) Bottom ​

go
func (r Rect) Bottom() float32

Bottom returns Y+H.

func (Rect) Center ​

go
func (r Rect) Center() Point

Center returns the center point.

func (Rect) Contains ​

go
func (r Rect) Contains(p Point) bool

Contains reports whether p lies inside r (half-open on the far edges).

func (Rect) Empty ​

go
func (r Rect) Empty() bool

Empty reports whether the rectangle has no area.

func (Rect) Expand ​

go
func (r Rect) Expand(d float32) Rect

Expand grows r by d on every side (negative d shrinks).

func (Rect) Inset ​

go
func (r Rect) Inset(in Insets) Rect

Inset shrinks r by the insets. The result never has negative size.

func (Rect) Intersect ​

go
func (r Rect) Intersect(s Rect) Rect

Intersect returns the overlap of r and s (zero Rect when disjoint).

func (Rect) Min ​

go
func (r Rect) Min() Point

Min returns the top-left corner.

func (Rect) Offset ​

go
func (r Rect) Offset(dx, dy float32) Rect

Offset translates r.

func (Rect) Right ​

go
func (r Rect) Right() float32

Right returns X+W.

func (Rect) Size ​

go
func (r Rect) Size() Size

Size returns the rectangle size.

func (Rect) Union ​

go
func (r Rect) Union(s Rect) Rect

Union returns the smallest rectangle containing r and s. Empty operands are ignored.

Size ​

go
type Size struct{ W, H float32 }

Size is a width/height pair.

以 MIT 许可发布