math

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 8 Imported by: 0

README

Math

Primitive math utilities to be used by the remaining of the library. Math imports nothing, everything else imports it. There is a slight hierarchy to the sub-packages found in math.

Sample

Sample serves as a group of definitions for defining a mapping from one numeric value to another. Another term for this is "function" or "mapping" but golang already took both of those keywords so I settled on "sample". Code throughout polyform uses the definitions like sample.FloatToVec2 to indicate this method maps a float to a Vector 2 value.

There are also some general utility functions for building common mappings between two domains of numbers.

  • Compose - Takes an array of sample functions and feeds the output value from one function into the input value to the next function before finally returning the final value.
    • ComposeFloat
    • ComposeVec2
    • ComposeVec3
  • LinearMapping - Remaps some float value between A and B to sample a line in N-Dimensional space linearly.
    • LinearFloatMapping
    • LinearVector2Mapping
    • LinearVector3Mapping
  • Trig
    • Sin - Maps a float value to a sin wave with some specified amplitude and frequency.
    • Cos - Maps a float value to a sin wave with some specified amplitude and frequency.

Curves

Curves builds off of the sample package. The one restriction it makes is that the input domain is restricted to float values between 0 and 1. This is where more common animation curves reside.

Noise

Different noise algorithms commonly used in procedural generation.

SDF

SDF implementations of different geometry primitives, along with common math functions. Basically slowly picking through Inigo Quilez's Distfunction article as I need them in my different projects.

TRS

Math around Translation / Rotation / Scale Matrices

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddNode added in v0.23.0

type AddNode[T vector.Number] struct {
	Values []nodes.Output[T] `description:"The nodes to sum"`
}

func (AddNode[T]) Float added in v0.32.2

func (an AddNode[T]) Float(out *nodes.StructOutput[float64])

func (AddNode[T]) Int added in v0.32.2

func (an AddNode[T]) Int(out *nodes.StructOutput[int])

type AddToArrayNode added in v0.32.0

type AddToArrayNode[T vector.Number] struct {
	In    nodes.Output[T]
	Array nodes.Output[[]T]
}

func (AddToArrayNode[T]) Sums added in v0.32.2

func (cn AddToArrayNode[T]) Sums(out *nodes.StructOutput[[]T])

type CircumferenceNode added in v0.27.1

type CircumferenceNode struct {
	Radius nodes.Output[float64]
}

func (CircumferenceNode) Description added in v0.27.1

func (cn CircumferenceNode) Description() string

func (CircumferenceNode) Float added in v0.27.1

func (cn CircumferenceNode) Float(out *nodes.StructOutput[float64])

func (CircumferenceNode) Int added in v0.27.1

func (cn CircumferenceNode) Int(out *nodes.StructOutput[int])

type DivideNode

type DivideNode[T vector.Number] struct {
	Dividend nodes.Output[T] `description:"the number being divided"`
	Divisor  nodes.Output[T] `description:"number doing the dividing"`
}

func (DivideNode[T]) Description added in v0.32.0

func (DivideNode[T]) Description() string

func (DivideNode[T]) Float added in v0.32.2

func (an DivideNode[T]) Float(out *nodes.StructOutput[float64])

func (DivideNode[T]) Int added in v0.32.2

func (an DivideNode[T]) Int(out *nodes.StructOutput[int])

type DivideToArrayNode added in v0.32.0

type DivideToArrayNode[T vector.Number] struct {
	In    nodes.Output[T]
	Array nodes.Output[[]T]
}

func (DivideToArrayNode[T]) Quotients added in v0.32.2

func (cn DivideToArrayNode[T]) Quotients(out *nodes.StructOutput[[]T])

type DoubleNode added in v0.25.0

type DoubleNode[T vector.Number] struct {
	In nodes.Output[T] `description:"The number to double"`
}

func (DoubleNode[T]) Description added in v0.25.0

func (cn DoubleNode[T]) Description() string

func (DoubleNode[T]) Float64 added in v0.25.0

func (cn DoubleNode[T]) Float64(out *nodes.StructOutput[float64])

func (DoubleNode[T]) Int added in v0.25.0

