Source File
envelope.go
Belonging Package
modernc.org/mathutil
// Copyright (c) 2014 The mathutil Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package mathutil // import "modernc.org/mathutil"import ()// Approximation type determines approximation methods used by e.g. Envelope.type Approximation int// Specific approximation method tagsconst (_ Approximation = iotaLinear // As namedSinusoidal // Smooth for all derivations)// Envelope is an utility for defining simple curves using a small (usually)// set of data points. Envelope returns a value defined by x, points and// approximation. The value of x must be in [0,1) otherwise the result is// undefined or the function may panic. Points are interpreted as dividing the// [0,1) interval in len(points)-1 sections, so len(points) must be > 1 or the// function may panic. According to the left and right points closing/adjacent// to the section the resulting value is interpolated using the chosen// approximation method. Unsupported values of approximation are silently// interpreted as 'Linear'.func ( float64, []float64, Approximation) float64 {:= 1 / float64(len()-1):= math.Floor( / ):= - *:= int(), := [], [+1]:= /switch {case Sinusoidal::= (math.Sin(math.Pi*(-0.5)) + 1) / 2return + (-)*case Linear:fallthroughdefault:return + (-)*}}
![]() |
The pages are generated with Golds v0.3.6. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |