geom

package module
v0.0.0-...-81cfd1f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 2 Imported by: 0

README

geom

Geometric functions for games and graphics with generics

Documentation

Index

Examples

Constants

View Source
const (
	Tau = math.Pi * 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Line2

type Line2[T intfloat] struct {
	X0, Y0, X1, Y1 T
}

type Rect

type Rect[T intfloat] struct {
	X0, Y0, X1, Y1 T
}
Example
package main

import (
	"fmt"

	"github.com/eihigh/geom"
)

func main() {
	r1 := geom.Recti{10, 10, 20, 20}
	r2 := geom.XYWHToRect(10, 10, 10, 10)
	r3 := geom.PosSizeToRect(geom.Vec2i{10, 10}, geom.Vec2i{10, 10})
	fmt.Println(r1.Eq(r2))
	fmt.Println(r1.Eq(r3))

}
Output:

true
true

func MinMaxToRect

func MinMaxToRect[T intfloat](min, max Vec2[T]) Rect[T]

func PosSizeToRect

func PosSizeToRect[T intfloat](pos, size Vec2[T]) Rect[T]

func XYWHToRect

func XYWHToRect[T intfloat](x, y, w, h T) Rect[T]

func (Rect[T]) Dx

func (r Rect[T]) Dx() T

func (Rect[T]) Dy

func (r Rect[T]) Dy() T

func (Rect[T]) Empty

func (r Rect[T]) Empty() bool

func (Rect[T]) Eq

func (r Rect[T]) Eq(other Rect[T]) bool

func (Rect[T]) Image

func (r Rect[T]) Image() image.Rectangle

func (Rect[T]) Max

func (r Rect[T]) Max() Vec2[T]

func (Rect[T]) Min

func (r Rect[T]) Min() Vec2[T]

func (Rect[T]) Size

func (r Rect[T]) Size() Vec2[T]

type Rectf

type Rectf = Rect[float64]

type Recti

type Recti = Rect[int]

type Vec2

type Vec2[T intfloat] struct {
	X, Y T
}

func (Vec2[T]) Add

func (v Vec2[T]) Add(other Vec2[T]) Vec2[T]

func (Vec2[T]) Angle

func (v Vec2[T]) Angle() float64

func (Vec2[T]) Complex128

func (v Vec2[T]) Complex128() complex128

func (Vec2[T]) Complex64

func (v Vec2[T]) Complex64() complex64

func (Vec2[T]) Eq

func (v Vec2[T]) Eq(other Vec2[T]) bool

func (Vec2[T]) Length

func (v Vec2[T]) Length() float64

func (Vec2[T]) LengthSq

func (v Vec2[T]) LengthSq() T

func (Vec2[T]) Polar

func (v Vec2[T]) Polar() (r, theta float64)

func (Vec2[T]) XY

func (v Vec2[T]) XY() (x, y T)

type Vec2f

type Vec2f = Vec2[float64]

func PolarToVec2

func PolarToVec2(r, theta float64) Vec2f

type Vec2i

type Vec2i = Vec2[int]

Jump to

Keyboard shortcuts

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