func (cn DoubleNode[T]) Int(out *nodes.StructOutput[int])

type HalfNode added in v0.25.0

type HalfNode[T vector.Number] struct {
	In nodes.Output[T] `description:"The number to halve"`
}

func (HalfNode[T]) Description added in v0.25.0

func (cn HalfNode[T]) Description() string

func (HalfNode[T]) Float64 added in v0.25.0

func (cn HalfNode[T]) Float64(out *nodes.StructOutput[float64])

func (HalfNode[T]) Int added in v0.25.0

func (cn HalfNode[T]) Int(out *nodes.StructOutput[int])

type HypotenuseNode added in v0.30.0

type HypotenuseNode struct {
	P nodes.Output[float64]
	Q nodes.Output[float64]
}

func (HypotenuseNode) Out added in v0.30.0

func (cn HypotenuseNode) Out(out *nodes.StructOutput[float64])

type IntToFloatNode added in v0.28.0

type IntToFloatNode struct {
	In nodes.Output[int]
}

func (IntToFloatNode) Out added in v0.28.0

func (cn IntToFloatNode) Out(out *nodes.StructOutput[float64])

type InverseNode added in v0.32.0

type InverseNode[T vector.Number] struct {
	In nodes.Output[T] `description:"The number to take the inverse of"`
}

============================================================================

func (InverseNode[T]) Additive added in v0.32.0

func (cn InverseNode[T]) Additive(out *nodes.StructOutput[T])

func (InverseNode[T]) AdditiveDescription added in v0.32.0

func (cn InverseNode[T]) AdditiveDescription() string

func (InverseNode[T]) Multiplicative added in v0.32.0

func (cn InverseNode[T]) Multiplicative(out *nodes.StructOutput[T])

func (InverseNode[T]) MultiplicativeDescription added in v0.32.0

func (cn InverseNode[T]) MultiplicativeDescription() string

type MaxArrayNode added in v0.27.0

type MaxArrayNode[T vector.Number] struct {
	In nodes.Output[[]T]
}

func (MaxArrayNode[T]) Float64 added in v0.27.0

func (n MaxArrayNode[T]) Float64(out *nodes.StructOutput[float64])

func (MaxArrayNode[T]) Int added in v0.27.0

func (n MaxArrayNode[T]) Int(out *nodes.StructOutput[int])

type MaxNode added in v0.27.0

type MaxNode[T vector.Number] struct {
	In []nodes.Output[T]
}

func (MaxNode[T]) Float64 added in v0.27.0

func (n MaxNode[T]) Float64(out *nodes.StructOutput[float64])

func (MaxNode[T]) Int added in v0.27.0

func (n MaxNode[T]) Int(out *nodes.StructOutput[int])

type MinArrayNode added in v0.27.0

type MinArrayNode[T vector.Number] struct {
	In nodes.Output[[]T]
}

func (MinArrayNode[T]) Float64 added in v0.27.0

func (n MinArrayNode[T]) Float64(out *nodes.StructOutput[float64])

func (MinArrayNode[T]) Int added in v0.27.0

func (n MinArrayNode[T]) Int(out *nodes.StructOutput[int])

type MinNode added in v0.27.0

type MinNode[T vector.Number] struct {
	In []nodes.Output[T]
}

func (MinNode[T]) Float64 added in v0.27.0

func (n MinNode[T]) Float64(out *nodes.StructOutput[float64])

func (MinNode[T]) Int added in v0.27.0

func (n MinNode[T]) Int(out *nodes.StructOutput[int])

type MultiplyNode added in v0.32.0

type MultiplyNode[T vector.Number] struct {
	Values []nodes.Output[T]
}

func (MultiplyNode[T]) Float added in v0.32.2

func (an MultiplyNode[T]) Float(out *nodes.StructOutput[float64])

func (MultiplyNode[T]) Int added in v0.32.2

func (an MultiplyNode[T]) Int(out *nodes.StructOutput[int])

type MultiplyToArrayNode added in v0.32.0

type MultiplyToArrayNode[T vector.Number] struct {
	In    nodes.Output[T]
	Array nodes.Output[[]T]
}

