r1 package - github.com/golang/geo/r1 - Go Packages (original) (raw)

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 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() Interval

EmptyInterval returns an empty interval.

IntervalFromPoint returns an interval representing a single point.

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

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.

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

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

Contains returns true iff the interval contains p.

func (i Interval) ContainsInterval(oi Interval) bool

ContainsInterval returns true iff the interval contains oi.

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).

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

func (Interval) Expanded

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.

InteriorContains returns true iff the interval strictly contains p.

func (i Interval) InteriorContainsInterval(oi Interval) bool

InteriorContainsInterval returns true iff the interval strictly contains oi.

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 (i Interval) Intersection(j Interval) Interval

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

func (i Interval) Intersects(oi Interval) bool

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

func (i Interval) IsEmpty() bool

IsEmpty reports whether the interval is empty.

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

func (i Interval) Union(other Interval) Interval

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