Skip to content
tiny linear interpolation library for go (factored out from https://github.com/sgreben/yeetgif)
Branch: master
Clone or download
Latest commit afc114d Nov 14, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Initial commit Oct 21, 2018
LICENSE Create LICENSE Oct 21, 2018
README.md
piecewiselinear.go Fix AreaUpTo Nov 14, 2018
piecewiselinear_test.go Fix AreaUpTo Nov 14, 2018
span.go Fix span Oct 21, 2018

README.md

piecewiselinear

cover.run Build Status

A tiny library for linear interpolation. O(log(N)) per evaluation for N control points.

import "github.com/sgreben/piecewiselinear"

Get it

go get -u "github.com/sgreben/piecewiselinear"

Use it

import "github.com/sgreben/piecewiselinear"

func main() {
    f := piecewiselinear.Function{Y:[]float64{0,1,0}} // range: "hat" function
    f.X = piecewiselinear.Span(0, 1, len(f.Y)) // domain: equidistant points along X axis
    fmt.Println(
		f.At(0), // f.At(x) evaluates f at x
		f.At(0.25),
		f.At(0.5),
		f.At(0.75),
		f.At(1.0),
		f.At(123.0),  // outside its domain X the function is constant 0
		f.At(-123.0), //
	)
    // Output:
    // 0 0.5 1 0.5 0 0 0
}
You can’t perform that action at this time.