canvas

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BoxZero is a preset box that represents an intentional zero value.
	BoxZero = Box{IsSet: true}
)

Functions

This section is empty.

Types

type Box

type Box struct {
	Top    int
	Left   int
	Right  int
	Bottom int
	IsSet  bool // IsSet is true if the box is set to a values explicitly.
}

Box represents the main 4 dimensions of a box.

func NewBox

func NewBox(top, left, right, bottom int) Box

NewBox returns a new (set) box.

func (Box) Aspect

func (b Box) Aspect() float64

Aspect returns the aspect ratio of the box.

func (Box) Center

func (b Box) Center() (x, y int)

Center returns the center of the box

func (Box) Clone

func (b Box) Clone() Box

Clone returns a new copy of the box.

func (Box) Constrain

func (b Box) Constrain(other Box) Box

Constrain is similar to `Fit` except that it will work more literally like the opposite of grow.

func (Box) Corners

func (b Box) Corners() BoxCorners

Corners returns the box as a set of corners.

func (Box) Equals

func (b Box) Equals(other Box) bool

Equals returns if the box equals another box.

func (Box) Fit

func (b Box) Fit(other Box) Box

Fit is functionally the inverse of grow. Fit maintains the original aspect ratio of the `other` box, but constrains it to the bounds of the target box.

func (Box) GetBottom

func (b Box) GetBottom(defaults ...int) int

GetBottom returns a coalesced value with a default.

func (Box) GetLeft

func (b Box) GetLeft(defaults ...int) int

GetLeft returns a coalesced value with a default.

func (Box) GetRight

func (b Box) GetRight(defaults ...int) int

GetRight returns a coalesced value with a default.

func (Box) GetTop

func (b Box) GetTop(defaults ...int) int

GetTop returns a coalesced value with a default.

func (Box) Grow

func (b Box) Grow(other Box) Box

Grow grows a box based on another box.

func (Box) Height

func (b Box) Height() int

Height returns the height

func (Box) IsBiggerThan

func (b Box) IsBiggerThan(other Box) bool

IsBiggerThan returns if a box is bigger than another box.

func (Box) IsSmallerThan

func (b Box) IsSmallerThan(other Box) bool

IsSmallerThan returns if a box is smaller than another box.

func (Box) IsZero

func (b Box) IsZero() bool

IsZero returns if the box is set or not.

func (Box) OuterConstrain

func (b Box) OuterConstrain(bounds, other Box) Box

OuterConstrain is similar to `Constraint` with the difference that it applies corrections

func (Box) Shift

func (b Box) Shift(x, y int) Box

Shift pushes a box by x,y.

func (Box) String

func (b Box) String() string

String returns a string representation of the box.

func (Box) Validate

func (b Box) Validate() error

func (Box) Width

func (b Box) Width() int

Width returns the width

type BoxCorners

type BoxCorners struct {
	TopLeft, TopRight, BottomRight, BottomLeft Point
}

BoxCorners is a box with independent corners.

func (BoxCorners) Box

func (bc BoxCorners) Box() Box

Box return the BoxCorners as a regular box.

func (BoxCorners) Center

func (bc BoxCorners) Center() (x, y int)

Center returns the center of the box

func (BoxCorners) Equals

func (bc BoxCorners) Equals(other BoxCorners) bool

Equals returns if the box equals another box.

func (BoxCorners) Height

func (bc BoxCorners) Height() int

Height returns the height

func (BoxCorners) Rotate

func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners

Rotate rotates the box.

func (BoxCorners) String

func (bc BoxCorners) String() string

func (BoxCorners) Width

func (bc BoxCorners) Width() int

Width returns the width

type Point

type Point struct {
	X, Y int
}

Point is an X,Y pair

func (Point) DistanceTo

func (p Point) DistanceTo(other Point) float64

DistanceTo calculates the distance to another point.

func (Point) Equals

func (p Point) Equals(other Point) bool

Equals returns if a point equals another point.

func (Point) String

func (p Point) String() string

String returns a string representation of the point.

Jump to

Keyboard shortcuts

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