rect

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Rect2D

type Rect2D[T Number] struct {
	Position *vector.Vector2D[T] `json:"position"`
	Size     *vector.Vector2D[T] `json:"size"`
}

A 2D axis-aligned bounding box using floating-point coordinates. Represents an axis-aligned rectangle in a 2D space. It is defined by its position and size, which are Vector2D.

func New2D

func New2D[T Number](position, size *vector.Vector2D[T]) *Rect2D[T]

New2D constructs a new VRect2D from the given position and size. position is the rectangle start x and y size is the rectangle width and height

func (*Rect2D[T]) Abs added in v0.0.7

func (r *Rect2D[T]) Abs() *Rect2D[T]

Abs returns a Rect2D equivalent to this rectangle, with its width and height modified to be non-negative values, and with its position being the top-left corner of the rectangle. E.g: Rect2D(25, 25, -100, -50) ~> Rect2D(-75, -25, 100, 50)

func (*Rect2D[T]) GetArea

func (r *Rect2D[T]) GetArea() T

GetArea returns the rectangle's area. This is equivalent to size.x * size.y

func (*Rect2D[T]) GetCenter

func (r *Rect2D[T]) GetCenter() *vector.Vector2D[T]

GetCenter returns the center point of the rectangle. This is the same as position + (size / 2.0).

func (*Rect2D[T]) GetPosition added in v0.0.6

func (r *Rect2D[T]) GetPosition() *vector.Vector2D[T]

GetPosition returns a vector with the starting point of the rectangle as x and y

func (*Rect2D[T]) GetRandomPoint added in v0.0.8

func (r *Rect2D[T]) GetRandomPoint() *vector.Vector2D[T]

GetRandomPoint generates a random coordinates vector within the rectangle's bounds

func (*Rect2D[T]) GetSize added in v0.0.6

func (r *Rect2D[T]) GetSize() *vector.Vector2D[T]

GetSize returns a vector with the current size of the Rectangle as width and height

func (*Rect2D[T]) HasPoint

func (r *Rect2D[T]) HasPoint(point *vector.Vector2D[T]) bool

HasPoint returns true if the rectangle contains the given point. By convention, points on the right and bottom edges are not included.

Jump to

Keyboard shortcuts

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