math

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 5 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 DifferenceNodeData added in v0.23.0

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

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

func (DifferenceNodeData[T]) Out added in v0.23.0

func (cn DifferenceNodeData[T]) Out() nodes.StructOutput[T]

type DivideNodeData added in v0.23.0

type DivideNodeData[T vector.Number] struct {
	Dividend nodes.Output[T]
	Divisor  nodes.Output[T]
}

func (DivideNodeData[T]) Description added in v0.23.0

func (DivideNodeData[T]) Description() string

func (DivideNodeData[T]) Out added in v0.23.0

func (cn DivideNodeData[T]) 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() nodes.StructOutput[float64]

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

func (cn DoubleNode[T]) Int() 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() nodes.StructOutput[float64]

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

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

type InverseNodeData added in v0.25.0

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

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

func (InverseNodeData[T]) Additive added in v0.25.0

func (cn InverseNodeData[T]) Additive() nodes.StructOutput[T]

func (InverseNodeData[T]) AdditiveDescription added in v0.25.0

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

func (InverseNodeData[T]) Multiplicative added in v0.25.0

func (cn InverseNodeData[T]) Multiplicative() nodes.StructOutput[T]

func (InverseNodeData[T]) MultiplicativeDescription added in v0.25.0

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

type MultiplyNodeData added in v0.23.0

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

func (MultiplyNodeData[T]) Out added in v0.23.0

func (cn MultiplyNodeData[T]) 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() 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() nodes.StructOutput[float64]

func (OneNode) Int added in v0.25.0

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

type Round

type Round = nodes.Struct[RoundNodeData]

type RoundNodeData added in v0.23.0

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

func (RoundNodeData) Float added in v0.23.0

func (RoundNodeData) Int added in v0.23.0

func (cn RoundNodeData) Int() nodes.StructOutput[int]

type SumNodeData added in v0.23.0

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

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

func (SumNodeData[T]) Out added in v0.23.0

func (cn SumNodeData[T]) 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() nodes.StructOutput[float64]

func (ZeroNode) Int added in v0.25.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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