Documentation ¶
Overview ¶
Package conversions provides Gadgets that offer some form of data conversion process
Index ¶
- func RoundPrec(x float64, prec int) float64
- type RangeMap
- type RangeMapData
- func (r *RangeMapData) Map(v int64) (int64, bool)
- func (r *RangeMapData) MustMap(v int64) int64
- func (r *RangeMapData) SetFromHi(v int64) bool
- func (r *RangeMapData) SetFromLow(v int64) bool
- func (r *RangeMapData) SetToHi(v int64) bool
- func (r *RangeMapData) SetToLow(v int64) bool
- func (r *RangeMapData) Valid() bool
- type RangeMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RangeMap ¶
type RangeMap interface { Map(int64) int64 SetToLow(int64) bool SetToHi(int64) bool SetFromLow(int64) bool SetFromHi(int64) bool }
TODO: move this out to a generic package and call back in.
type RangeMapData ¶
type RangeMapData struct {
// contains filtered or unexported fields
}
func NewRangeMap ¶
func NewRangeMap() *RangeMapData
NewRangeMap creates a RangeMap that must be provided a From/To range later otherwise its not valid
func NewRangeMapFrom ¶
func NewRangeMapFrom(fromLo, fromHi, toLo, toHi int64) *RangeMapData
NewRangeMapFrom creates a RangeMap with the From/To values provided
func (*RangeMapData) Map ¶
func (r *RangeMapData) Map(v int64) (int64, bool)
Map will transform the input (between fromLow, fromHi) to a value within the range (toLow, toHi) using this simple formula: = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; input is converted to float64 before calculations and the result is rounded back down to fit an int64 output, where 1.51 = 2 and 1.49=1 output is capped to stay within output range this is a generalised function for *MY* wide use-cases, there are many ways to get specific results faster and more efficiently
func (*RangeMapData) MustMap ¶
func (r *RangeMapData) MustMap(v int64) int64
MustMap will panic if the Map function returns false, otherwise it silently returns Map value.
func (*RangeMapData) SetFromHi ¶
func (r *RangeMapData) SetFromHi(v int64) bool
func (*RangeMapData) SetFromLow ¶
func (r *RangeMapData) SetFromLow(v int64) bool
func (*RangeMapData) SetToHi ¶
func (r *RangeMapData) SetToHi(v int64) bool
func (*RangeMapData) SetToLow ¶
func (r *RangeMapData) SetToLow(v int64) bool
func (*RangeMapData) Valid ¶
func (r *RangeMapData) Valid() bool