Documentation ¶
Overview ¶
Package geom provides utilities for manipulating rectangular geometry.
It is patterned heavily after image.Rectangle and image.Point, but vastly extends their capabilities.
Index ¶
- func ArrangeVerticalStack[T Scalar](rects []Rect[T])
- func TileEvenHorizontally[T Scalar](tiles []Rect[T], r Rect[T])
- func TileEvenVertically[T Scalar](tiles []Rect[T], r Rect[T])
- func TileRightThenDown[T Scalar](tiles []Rect[T], r Rect[T])
- func TileRows[T Scalar](tiles []Rect[T], r Rect[T], cols int)
- func TileTwoThirdsSidebar[T Scalar](tiles []Rect[T], r Rect[T])
- type Edges
- type Point
- type Rect
- func (r Rect[T]) Add(p Point[T]) Rect[T]
- func (r Rect[T]) Aspect() float64
- func (r Rect[T]) Canon() Rect[T]
- func (r Rect[T]) Center() Point[T]
- func (r Rect[T]) CenterAt(p Point[T]) Rect[T]
- func (r Rect[T]) ClosestIn(s Rect[T]) Rect[T]
- func (r Rect[T]) Dx() T
- func (r Rect[T]) Dy() T
- func (r Rect[T]) Empty() bool
- func (r Rect[T]) Eq(s Rect[T]) bool
- func (r Rect[T]) FitTo(size Point[T]) Rect[T]
- func (r Rect[T]) ImageRect() image.Rectangle
- func (r Rect[T]) In(s Rect[T]) bool
- func (r Rect[T]) Inset(n T) Rect[T]
- func (r Rect[T]) Inset2(n Point[T]) Rect[T]
- func (r Rect[T]) Intersect(s Rect[T]) Rect[T]
- func (r Rect[T]) IsZero() bool
- func (r Rect[T]) Overlaps(s Rect[T]) bool
- func (r Rect[T]) Pad(top, bottom, left, right T) Rect[T]
- func (r Rect[T]) PropShift(to, from Rect[T]) Rect[T]
- func (r Rect[T]) Resize(size Point[T]) Rect[T]
- func (r Rect[T]) Size() Point[T]
- func (r Rect[T]) Sub(p Point[T]) Rect[T]
- func (r Rect[T]) Union(s Rect[T]) Rect[T]
- func (r Rect[T]) WithAspect(aspect float64) Rect[T]
- type Scalar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrangeVerticalStack ¶
ArrangeVerticalStack arranges the subsequent rectangles of rects underneath the first vertically, expanding all for which it is necessary so that they are all the same width including the first.
func TileEvenHorizontally ¶
TileEvenHorizontally arranges and resizes the elements of tiles so that the result are a series of rectangles that comprise an even, horizontal splitting of r. In other words,
tiles := make([]geom.Rect[float64], 3) TileEvenHorizontally(tiles, r)
will produce
---------- | | | | ----------
func TileEvenVertically ¶
TileEvenVertically arranges and resizes the elements of tiles so that the result are a series of rectangles that comprise an even, vertical splitting of r. In other words,
tiles := make([]geom.Rect[float64], 3) TileEvenVertically(tiles, r)
will produce
---------- | | ---------- | | ---------- | | ----------
func TileRightThenDown ¶
TileRightThenDown arranges and resizes the elements of tiles in order to split r into a series of rectangles that recursively split each section halfway to the right and then downwards. In other words,
tiles := make([]geom.Rect[float64], 4) TileRightThenDown(tiles, r)
will produce
------------ | | | | ------- | | | | ------------
func TileRows ¶
TileRows arranges and resizes the elements of tiles to produce a series of rows and columns the union of which reproduces r. The final row of the table is split evenly into at most cols columns. When that number is exceeded, a new row is added below it instead.
func TileTwoThirdsSidebar ¶
TileTwoThirdsSidebar arranges and resizes the elements of tiles so that the result are a series of rectangles where the first is two-thirds the width of r and the rest are arranged vertically in an even split in the remaining space.
Types ¶
type Rect ¶
A Rect contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.
func Align ¶
Align shifts the specified edges of inner to align with the corresponding edges of outer, stretching the rectangle as necessary if opposite edges are specified.
func Rt ¶
Rt is shorthand for Rect{Pt(x0, y0), Pt(x1, y1)}. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Rect[T]) CenterAt ¶
CenterAt returns a new rectangle with the same dimensions as r but with a center point at p.
func (Rect[T]) ClosestIn ¶
ClosestIn returns r shifted to be inside of s at the closest possible point to its starting position. If r is already entirely inside of s, r is returned unchanged. If r can not fit entirely inside of s, the zero Rect is returned.
func (Rect[T]) WithAspect ¶
type Scalar ¶
type Scalar interface { constraints.Integer | constraints.Float }
Scalar is a constraint for the types that geom types and functions can handle.