conversions

package
v0.0.0-...-8969683 Latest Latest
Warning

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

Go to latest
Published: May 16, 2014 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package conversions provides Gadgets that offer some form of data conversion process

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RoundPrec

func RoundPrec(x float64, prec int) float64

generic Precision rounding of float64 (go-lang-nuts discussion)

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

type RangeMapper

type RangeMapper struct {
	flow.Gadget
	Param flow.Input
	In    flow.Input
	Out   flow.Output
}

RangeMapper helps to convert an input value to an equivalent output value within a set scale

func (*RangeMapper) Run

func (g *RangeMapper) Run()

Gadget loop

Jump to

Keyboard shortcuts

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