func (MultiplyToArrayNode[T]) Products added in v0.32.2

func (cn MultiplyToArrayNode[T]) Products(out *nodes.StructOutput[[]T])

type NegateNode added in v0.25.0

type NegateNode[T vector.Number] struct {
	In nodes.Output[T] `description:"The number to take the additive inverse of"`
}

func (NegateNode[T]) Description added in v0.25.0

func (cn NegateNode[T]) Description() string

func (NegateNode[T]) Out added in v0.25.0

func (cn NegateNode[T]) Out(out *nodes.StructOutput[T])

type OneNode added in v0.25.0

type OneNode struct{}

func (OneNode) Description added in v0.25.0

func (cn OneNode) Description() string

func (OneNode) Float64 added in v0.25.0

func (cn OneNode) Float64(out *nodes.StructOutput[float64])

func (OneNode) Int added in v0.25.0

func (cn OneNode) Int(out *nodes.StructOutput[int])

type PlaneFromNormalNode added in v0.30.0

type PlaneFromNormalNode struct {
	Normal   nodes.Output[vector3.Float64]
	Position nodes.Output[vector3.Float64]
}

func (PlaneFromNormalNode) Out added in v0.30.0

type RemapNode added in v0.30.0

type RemapNode[T vector.Number] struct {
	Value nodes.Output[T]

	InMin nodes.Output[T]
	InMax nodes.Output[T]

	OutMin nodes.Output[T]
	OutMax nodes.Output[T]
}

func (RemapNode[T]) Out added in v0.30.0

func (n RemapNode[T]) Out(out *nodes.StructOutput[T])

type RemapToArrayNode added in v0.30.0

type RemapToArrayNode[T vector.Number] struct {
	Value nodes.Output[[]T]

	InMin nodes.Output[T]
	InMax nodes.Output[T]

	OutMin nodes.Output[T]
	OutMax nodes.Output[T]

	Clamp nodes.Output[bool]
}

func (RemapToArrayNode[T]) Out added in v0.30.0

func (n RemapToArrayNode[T]) Out(out *nodes.StructOutput[[]T])

type RoundNode added in v0.32.0

type RoundNode struct {
	In nodes.Output[float64]
}

func (RoundNode) Float added in v0.32.0

func (cn RoundNode) Float(out *nodes.StructOutput[float64])

func (RoundNode) Int added in v0.32.0

func (cn RoundNode) Int(out *nodes.StructOutput[int])

type SquareNode added in v0.30.0

type SquareNode struct {
	In nodes.Output[float64]
}

============================================================================

func (SquareNode) Out added in v0.30.0

func (cn SquareNode) Out(out *nodes.StructOutput[float64])

type SquareRootNode added in v0.30.0

type SquareRootNode struct {
	In nodes.Output[float64]
}

func (SquareRootNode) Out added in v0.30.0

func (cn SquareRootNode) Out(out *nodes.StructOutput[float64])

type SubtractNode added in v0.32.2

type SubtractNode[T vector.Number] struct {
	A nodes.Output[T]
	B nodes.Output[T]
}

func (SubtractNode[T]) Float added in v0.32.2

func (an SubtractNode[T]) Float(out *nodes.StructOutput[float64])

func (SubtractNode[T]) Int added in v0.32.2

func (an SubtractNode[T]) Int(out *nodes.StructOutput[int])

type SubtractToArrayNode added in v0.32.2

type SubtractToArrayNode[T vector.Number] struct {
	In    nodes.Output[T]
	Array nodes.Output[[]T]
}

func (SubtractToArrayNode[T]) Differences added in v0.32.2

func (cn SubtractToArrayNode[T]) Differences(out *nodes.StructOutput[[]T])

type ZeroNode added in v0.25.0

type ZeroNode struct{}

func (ZeroNode) Description added in v0.25.0

func (cn ZeroNode) Description() string

func (ZeroNode) Float64 added in v0.25.0

func (cn ZeroNode) Float64(out *nodes.StructOutput[float64])

func (ZeroNode) Int added in v0.25.0

func (cn ZeroNode) Int(out *nodes.StructOutput[int])

Jump to

Keyboard shortcuts

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