v0.0.0-...-6adc566 Latest Latest

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 2 Imported by: 57



Package r1 implements types and functions for working with geometry in ℝ¹.

See ../s2 for a more detailed overview.



This section is empty.


This section is empty.


This section is empty.


type Interval

type Interval struct {
	Lo, Hi float64

Interval represents a closed interval on ℝ. Zero-length intervals (where Lo == Hi) represent single points. If Lo > Hi then the interval is empty.

func EmptyInterval

func EmptyInterval() Interval

EmptyInterval returns an empty interval.

func IntervalFromPoint

func IntervalFromPoint(p float64) Interval

IntervalFromPoint returns an interval representing a single point.

func (Interval) AddPoint

func (i Interval) AddPoint(p float64) Interval

AddPoint returns the interval expanded so that it contains the given point.

func (Interval) ApproxEqual

func (i Interval) ApproxEqual(other Interval) bool

ApproxEqual reports whether the interval can be transformed into the given interval by moving each endpoint a small distance. The empty interval is considered to be positioned arbitrarily on the real line, so any interval with a small enough length will match the empty interval.

func (Interval) Center

func (i Interval) Center() float64

Center returns the midpoint of the interval. It is undefined for empty intervals.

func (Interval) ClampPoint

func (i Interval) ClampPoint(p float64) float64

ClampPoint returns the closest point in the interval to the given point "p". The interval must be non-empty.

func (Interval) Contains

func (i Interval) Contains(p float64) bool

Contains returns true iff the interval contains p.

func (Interval) ContainsInterval

func (i Interval) ContainsInterval(oi Interval) bool

ContainsInterval returns true iff the interval contains oi.

func (Interval) DirectedHausdorffDistance

func (i Interval) DirectedHausdorffDistance(other Interval) float64

DirectedHausdorffDistance returns the Hausdorff distance to the given interval. For two intervals x and y, this distance is defined as

h(x, y) = max_{p in x} min_{q in y} d(p, q).

func (Interval) Equal

func (i Interval) Equal(oi Interval) bool

Equal returns true iff the interval contains the same points as oi.

func (Interval) Expanded

func (i Interval) Expanded(margin float64) Interval

Expanded returns an interval that has been expanded on each side by margin. If margin is negative, then the function shrinks the interval on each side by margin instead. The resulting interval may be empty. Any expansion of an empty interval remains empty.

func (Interval) InteriorContains

func (i Interval) InteriorContains(p float64) bool

InteriorContains returns true iff the interval strictly contains p.

func (Interval) InteriorContainsInterval

func (i Interval) InteriorContainsInterval(oi Interval) bool

InteriorContainsInterval returns true iff the interval strictly contains oi.

func (Interval) InteriorIntersects

func (i Interval) InteriorIntersects(oi Interval) bool

InteriorIntersects returns true iff the interior of the interval contains any points in common with oi, including the latter's boundary.

func (Interval) Intersection

func (i Interval) Intersection(j Interval) Interval

Intersection returns the interval containing all points common to i and j.

func (Interval) Intersects

func (i Interval) Intersects(oi Interval) bool

Intersects returns true iff the interval contains any points in common with oi.

func (Interval) IsEmpty

func (i Interval) IsEmpty() bool

IsEmpty reports whether the interval is empty.

func (Interval) Length

func (i Interval) Length() float64

Length returns the length of the interval. The length of an empty interval is negative.

func (Interval) String

func (i Interval) String() string

func (Interval) Union

func (i Interval) Union(other Interval) Interval

Union returns the smallest interval that contains this interval and the given interval.

Jump to

Keyboard shortcuts

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