Documentation ¶
Overview ¶
Package segmentpb contains utilities for working with traits.ElectricMode_Segment values.
Index ¶
- func ActiveAt(d time.Duration, segments ...*traits.ElectricMode_Segment) (elapsed time.Duration, index int)
- func Cut(d time.Duration, segment *traits.ElectricMode_Segment) (before, after *traits.ElectricMode_Segment, outside bool)
- func Duration(s ...*traits.ElectricMode_Segment) (total time.Duration, infinite bool)
- func MagnitudeAt(d time.Duration, segments ...*traits.ElectricMode_Segment) (level float32, ok bool)
- func Max(segments ...*traits.ElectricMode_Segment) (index int)
- func MaxAfter(d time.Duration, segments ...*traits.ElectricMode_Segment) (index int)
- func MaxMagnitude(segments ...*traits.ElectricMode_Segment) (max float32)
- func Shift(d time.Duration, segments ...*traits.ElectricMode_Segment) []*traits.ElectricMode_Segment
- func Sum(segmentSlices ...[]*traits.ElectricMode_Segment) []*traits.ElectricMode_Segment
- func SumMagnitude(segments ...*traits.ElectricMode_Segment) (sum float32)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActiveAt ¶
func ActiveAt(d time.Duration, segments ...*traits.ElectricMode_Segment) (elapsed time.Duration, index int)
ActiveAt finds the active segment at time d. The index of the active segment in segments is returned along with the elapsed time before that segment started. If segments is empty, (0,0) is returned. If d<0, (d,0) is returned. If d is after all segments, the total length of the segments is returned as elapsed, and len(segments) as index.
func Cut ¶
func Cut(d time.Duration, segment *traits.ElectricMode_Segment) (before, after *traits.ElectricMode_Segment, outside bool)
Cut divides a segment in two along d. Cutting an infinite segment results in the same infinite segment for both before and after. If d is negative, `nil, segment` is returned.
func Duration ¶
func Duration(s ...*traits.ElectricMode_Segment) (total time.Duration, infinite bool)
Duration returns the total duration for all the given segments. If a segment is found without a length, the total up to that point and true will be returned.
func MagnitudeAt ¶
func MagnitudeAt(d time.Duration, segments ...*traits.ElectricMode_Segment) (level float32, ok bool)
MagnitudeAt returns the magnitude of the segment active at d. If there is no segment at d, ok will be false.
func Max ¶
func Max(segments ...*traits.ElectricMode_Segment) (index int)
Max returns the index of the segment with the largest magnitude of all non-zero length segments. If segments is empty, or contains only zero length segments, len(segments) is returned.
func MaxAfter ¶
func MaxAfter(d time.Duration, segments ...*traits.ElectricMode_Segment) (index int)
MaxAfter returns the index of the segment with the largest magnitude of all non-zero length segments after d time. If segments is empty, or contains only zero length segments, len(segments) is returned.
func MaxMagnitude ¶
func MaxMagnitude(segments ...*traits.ElectricMode_Segment) (max float32)
MaxMagnitude returns the largest segment magnitude of all non-zero length segments. If segments is empty or contains only zero-length segments, returns 0.
func Shift ¶
func Shift(d time.Duration, segments ...*traits.ElectricMode_Segment) []*traits.ElectricMode_Segment
Shift adjusts the offset of the given segments by d. If d is positive, this is the equivalent of inserting a new 0-magnitude segment of length d to the start. If d is negative, this removes segments until d length has been removed. This will cut the first returned segment if d falls within the length of that segment.
func Sum ¶
func Sum(segmentSlices ...[]*traits.ElectricMode_Segment) []*traits.ElectricMode_Segment
Sum combines the segment lists given by segmentSlices together into a single segment list.
func SumMagnitude ¶
func SumMagnitude(segments ...*traits.ElectricMode_Segment) (sum float32)
SumMagnitude sums the magnitude of all the given segments.
Types ¶
This section is empty.