Documentation
¶
Overview ¶
Scaff + math = scath. As you can tell, this is scaff's math package for things like padding, vectors and more.
Vec provides abstractions over vector math. A lot of the code for it is taken from https://github.com/setanarut/v.
Padding is for general padding in UI and more.
Timeframe provides functions to deal with, well, time frames. Various lerp functions are available as well to help with animations and transitions.
Constraints are normal rectangle constraints with lots of utility.
Index ¶
- Constants
- Variables
- type Constraints
- func Expand(width, height float64) Constraints
- func Loose(maxX, maxY float64) Constraints
- func Minimum(minX, minY float64) Constraints
- func NewConstraints(minX, maxX, minY, maxY float64) Constraints
- func Tight(width, height float64) Constraints
- func TightFor(width, height float64) Constraints
- func TightForFinite(width, height float64) Constraints
- func Unconstrained() Constraints
- func (c Constraints) DoesXFit(w float64) bool
- func (c Constraints) DoesYFit(h float64) bool
- func (c Constraints) Fits(c2 Constraints) bool
- func (c Constraints) IsTight() bool
- func (c Constraints) Max(horizontal bool) float64
- func (c Constraints) Min(horizontal bool) float64
- func (c Constraints) RealMax(horizontal bool) float64
- func (c Constraints) RealMaxX() float64
- func (c Constraints) RealMaxY() float64
- func (c Constraints) SubtractPadding(padding Padding) Constraints
- func (c Constraints) TakeMaxWithin(c2 Constraints) (Vec, error)
- type Padding
- func NewPadding(top, right, bottom, left float64) Padding
- func Pad(value float64) Padding
- func PadBottom(value float64) Padding
- func PadHorizontal(value float64) Padding
- func PadLeft(value float64) Padding
- func PadRight(value float64) Padding
- func PadTop(value float64) Padding
- func PadVertical(value float64) Padding
- type Timeframe
- func (f Timeframe) AddDelay(delay time.Duration) Timeframe
- func (f Timeframe) IsBackwards() bool
- func (f Timeframe) LerpFloat(now time.Time, a, b float64) float64
- func (f Timeframe) LerpInt(now time.Time, a, b int) int
- func (f Timeframe) LerpTypewriter(now time.Time, a string) string
- func (f Timeframe) LerpTypewriterBetween(now time.Time, a, b string) string
- func (f Timeframe) LerpUint(now time.Time, a, b uint) uint
- func (f Timeframe) MakeBackwards() Timeframe
- func (f Timeframe) MakeForwards() Timeframe
- func (f Timeframe) Over(now time.Time) bool
- func (f Timeframe) Remaining(now time.Time) time.Duration
- func (f Timeframe) Started(now time.Time) bool
- type Vec
- func (v Vec) Abs() Vec
- func (v Vec) AbsX() float64
- func (v Vec) AbsY() float64
- func (v Vec) Add(a Vec) Vec
- func (v Vec) AddC(c float64) Vec
- func (v Vec) AddPadding(padding Padding) Vec
- func (v Vec) Angle() float64
- func (v Vec) AngleTo(other Vec) float64
- func (v Vec) Ceil() Vec
- func (v Vec) Cross(other Vec) float64
- func (v Vec) Dist(other Vec) float64
- func (v Vec) DistSq(other Vec) float64
- func (v Vec) Div(a Vec) Vec
- func (v Vec) DivS(s float64) Vec
- func (v Vec) Dot(other Vec) float64
- func (v Vec) Equals(other Vec) bool
- func (v Vec) EqualsPr(other Vec, allowedDelta float64) bool
- func (v Vec) FitsWithin(c Constraints) bool
- func (v Vec) Floor() Vec
- func (v Vec) IsWithinRectangle(start Vec, size Vec) bool
- func (v Vec) IsZero() bool
- func (v Vec) Lerp(other Vec, t float64) Vec
- func (v Vec) Limit(max float64) Vec
- func (v Vec) Mag() float64
- func (v Vec) MagSq() float64
- func (v Vec) Mul(a Vec) Vec
- func (v Vec) Neg() Vec
- func (v Vec) NegX() Vec
- func (v Vec) NegY() Vec
- func (v Vec) Project(other Vec) Vec
- func (v Vec) Reflect(normal Vec) Vec
- func (v Vec) Rotate(angle float64) Vec
- func (v Vec) Round() Vec
- func (v Vec) Scale(s float64) Vec
- func (v Vec) Slerp(to Vec, weight float64) Vec
- func (v Vec) String() string
- func (v Vec) Sub(a Vec) Vec
- func (v Vec) SubtractPadding(padding Padding) Vec
- func (v Vec) Unit() Vec
Constants ¶
const Infinite float64 = -1
Infinite represents an unbounded maximum size.
Variables ¶
var ( // Zero Vec{0, 0} vector is a vector with all components set to 0. Zero = Vec{0, 0} // One Vec{1, 1} vector is a vector with all components set to 1. One = Vec{1, 1} // Left unit vector. Vec{-1, 0} Represents the direction of left. Left = Vec{-1, 0} // Right unit vector. Vec{1, 0} Represents the direction of right. Right = Vec{1, 0} // Up unit vector. Vec{0, -1} Y is down in 2D, so this vector points -Y. Up = Vec{0, -1} // Down unit vector. Vec{0, 1} Y is down in 2D, so this vector points +Y. Down = Vec{0, 1} )
Functions ¶
This section is empty.
Types ¶
type Constraints ¶
func Expand ¶
func Expand(width, height float64) Constraints
Expand returns constraints that fill specified finite axes.
func Loose ¶
func Loose(maxX, maxY float64) Constraints
Loose returns constraints that are only bounded by maxima.
func Minimum ¶
func Minimum(minX, minY float64) Constraints
func NewConstraints ¶
func NewConstraints(minX, maxX, minY, maxY float64) Constraints
NewConstraints creates normalized width and height constraints.
func Tight ¶
func Tight(width, height float64) Constraints
Tight returns constraints with an exact width and height.
func TightFor ¶
func TightFor(width, height float64) Constraints
TightFor returns tight constraints for provided axes.
func TightForFinite ¶
func TightForFinite(width, height float64) Constraints
TightForFinite returns tight constraints only for finite axes.
func Unconstrained ¶
func Unconstrained() Constraints
Unconstrained returns constraints with no upper bound.
func (Constraints) DoesXFit ¶
func (c Constraints) DoesXFit(w float64) bool
func (Constraints) DoesYFit ¶
func (c Constraints) DoesYFit(h float64) bool
func (Constraints) Fits ¶
func (c Constraints) Fits(c2 Constraints) bool
func (Constraints) IsTight ¶
func (c Constraints) IsTight() bool
func (Constraints) Max ¶
func (c Constraints) Max(horizontal bool) float64
Find the max size of constraints.
func (Constraints) Min ¶
func (c Constraints) Min(horizontal bool) float64
Find the min size of constraints.
func (Constraints) RealMax ¶
func (c Constraints) RealMax(horizontal bool) float64
Find the max size of constraints.
func (Constraints) RealMaxX ¶
func (c Constraints) RealMaxX() float64
func (Constraints) RealMaxY ¶
func (c Constraints) RealMaxY() float64
func (Constraints) SubtractPadding ¶
func (c Constraints) SubtractPadding(padding Padding) Constraints
SubtractPadding shrinks constraints by horizontal and vertical padding totals.
func (Constraints) TakeMaxWithin ¶
func (c Constraints) TakeMaxWithin(c2 Constraints) (Vec, error)
type Padding ¶
func NewPadding ¶
NewPadding creates padding with explicit top, right, bottom, and left values.
func PadHorizontal ¶
PadHorizontal creates padding on left and right sides.
func PadVertical ¶
PadVertical creates padding on top and bottom sides.
func (Padding) ToVecTopLeft ¶
ToVecTopLeft converts top and left padding into position vector.
type Timeframe ¶
type Timeframe struct {
// contains filtered or unexported fields
}
Timeframe represents a duration with a start and end time.
func NewTimeframe ¶
NewTimeframe creates a new Timeframe with the given start time and duration.
func (Timeframe) IsBackwards ¶
IsBackwards returns true if the timeframe is backwards.
func (Timeframe) LerpTypewriter ¶
LerpTypewriter writes a string with a typewriter effect, constructing it over time.
func (Timeframe) LerpTypewriterBetween ¶
LerpTypewriterBetween writes a string with a typewriter effect between two strings, deleting the first and then writing the second.
func (Timeframe) MakeBackwards ¶
MakeBackwards sets the timeframe to be backwards (end < start).
func (Timeframe) MakeForwards ¶
MakeForwards sets the timeframe to be forwards (end > start).
type Vec ¶
func (Vec) AddPadding ¶
AddPadding grows v by horizontal and vertical padding totals.
func (Vec) Cross ¶
Cross calculates the 2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the magnitude of the z value.
func (Vec) DistSq ¶
DistSq returns the squared distance between this and other.
Faster than v.Dist() when you only need to compare distances.
func (Vec) Equals ¶
Equals checks if two vectors are equal. (Be careful when comparing floating point numbers!)
func (Vec) EqualsPr ¶
EqualsP returns they are practically equal with each other within a delta tolerance.
func (Vec) FitsWithin ¶
func (v Vec) FitsWithin(c Constraints) bool
FitsWithin checks if x and y (treated as width and height) fit into constraints
func (Vec) Floor ¶
Floor returns vector with all components rounded down (towards negative infinity).
func (Vec) IsWithinRectangle ¶
IsWithin checks if the current position is in the rectangle starting at start with size.
func (Vec) MagSq ¶
MagSq returns the magnitude (length) of the vector, squared.
This method is often used to improve performance since, unlike Mag(), it does not require a Sqrt() operation.
func (Vec) Reflect ¶
Reflect returns the reflection of the vector v over the given normal. normal should be a normalized (unit) vector.
func (Vec) Slerp ¶
Slerp performs spherical linear interpolation between two vectors with given weight value in [0,1] range, returning interpolated vector
func (Vec) SubtractPadding ¶
SubtractPadding shrinks v by horizontal and vertical padding totals.