coords

package
Version: v0.0.0-...-683b059 Latest Latest

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause

Documentation ¶

Overview ¶

Package coords keeps coordinates-related structs and their utilities for the UI system.

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func CompareBoundsWithMargin ¶

`func CompareBoundsWithMargin(a, b Rect, margin int) bool`

CompareBoundsWithMargin returns true if the given two bounds have the same value allowing the same margin in all directions.

func CompareBoundsWithMargins ¶

`func CompareBoundsWithMargins(a, b Rect, ml, mt, mr, mb int) bool`

CompareBoundsWithMargins returns true if the given two bounds have the same value allowing the provided margins.

Types ¶

type Point ¶

```type Point struct {
X int `json:"x"`
Y int `json:"y"`
}```

Point represents a location.

func NewPoint ¶

`func NewPoint(x, y int) Point`

NewPoint creates a new Point instance for given x,y coordinates.

`func (p Point) Add(p2 Point) Point`

func (Point) Equals ¶

`func (p Point) Equals(p2 Point) bool`

Equals returns true if the point equals another one.

func (Point) In ¶

`func (p Point) In(r Rect) bool`

In returns whether the point is contained within r.

func (Point) String ¶

`func (p Point) String() string`

String returns the string representation of Point.

func (Point) Sub ¶

`func (p Point) Sub(p2 Point) Point`

Sub returns the subtraction of two Points.

type Rect ¶

```type Rect struct {
Left   int `json:"left"`
Top    int `json:"top"`
Width  int `json:"width"`
Height int `json:"height"`
}```

Rect represents a rectangular region.

func ConvertBoundsFromDPToPX ¶

`func ConvertBoundsFromDPToPX(bounds Rect, dsf float64) Rect`

ConvertBoundsFromDPToPX converts the given bounds in dips to pixels based on the given device scale factor. The converted values of Left, Top, Width, and Height are rounded.

func ConvertBoundsFromPXToDP ¶

`func ConvertBoundsFromPXToDP(bounds Rect, dsf float64) Rect`

ConvertBoundsFromPXToDP converts the given bounds in pixels to dips based on the given device scale factor. The converted values of Left, Top, Width, and Height are rounded.

func NewRect ¶

`func NewRect(x, y, w, h int) Rect`

NewRect creates a new Rect instance for given x, y width, and height.

func NewRectLTRB ¶

`func NewRectLTRB(l, t, r, b int) Rect`

NewRectLTRB creates a new rect instance for left, top, right, and bottom coordinates.

func (Rect) Bottom ¶

`func (r Rect) Bottom() int`

Bottom returns the y-value of the bottom edge of the rectangle.

func (Rect) BottomCenter ¶

`func (r Rect) BottomCenter() Point`

BottomCenter returns the center location of the bottom edge of the rectangle.

func (Rect) BottomLeft ¶

`func (r Rect) BottomLeft() Point`

BottomLeft returns the location of the bottom left of the rectangle.

func (Rect) BottomRight ¶

`func (r Rect) BottomRight() Point`

BottomRight returns the location of the bottom right of the rectangle.

func (Rect) CenterPoint ¶

`func (r Rect) CenterPoint() Point`

CenterPoint returns the location of the center of the rectangle.

func (Rect) CenterX ¶

`func (r Rect) CenterX() int`

CenterX returns the x-value of the center point of the rectangle.

func (Rect) CenterY ¶

`func (r Rect) CenterY() int`

CenterY returns the y-value of the center point of the rectangle.

func (Rect) Contains ¶

`func (r Rect) Contains(other Rect) bool`

Contains returns whether `other` is a rectangle contained within r. A rectangle is considered to contain itself.

func (Rect) Empty ¶

`func (r Rect) Empty() bool`

Empty returns true if the r is zero-value.

func (Rect) Equals ¶

`func (r Rect) Equals(r2 Rect) bool`

Equals returns true if the Rect equals another one.

func (Rect) Intersection ¶

`func (r Rect) Intersection(other Rect) Rect`

Intersection returns the intersection of two rectangles, or an empty rectangle if they don't intersect.

func (Rect) LeftCenter ¶

`func (r Rect) LeftCenter() Point`

LeftCenter returns the center location of the left edge of the rectangle.

func (Rect) Right ¶

`func (r Rect) Right() int`

Right returns the x-value of the right edge of the rectangle.

func (Rect) RightCenter ¶

`func (r Rect) RightCenter() Point`

RightCenter returns the center location of the right edge of the rectangle.

func (Rect) Size ¶

`func (r Rect) Size() Size`

Size returns the size of the rect.

func (Rect) String ¶

`func (r Rect) String() string`

String returns the string representation of Rect.

func (Rect) TopLeft ¶

`func (r Rect) TopLeft() Point`

TopLeft returns the location of the top left of the rectangle.

func (Rect) TopRight ¶

`func (r Rect) TopRight() Point`

TopRight returns the location of the top right of the rectangle.

func (Rect) WithInset ¶

`func (r Rect) WithInset(dw, dh int) Rect`

WithInset returns a new Rect inset by the given amounts. If insetting would cause the rectangle to have negative area, instead an empty rectangle with the same CenterPoint is returned. Note that dw and dh may be negative to outset a rectangle.

func (Rect) WithOffset ¶

`func (r Rect) WithOffset(dl, dt int) Rect`

WithOffset returns a new Rect offset by the given amounts.

type Size ¶

```type Size struct {
Width  int `json:"width"`
Height int `json:"height"`
}```

Size represents a size of a region.

func NewSize ¶

`func NewSize(w, h int) Size`

NewSize creates a new Size instance for given width,height.

func (Size) String ¶

`func (s Size) String() string`

String returns the string representation of Size.