Documentation ¶
Overview ¶
Package alg provides algorithms and math utilities.
Index ¶
- Constants
- func ChooseX(weights []float64, n int) []int
- func CumulativeWeights(weights []float64) []float64
- func F64eq(f1, f2 float64) bool
- func F64eqEps(f1, f2, epsilon float64) bool
- func RoundF64(a float64) int
- func TriangulateConvex(face []int) [][3]int
- func UniqueChooseX(weights []float64, n int) []int
- func UniqueChooseXSeeded(weights []float64, n int, rng Float64Generator) []int
- func WeightedChooseOne(cumulative []float64) int
- func WeightedChooseOneSeeded(cumulative []float64, rng Float64Generator) int
- func WeightedMapChoice(weightMap map[int]float64) int
- func WeightedMapChoiceSeeded(weightMap map[int]float64, rng Float64Generator) int
- type Degree
- type Float64Generator
- type Radian
Constants ¶
const ( // DegToRad is the constant value something in // degrees should be multiplied by to obtain // something in radians. DegToRad = math.Pi / 180 // RadToDeg is the constant value something in // radians should be multiplied by to obtain // something in degrees. RadToDeg = 180 / math.Pi )
Variables ¶
This section is empty.
Functions ¶
func ChooseX ¶
ChooseX - also known as Roulette Search. This returns n indices from the input weights at a count relative to the weight of each index. It can return the same index multiple times.
func CumulativeWeights ¶
CumulativeWeights converts a slice of weights into a slice of cumulative weights, where each index is the sum of all weights following that index in the original slice
func TriangulateConvex ¶
TriangulateConvex takes a face, in the form of a slice of indices, and outputs those indicies split into triangles based on the assumption that the face is convex. This involves forming pairs of indices and drawing an edge back to the first index repeatedly.
If given less than 3 indices, returns an empty slice.
Example input: [0,1,2,3,4] Example output: [[0,1,2][0,2,3][0,3,4]]
Visual Example:
____0____ 4 1 \ / 3-----2 - - - ____0____ 4 / \ 1 \ / \ / 3-----2
This makes additional assumptions that the points represented by the indices are coplanar, and that there are no holes present in the face.
func UniqueChooseX ¶
UniqueChooseX returns n indices from the input weights at a count relative to the weight of each index. This will never return duplicate indices. if n > len(weights), it will return -1 after depleting the n elements from weights.
func UniqueChooseXSeeded ¶
func UniqueChooseXSeeded(weights []float64, n int, rng Float64Generator) []int
UniqueChooseXSeeded returns n indices from the input weights at a count relative to the weight of each index. This will never return duplicate indices. if n > len(weights), it will return -1 after depleting the n elements from weights. If you do not want to use your own rand use UniqueChooseX.
func WeightedChooseOne ¶
WeightedChooseOne returns a single index from the weights given at a rate relative to the magnitude of each weight. It expects the input to be in the form of CumulativeWeights, cumulative with the total at index 0.
func WeightedChooseOneSeeded ¶
func WeightedChooseOneSeeded(cumulative []float64, rng Float64Generator) int
WeightedChooseOneSeeded returns a single index from the weights given at a rate relative to the magnitude of each weight. It expects the input to be in the form of CumulativeWeights, cumulative with the total at index 0. If you do not want to use your own rand use WeightedChooseOne.
func WeightedMapChoice ¶
WeightedMapChoice converts the input map into a set where keys are indices and values are weights for WeightedChooseOne, then returns the key for WeightedChooseOne of the weights.
func WeightedMapChoiceSeeded ¶
func WeightedMapChoiceSeeded(weightMap map[int]float64, rng Float64Generator) int
WeightedMapChoiceSeeded converts the input map into a set where keys are indices and values are weights for WeightedChooseOne, then returns the key for WeightedChooseOne of the weight. If you do not want to use your own rand use WeightedMapChoice.
Types ¶
type Float64Generator ¶
type Float64Generator interface {
Float64() float64
}
A Float64Generator must be able to generate a float64. This is generally used to implement randomness See rand.Float64 for an example
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package floatgeom provides primitives for floating point geometry.
|
Package floatgeom provides primitives for floating point geometry. |
Package intgeom provides primitives for integer geometry.
|
Package intgeom provides primitives for integer geometry. |
range
|
|
colorrange
Package colorrange provides distributions that accept and return color.Colors.
|
Package colorrange provides distributions that accept and return color.Colors. |
floatrange
Package floatrange provides distributions that accept and return float64s.
|
Package floatrange provides distributions that accept and return float64s. |
intrange
Package intrange provides distributions that return ints.
|
Package intrange provides distributions that return ints. |