geo: github.com/golang/geo/r2 Index | Files

package r2

import "github.com/golang/geo/r2"

Package r2 implements types and functions for working with geometry in ℝ².

See package s2 for a more detailed overview.

Index

Package Files

doc.go rect.go

type Point Uses

type Point struct {
    X, Y float64
}

Point represents a point in ℝ².

func (Point) Add Uses

func (p Point) Add(op Point) Point

Add returns the sum of p and op.

func (Point) Cross Uses

func (p Point) Cross(op Point) float64

Cross returns the cross product of p and op.

func (Point) Dot Uses

func (p Point) Dot(op Point) float64

Dot returns the dot product between p and op.

func (Point) Mul Uses

func (p Point) Mul(m float64) Point

Mul returns the scalar product of p and m.

func (Point) Norm Uses

func (p Point) Norm() float64

Norm returns the vector's norm.

func (Point) Normalize Uses

func (p Point) Normalize() Point

Normalize returns a unit point in the same direction as p.

func (Point) Ortho Uses

func (p Point) Ortho() Point

Ortho returns a counterclockwise orthogonal point with the same norm.

func (Point) String Uses

func (p Point) String() string

func (Point) Sub Uses

func (p Point) Sub(op Point) Point

Sub returns the difference of p and op.

type Rect Uses

type Rect struct {
    X, Y r1.Interval
}

Rect represents a closed axis-aligned rectangle in the (x,y) plane.

func EmptyRect Uses

func EmptyRect() Rect

EmptyRect constructs the canonical empty rectangle. Use IsEmpty() to test for empty rectangles, since they have more than one representation. A Rect{} is not the same as the EmptyRect.

func RectFromCenterSize Uses

func RectFromCenterSize(center, size Point) Rect

RectFromCenterSize constructs a rectangle with the given center and size. Both dimensions of size must be non-negative.

func RectFromPoints Uses

func RectFromPoints(pts ...Point) Rect

RectFromPoints constructs a rect that contains the given points.

func (Rect) AddPoint Uses

func (r Rect) AddPoint(p Point) Rect

AddPoint expands the rectangle to include the given point. The rectangle is expanded by the minimum amount possible.

func (Rect) AddRect Uses

func (r Rect) AddRect(other Rect) Rect

AddRect expands the rectangle to include the given rectangle. This is the same as replacing the rectangle by the union of the two rectangles, but is more efficient.

func (Rect) ApproxEquals Uses

func (r Rect) ApproxEquals(r2 Rect) bool

ApproxEquals returns true if the x- and y-intervals of the two rectangles are the same up to the given tolerance.

func (Rect) Center Uses

func (r Rect) Center() Point

Center returns the center of the rectangle in (x,y)-space

func (Rect) ClampPoint Uses

func (r Rect) ClampPoint(p Point) Point

ClampPoint returns the closest point in the rectangle to the given point. The rectangle must be non-empty.

func (Rect) Contains Uses

func (r Rect) Contains(other Rect) bool

Contains reports whether the rectangle contains the given rectangle.

func (Rect) ContainsPoint Uses

func (r Rect) ContainsPoint(p Point) bool

ContainsPoint reports whether the rectangle contains the given point. Rectangles are closed regions, i.e. they contain their boundary.

func (Rect) Expanded Uses

func (r Rect) Expanded(margin Point) Rect

Expanded returns a rectangle that has been expanded in the x-direction by margin.X, and in y-direction by margin.Y. If either margin is empty, then shrink the interval on the corresponding sides instead. The resulting rectangle may be empty. Any expansion of an empty rectangle remains empty.

func (Rect) ExpandedByMargin Uses

func (r Rect) ExpandedByMargin(margin float64) Rect

ExpandedByMargin returns a Rect that has been expanded by the amount on all sides.

func (Rect) Hi Uses

func (r Rect) Hi() Point

Hi returns the high corner of the rect.

func (Rect) InteriorContains Uses

func (r Rect) InteriorContains(other Rect) bool

InteriorContains reports whether the interior of this rectangle contains all of the points of the given other rectangle (including its boundary).

func (Rect) InteriorContainsPoint Uses

func (r Rect) InteriorContainsPoint(p Point) bool

InteriorContainsPoint returns true iff the given point is contained in the interior of the region (i.e. the region excluding its boundary).

func (Rect) InteriorIntersects Uses

func (r Rect) InteriorIntersects(other Rect) bool

InteriorIntersects reports whether the interior of this rectangle intersects any point (including the boundary) of the given other rectangle.

func (Rect) Intersection Uses

func (r Rect) Intersection(other Rect) Rect

Intersection returns the smallest rectangle containing the intersection of this rectangle and the given rectangle.

func (Rect) Intersects Uses

func (r Rect) Intersects(other Rect) bool

Intersects reports whether this rectangle and the other rectangle have any points in common.

func (Rect) IsEmpty Uses

func (r Rect) IsEmpty() bool

IsEmpty reports whether the rectangle is empty.

func (Rect) IsValid Uses

func (r Rect) IsValid() bool

IsValid reports whether the rectangle is valid. This requires the width to be empty iff the height is empty.

func (Rect) Lo Uses

func (r Rect) Lo() Point

Lo returns the low corner of the rect.

func (Rect) Size Uses

func (r Rect) Size() Point

Size returns the width and height of this rectangle in (x,y)-space. Empty rectangles have a negative width and height.

func (Rect) String Uses

func (r Rect) String() string

func (Rect) Union Uses

func (r Rect) Union(other Rect) Rect

Union returns the smallest rectangle containing the union of this rectangle and the given rectangle.

func (Rect) VertexIJ Uses

func (r Rect) VertexIJ(i, j int) Point

VertexIJ returns the vertex in direction i along the X-axis (0=left, 1=right) and direction j along the Y-axis (0=down, 1=up).

func (Rect) Vertices Uses

func (r Rect) Vertices() [4]Point

Vertices returns all four vertices of the rectangle. Vertices are returned in CCW direction starting with the lower left corner.

Package r2 imports 3 packages (graph) and is imported by 4 packages. Updated 2016-07-26. Refresh now. Tools for package owners.