vector

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 0 Imported by: 20

README

Vector

Collection of generic, immutable vector math functions I've written overtime for different hobby projects.

Has support for both Vector2 (x, y) and Vector3 (x, y, z) functions.

Example

Below is an example on how to implement the sign distance field of a sphere in a generic fashion to work for both int, int64, float32, and float64.

package sdf

import (
	"github.com/EliCDavis/vector"
	"github.com/EliCDavis/vector/vector3"
)

type Field[T vector.Number] func(v vector3.Vector[T]) float64

func Sphere[T vector.Number](pos vector3.Vector[T], radius float64) Field[T] {
	return func(v vector3.Vector[T]) float64 {
		return v.Distance(pos) - radius
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

type Number interface {
	int64 | float64 | int | float32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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