geom

package
v0.0.0-...-1356a85 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NullPoint = Point{X: -math.MaxInt32, Y: -math.MaxInt32}

Functions

func IterateLine

func IterateLine(x0, y0, x1, y1 int, callBack BresenhamCallBack)

IterateLine from x0,y0 to x1,y1. For each point on the line it calls the callBack function. Note: The order of the points is not preserved.

func IterateLineOrdered

func IterateLineOrdered(x0, y0, x1, y1 int, callBack BresenhamCallBack)

IterateLineOrdered from x0,y0 to x1,y1. For each point on the line it calls the callBack function. Note: The order of the points is preserved, use IterateLineOrdered if speed is more important.

Types

type Alignment

type Alignment uint32
const (
	AlignmentHCenter Alignment = 1 << iota
	AlignmentHLeft
	AlignmentHRight
	AlignmentVCenter
	AlignmentVTop
	AlignmentVBottom

	AlignmentNone   Alignment = 0
	AlignmentCenter           = AlignmentHCenter | AlignmentVCenter
)

type BresenhamCallBack

type BresenhamCallBack func(x int, y int) bool

The BresenhamCallBack function should return true if the iteration needs to stop. x,y are the current iteration coordinates.

type FitMode

type FitMode int
const (
	FitModeAlign FitMode = iota
	FitModeFill
	FitModeAspectFit
	FitModeAspectFill
)

type FreeRectChoiceHeuristic

type FreeRectChoiceHeuristic int
const (
	// BSSF: Positions the rectangle against the short side of a free rectangle into which it fits the best.
	RectBestShortSideFit FreeRectChoiceHeuristic = iota
	// BAF: Positions the rectangle into the smallest free rect into which it fits.
	RectBestAreaFit
	// BL: Does the Tetris placement.
	RectBottomLeftRule
)

type Insets

type Insets struct {
	Top, Right, Bottom, Left int
}

func HomogeneousInsets

func HomogeneousInsets(inset int) Insets

type MaxRectsBinPacker

type MaxRectsBinPacker struct {
	// contains filtered or unexported fields
}

func NewMaxRectsBinPacker

func NewMaxRectsBinPacker(width, height int, paddingX, paddingY int, allowRotation bool) *MaxRectsBinPacker

Create a new MaxRectsBinPacker packer

func (*MaxRectsBinPacker) Occupancy

func (mr *MaxRectsBinPacker) Occupancy() float32

Computes the ratio of used surface area

func (*MaxRectsBinPacker) Pack

func (mr *MaxRectsBinPacker) Pack(inputRects []RectNode, method FreeRectChoiceHeuristic) *MaxRectsBinResult

Packs the passed rects with the chosen heuristic. The dimensions of the returned rects will include the padding.

type MaxRectsBinResult

type MaxRectsBinResult struct {
	PlacedRects    []RectNode              // Rects that have been placed
	NotPlacedRects []RectNode              // Rects that didn't fit in the provided area
	Width          int                     // Total Width used by the rects
	Height         int                     // Total Height used by the rects
	Method         FreeRectChoiceHeuristic // Method used to pack the rects
}

type Point

type Point struct {
	X, Y int
}

func PointFromFloats

func PointFromFloats(x, y float32) Point

func (Point) Add

func (p Point) Add(other Point) Point

func (Point) EqualsTo

func (p Point) EqualsTo(other Point) bool

func (Point) Scale

func (p Point) Scale(scale float32) Point

func (Point) String

func (p Point) String() string

type Rect

type Rect struct {
	X, Y, W, H int
}

func RectFromArray

func RectFromArray(values [4]int) Rect

func RectFromFloat

func RectFromFloat(x, y, w, h float32) Rect

func RectFromRectangle

func RectFromRectangle(r image.Rectangle) Rect

func (Rect) AlignIn

func (r Rect) AlignIn(b Rect, alignment Alignment) Rect

func (Rect) Bottom

func (r Rect) Bottom() int

func (Rect) Center

func (r Rect) Center() Point

func (Rect) CenterIn

func (r Rect) CenterIn(o Rect) Rect

func (Rect) CenterX

func (r Rect) CenterX() int

func (Rect) CenterY

func (r Rect) CenterY() int

func (Rect) ContainsPoint

func (r Rect) ContainsPoint(pointX, pointY int) bool

func (Rect) Empty

func (r Rect) Empty() bool

func (Rect) EqualsTo

func (r Rect) EqualsTo(other Rect) bool

func (Rect) FitIn

func (r Rect) FitIn(b Rect, mode FitMode, alignment Alignment) Rect

func (Rect) Intersect

func (r Rect) Intersect(r2 Rect) bool

func (Rect) IntersectWithCircle

func (r Rect) IntersectWithCircle(circleX, circleY, circleRadius int) bool

https://yal.cc/rectangle-circle-intersection-test/

func (Rect) Intersection

func (r Rect) Intersection(s Rect) Rect

func (Rect) IsContainedIn

func (r Rect) IsContainedIn(b Rect) bool

func (Rect) Left

func (r Rect) Left() int

func (Rect) MaxPoint

func (r Rect) MaxPoint() Point

func (Rect) MinPoint

func (r Rect) MinPoint() Point

func (Rect) MoveTo

func (r Rect) MoveTo(x, y int) Rect

func (Rect) ResizeTo

func (r Rect) ResizeTo(w, h int) Rect

func (Rect) Right

func (r Rect) Right() int

func (Rect) Scale

func (r Rect) Scale(factor float32) Rect

func (Rect) ShrinkByInsets

func (r Rect) ShrinkByInsets(i Insets) Rect

func (Rect) ShrinkByInt

func (r Rect) ShrinkByInt(i int) Rect

func (Rect) Size

func (r Rect) Size() Size

func (Rect) String

func (r Rect) String() string

func (Rect) ToRectangle

func (r Rect) ToRectangle() image.Rectangle

func (Rect) Top

func (r Rect) Top() int

func (Rect) Translate

func (r Rect) Translate(x, y int) Rect

func (Rect) TranslateFloat

func (r Rect) TranslateFloat(x, y float32) Rect

func (Rect) TranslatePoint

func (r Rect) TranslatePoint(point Point) Rect

func (Rect) UnionWith

func (r Rect) UnionWith(other Rect) Rect

type RectNode

type RectNode struct {
	Rect         // Width and Height include padding
	Index   int  // This index is used to keep track of which of the input rects this is
	Rotated bool // True if the rect has been rotated 90 degrees
}

func NewRectNode

func NewRectNode(index, width, height int) RectNode

func NewRectNodeFrom

func NewRectNodeFrom(b RectNode) RectNode

type Segment

type Segment struct {
	A, B Point
}

type Size

type Size struct {
	W, H int
}

func MaxSize

func MaxSize(a, b Size) Size

func MinSize

func MinSize(a, b Size) Size

func SizeFromFloats

func SizeFromFloats(w, h float32) Size

func (Size) Scale

func (s Size) Scale(factor float32) Size

func (Size) String

func (s Size) String() string

func (Size) Sub

func (s Size) Sub(t Size) Size

Jump to

Keyboard shortcuts

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