interval

package
v0.0.0-...-8609aed Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: CC0-1.0, MIT-0 Imports: 1 Imported by: 0

README

Package interval

import "gitlab.com/fospathi/universal/interval"

Go package interval contains primitives for working with basic numeric intervals.

Development status

Package interval is unstable; expect breaking changes with every commit.

Documentation

Overview

Package interval contains primitives for working with basic numeric intervals.

Index

Constants

This section is empty.

Variables

View Source
var PiIn = In{-math.Pi, math.Pi}

PiIn is an interval from -Pi to +Pi.

Functions

This section is empty.

Types

type In

type In [2]float64

In represents a directed interval on the real line from the first element to the second element.

func (In) AbsLen

func (in1 In) AbsLen() float64

AbsLen is the length of the interval's domain.

func (In) AsClosedContains

func (in1 In) AsClosedContains(v float64) bool

AsClosedContains reports whether the closed interval contains the argument value.

func (In) AsOpenContains

func (in1 In) AsOpenContains(v float64) bool

AsOpenContains reports whether the open interval contains the argument value.

func (In) AsOpenIntersection

func (in1 In) AsOpenIntersection(in2 In) (In, bool)

AsOpenIntersection reports whether two non-zero length open intervals overlap and in the affirmative case returns the intersection of the intervals.

The returned intersection, if it exists, has the same direction as the receiver interval.

Returns false if there is no intersection.

func (In) Clamp

func (in1 In) Clamp(v float64) float64

Clamp the given value to the interval's domain.

func (In) ClampedT

func (in1 In) ClampedT(t float64) float64

ClampedT is the interval value at the argument proportion, in the range 0..1, of the interval domain.

A t of 0 or less returns the interval's first element. A t of 1 or greater returns the interval's second element.

func (In) ContractLimits

func (in1 In) ContractLimits(d float64) In

ContractLimits returns an interval with the same midpoint but with each of the interval limits moved closer to the midpoint by the given distance.

If the interval's length is less than or equals twice the given distance then the returned interval is a zero length interval.

func (In) Midpoint

func (in1 In) Midpoint() float64

Midpoint of the interval.

func (In) MinMax

func (in1 In) MinMax() (float64, float64)

MinMax interval limits.

func (In) Opposite

func (in1 In) Opposite() In

Opposite direction interval to the receiver with the same domain.

func (In) Split

func (in1 In) Split(n int) []In

Split the interval into argument almost equally sized sub intervals.

The sub intervals are in the same direction as the receiver interval.

If the interval has zero length, the return value is nil.

func (In) T

func (in1 In) T(t float64) float64

T is the interval value at the argument proportion, usually in the range 0..1, of the interval domain.

func (In) TAtX

func (in1 In) TAtX(x float64) float64

TAtX is the proportion of the interval width (t) for the given value in the interval domain.

func (In) TSub

func (in1 In) TSub(t In) In

TSub is the subinterval between the argument proportions such that 0 in the argument interval corresponds to the receiver's first element and 1 corresponds to the second element.

type Pi

type Pi [2]float64

Pi is a trig angle interval anticlockwise from the first to the second angle element, measured in radians, with values not greater than Pi in magnitude.

Numerically speaking the interval is not necessarily continuous. Usually when the start is greater than the finish then there is a discontinuity in the interval at Pi. Abstractly speaking the interval is always continuous.

The angle should be less than two Pi radians except in the case -Pi to Pi which is the canonical way to represent a complete revolution.

Two equal interval limits represent an interval whose angle is zero.

func NewPi

func NewPi(from, to float64) Pi

NewPi returns a new Pi trig interval using the argument angles, measured in radians.

The argument values are clamped to the range -Pi <= angle <= Pi.

func (Pi) Angle

func (in Pi) Angle() float64

Angle is the magnitude of the anticlockwise angle covered by the receiver trig interval.

func (Pi) AsClosedContains

func (in Pi) AsClosedContains(v float64) bool

AsClosedContains returns whether the argument angle value, measured in radians, is contained in the closed receiver interval.

The special cases are:

* when the receiver's angle value is zero, such that the receiver interval is empty, false is always returned.

func (Pi) Complement

func (in Pi) Complement() Pi

Complement returns the other part of the possible interval space that is not occupied by the receiver interval.

The special cases are:

* if the receiver interval has an angle of zero then the returned complement is the canonical full revolution representation of -Pi to Pi.

* if the receiver interval has an angle of exactly two Pi then the returned complement is an empty revolution representation of 0 to 0.

func (Pi) Containing

func (in Pi) Containing(a float64) Pi

Containing returns a pi trig interval with the same limits as the receiver containing the argument angle which shall be measured in radians and in the range -Pi to Pi.

The argument angle shall not coincide with an interval limit.

func (Pi) Interval

func (in Pi) Interval() In

Interval returns the interval that is equivalent to the receiver trig interval.

Interval prefers to return an interval whose limits are in the range -Pi to Pi but when this isn't possible the returned interval's endpoint can be greater than Pi.

func (Pi) Intervals

func (in Pi) Intervals() []In

Intervals returns the intervals, where each one is numerically continuous, that together are equivalent to the receiver trig interval.

The returned intervals are in the range -Pi to Pi.

func (Pi) IsContinuous

func (in Pi) IsContinuous() bool

IsContinuous returns whether the receiver trig interval can be represented as a single continuous interval in the range -Pi to Pi.

func (Pi) NotContaining

func (in Pi) NotContaining(a float64) Pi

NotContaining returns a pi trig interval with the same limits as the receiver which does not contain the argument angle which shall be measured in radians and in the range -Pi to Pi.

The argument angle shall not coincide with an interval limit.

Jump to

Keyboard shortcuts

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