collision

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package collision provides struct for helping with positioning and collisions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Circle

type Circle struct {
	Center vector.Vector
	Radius float64
}

Circle represents a 2d circle at Center with Radius

func NewCircle added in v0.1.3

func NewCircle(x, y, radius float64) Circle

NewCircle creates a new circle at point x, y and radius

func (Circle) Collides

func (c Circle) Collides(c2 Circle) bool

Collides compares two circles to check for collision

func (Circle) CollidesWithRect added in v0.1.3

func (c Circle) CollidesWithRect(r Rect) bool

CollidesWithRect compares a circle and a rect for collision

type Quadtree

type Quadtree[R Rectangler] struct {
	// contains filtered or unexported fields
}

Quadtree is a wrapper for quickly looking up possible collisions for it's element type R Because collision calculations are expensive to run, the quadtree looks for elements that are in the same quadrant to return a slice of possible collisions. Where further collision detection algorithms can be run.

func NewQuadtree

func NewQuadtree[R Rectangler](bounds Rect) *Quadtree[R]

NewQuadTree creates a new QuadTree with element type R, number of levels, and the bounds of the 2D plane

func (*Quadtree[R]) Clear

func (qt *Quadtree[R]) Clear()

Clear removes all elements from the QuadTree

func (*Quadtree[R]) Insert

func (qt *Quadtree[R]) Insert(rect R)

Insert adds an element R to the internal objects slice. Checks to determine if a new quadrant needs to be formed.

func (*Quadtree[R]) Retrieve

func (qt *Quadtree[R]) Retrieve(rect Rectangler) []R

Retrieve takes a Rectangler (not necessarily of type R of the QuadTree) and returns a slice of objects in the same quadrant

type Rect

type Rect struct {
	Origin        vector.Vector
	Width, Height float64
}

Rect represents a 2d rectangle at Origin with Width and Height

func NewRect

func NewRect(x, y, width, height float64) Rect

NewRect creates a rectangle at x, y with given width and height

func (Rect) AlignedCollides

func (r Rect) AlignedCollides(r2 Rect) bool

AlignedCollides checks for collision between two Rects, that are aligned (i.e. neither of them rotated)

func (Rect) CollidesWithCircle added in v0.1.3

func (r Rect) CollidesWithCircle(c Circle) bool

CollidesWithCircle checks a rectangle and a circle for collision

type Rectangler

type Rectangler interface {
	Rect() Rect
}

Rectangler is an interface that provides a Rect

Jump to

Keyboard shortcuts

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