Documentation
¶
Overview ¶
Package geometry is go-gfx's floating-point 2-D geometry substrate: a Point, an axis-aligned Rect, and a 2-D affine Matrix (translate / scale / rotate / shear, composed, inverted, and applied to points and rectangles).
Everything here is in continuous float64 coordinates, deliberately distinct from the standard library's integer image.Point / image.Rectangle (which raster keeps using for pixel-grid bounds): a vector transform needs sub-pixel positions, so this layer never rounds until a consumer asks it to. The types are small value types passed and returned by value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matrix ¶
Matrix is a 2-D affine transform stored as the six meaningful entries of a 3x3 homogeneous matrix (the bottom row is always [0 0 1]):
| Xx Yx X0 | x' = Xx*x + Yx*y + X0 | Xy Yy Y0 | y' = Xy*x + Yy*y + Y0 | 0 0 1 |
It maps a Point with Matrix.TransformPoint. Transforms compose with Matrix.Mul: m.Mul(n) is the transform that applies n first and then m, so m.Mul(n).TransformPoint(p) equals m.TransformPoint(n.TransformPoint(p)). A Matrix is a small value type, passed and returned by value.
func Identity ¶
func Identity() Matrix
Identity returns the transform that leaves every point unchanged.
func Rotate ¶
Rotate returns the transform that rotates about the origin by theta radians, counter-clockwise in a y-down (screen) coordinate system.
func Shear ¶
Shear returns the transform that shears by (shx, shy): x gains shx*y and y gains shy*x.
func (Matrix) Determinant ¶
Determinant returns the determinant of the transform's linear part (Xx*Yy - Yx*Xy). Its magnitude is the area-scaling factor; a zero value means the transform collapses the plane and cannot be inverted.
func (Matrix) Invert ¶
Invert returns the inverse transform and ok=true, or the zero Matrix and ok=false when the transform is singular (zero determinant). When ok is true, inv.Mul(m) is the identity up to floating-point rounding.
func (Matrix) IsInvertible ¶
IsInvertible reports whether the transform has a non-zero determinant and can therefore be inverted.
func (Matrix) Mul ¶
Mul returns the composed transform m*n: the one that applies n first and then m to a point.
func (Matrix) TransformPoint ¶
TransformPoint returns p mapped through the transform.
func (Matrix) TransformRect ¶
TransformRect returns the axis-aligned bounding box of r's four corners after they are mapped through the transform. Under a rotation or shear the mapped rectangle is no longer axis-aligned, so this reports the tight enclosing upright box rather than the true (rotated) quadrilateral.
type Rect ¶
type Rect struct{ Min, Max Point }
Rect is an axis-aligned rectangle spanning [Min.X, Max.X] x [Min.Y, Max.Y]. It is well-formed ("canonical") when Min <= Max on both axes; the query and set methods assume canonical input, and Rect.Canon repairs one that is not.
func Rectangle ¶
Rectangle returns the canonical Rect with the given corner coordinates, swapping ends as needed so Min <= Max on each axis.
func (Rect) Canon ¶
Canon returns the rectangle with its corners ordered so Min <= Max on each axis.
func (Rect) Contains ¶
Contains reports whether p lies within the closed rectangle (edges included).
func (Rect) Empty ¶
Empty reports whether the rectangle encloses no area (zero or inverted on either axis).