geom

package
v0.0.0-...-4142f2f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

The geom package provides basic geometry types and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Circle

type Circle struct {
	X float32
	Y float32
	R float32
}

func MakeCircle

func MakeCircle(x, y, r float32) Circle

func (Circle) ContainsPoint

func (c Circle) ContainsPoint(p Point) bool

func (Circle) Diameter

func (c Circle) Diameter() float32

func (Circle) HasOverlap

func (c Circle) HasOverlap(other Circle) bool

type Collision

type Collision struct {
	Point    Vector
	FarPoint Vector
	Normal   Vector
	TimeNear Vector
	TimeFar  Vector
	HitNear  float64
	HitFar   float64
}

type Cube

type Cube [8]Point3D

func MakeCube

func MakeCube(points [8]Point3D) Cube

func (*Cube) Centroid

func (c *Cube) Centroid() Point3D

func (Cube) GetVertices

func (c Cube) GetVertices() []float32

func (*Cube) Scale

func (c *Cube) Scale(factor float32)

func (*Cube) Translate

func (c *Cube) Translate(vector Vector3D)

type Line

type Line struct {
	Segment Segment
	// contains filtered or unexported fields
}

func MakeLine

func MakeLine(a, b Point) Line

func (Line) EvalX

func (l Line) EvalX(x float32) float32

func (Line) Intersection

func (l Line) Intersection(l2 Line) (Point, error)

func (Line) IsParrallel

func (l Line) IsParrallel(l1, l2 Line) bool

type Mesh

type Mesh struct {
	Vertices []float32
	Indices  []uint32
}

func NewMesh

func NewMesh(vertices []float32, indices []uint32) *Mesh

type Model

type Model struct {
	Meshes      []*Mesh
	Matrix      matrix.Matrix
	ScaleFactor float32
	Position    Vector3D
	Rotation    matrix.Matrix
}

func NewModel

func NewModel(mesh *Mesh) *Model

func (*Model) ApplyMatrix

func (m *Model) ApplyMatrix(matrix matrix.Matrix)

func (*Model) GetMeshes

func (m *Model) GetMeshes() []*Mesh

func (*Model) GetPosition

func (m *Model) GetPosition() Vector3D

func (*Model) GetRotation

func (m *Model) GetRotation() matrix.Matrix

func (*Model) GetScaleFactor

func (m *Model) GetScaleFactor() float32

func (*Model) Rotate

func (m *Model) Rotate(angle float32, axis Vector3D)

func (*Model) Scale

func (m *Model) Scale(factor float32)

func (*Model) SetPosition

func (m *Model) SetPosition(v Vector3D)

func (*Model) SetRotation

func (m *Model) SetRotation(v Vector3D)

func (*Model) Translate

func (m *Model) Translate(v Vector3D)

type Normal

type Normal struct{}

type Point

type Point struct {
	X float32
	Y float32
}

func MakePoint

func MakePoint(x, y float32) Point

func (Point) ToVector

func (p Point) ToVector() Vector

type Point3D

type Point3D struct {
	X, Y, Z float32
}

func MakePoint3D

func MakePoint3D(x, y, z float32) Point3D

func (Point3D) Add

func (p Point3D) Add(other Point3D) Point3D

func (Point3D) Cross

func (p Point3D) Cross(other Point3D) Point3D

func (Point3D) Magnitude

func (p Point3D) Magnitude() float32

func (Point3D) Normalize

func (p Point3D) Normalize() Point3D

func (Point3D) Subtract

func (p Point3D) Subtract(other Point3D) Point3D

func (Point3D) ToVector3D

func (p Point3D) ToVector3D() Vector3D

type Polygon

type Polygon []Point

func MakePolygon

func MakePolygon(points ...Point) Polygon

MakePolygon creates a new polygon from a slice of points.

func (*Polygon) AddPoint

func (p *Polygon) AddPoint(pt Point)

AddPoint appends a point to the end of the polygon.

func (Polygon) At

func (p Polygon) At(i int) Point

At returns the i-th point of the polygon.

func (Polygon) NumPoints

func (p Polygon) NumPoints() int

NumPoints returns the number of points in the polygon.

type Ray

type Ray struct {
	Origin    Vector
	Direction Vector
}

type Rect

type Rect [4]float32

Rect a float32 slice with 4 elements []float32{x, y, width, height}

func MakeRect

func MakeRect(x, y, width, height float32) Rect

func (Rect) ContainsPoint

func (r Rect) ContainsPoint(p Point) bool

func (Rect) Dimension

func (r Rect) Dimension(i int) float32

Dimension returns the value of the i-th dimension

func (Rect) Dimensions

func (r Rect) Dimensions() int

Dimensions returns the total number of dimensions

func (Rect) GetCenter

func (r Rect) GetCenter() (float32, float32)

func (Rect) GetOverlap

func (r Rect) GetOverlap(other Rect) (float32, float32)

func (Rect) HasRayIntersection

func (r Rect) HasRayIntersection(ray Ray, collision *Collision) bool

HasRayIntersection returns true if an intersection exists the collision argument will contain information about the collision

func (Rect) IsAxisAlignedCollision

func (r Rect) IsAxisAlignedCollision(other Rect) bool

type Segment

type Segment struct {
	V0 Vector
	V1 Vector
}

type Square

type Square [4]Point

func MakeSquare

func MakeSquare(points [4]Point) Square

func (*Square) Area

func (s *Square) Area() float32

func (*Square) Centroid

func (s *Square) Centroid() Point

func (*Square) Rotate

func (s *Square) Rotate(angle float64)

func (*Square) Scale

func (s *Square) Scale(factor float32)

func (*Square) Translate

func (s *Square) Translate(vector Vector)

type Texture

type Texture struct {
	ID uint32
}

type Triangle

type Triangle [3]Vector

func MakeTriangle

func MakeTriangle(vecs [3]Vector) Triangle

func (*Triangle) Centroid

func (t *Triangle) Centroid() Point

func (*Triangle) Rotate

func (t *Triangle) Rotate(angle float32)

type Vector

type Vector [2]float32

Vector a float32 slice with 2 elements [2]float32{x, y}

func MakeVector

func MakeVector(x, y float32) Vector

func (Vector) Add

func (v Vector) Add(other Vector) Vector

func (Vector) Divide

func (v Vector) Divide(other Vector) Vector

func (Vector) GetDirection

func (v Vector) GetDirection(b Vector) float32

func (Vector) GetDistance

func (v Vector) GetDistance(b Vector) float32

func (Vector) Multiply

func (v Vector) Multiply(other Vector) Vector

func (Vector) Offset

func (v Vector) Offset(o Vector) Vector

func (Vector) String

func (v Vector) String() string

func (Vector) Subtract

func (v Vector) Subtract(other Vector) Vector

func (Vector) ToPoint

func (v Vector) ToPoint() Point

type Vector3D

type Vector3D [3]float32

func MakeVector3D

func MakeVector3D(x, y, z float32) Vector3D

func (Vector3D) Add

func (v Vector3D) Add(other Vector3D) Vector3D

func (Vector3D) DistanceTo

func (v Vector3D) DistanceTo(other Vector3D) float32

func (Vector3D) Scaled

func (v Vector3D) Scaled(scalar float32) Vector3D

Scaled scales the vector by a scalar value.

func (Vector3D) Subtract

func (v Vector3D) Subtract(other Vector3D) Vector3D

func (Vector3D) ToPoint3D

func (v Vector3D) ToPoint3D() Point3D

Jump to

Keyboard shortcuts

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