span

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package span provides helper constructs to represent ranges of values, to poll from or clamp to

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Span

type Span[T any] interface {
	// Poll returns a pseudorandom value within this span.
	Poll() T
	// Clamp, if v lies within the boundary of this span, returns v.
	// Otherwise, CLamp returns a modified version of v that is rounded to the closest value
	// that does lie within the boundary of this span.
	Clamp(v T) T
	// Percentile returns the value along this span that is at the provided percentile through the span,
	// e.g. providing .5 will return the middle of the span, providing 1 will return the maximum value in
	// the span. Providing a value less than 0 or greater than 1 may extend the span by where it would theoretically
	// progress, but should not be relied upon unless a given implementation specifies what it will do. If this span
	// represents multiple degrees of freedom, this will pin all those degrees to the single provided percent.
	Percentile(float64) T
	// MulSpan returns this span with its entire range multiplied by the given constant.
	MulSpan(float64) Span[T]
}

A Span represents some enumerable range.

func NewConstant

func NewConstant[T Spanable](i T) Span[T]

NewConstant returns a span where the minimum and maximum are both i. Poll, Percentile, and Clamp will always return i.

func NewLinear

func NewLinear[T Spanable](min, max T) Span[T]

NewLinear returns a linear span between min and max. The linearity implies that no point in the span is preferred, and Percentile will scale in a constant fashion from min to max.

func NewLinearColor

func NewLinearColor(minColor, maxColor color.Color) Span[color.Color]

NewLinearColor returns a linear color distribution between min and maxColor

func NewSpread

func NewSpread[T Spanable](base, spread T) Span[T]

NewSpread returns a linear span from base-spread to base+spread.

type Spanable

type Spanable interface {
	constraints.Float | constraints.Integer
}

A Spanable must be usable in basic arithmetic-- addition, subtraction, and multiplication.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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