point

package
v0.0.0-...-e2c65c2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package point provides convenience logic for manipulating points and regions in 2-space.

NOTE: this package mostly exists because I (Josh) had never used the core "image" package much, and didn't know about its Point/Rectangle structs; one point of view would say that many of the utililyt methods should just be broken out (maybe into "bork/internal/moremath") as function-taking-data (rather than receiving). The Point structure is (coincidentally) cast-compatible with the standard one in the "image" package; the Box isn't becasue of Go's conservatism composing poorly with my short sightedness.

TODO: de-conflict and align better with core "image".Point et al along spiritually identical or similar methods.

Index

Constants

This section is empty.

Variables

View Source
var Zero = Point{}

Zero is the origin, the zero value of Point.

Functions

func MulRespective

func MulRespective(a, b image.Point) image.Point

MulRespective returns a point scaled by another point, multiplying the values of their respective axes.

func Sign

func Sign(pt image.Point) image.Point

Sign returns a copy of the point reduced to the values -1, 0, or 1 depending on the sign of the original values.

func SumSQ

func SumSQ(pt image.Point) int

SumSQ returns the sum of squared-components of a given point.

Types

type Box

type Box struct {
	TopLeft     Point
	BottomRight Point
}

Box represents a bounding box defined by a top-left and bottom-right point.

func Bx

func Bx(tlx, tly int, brx, bry int) Box

Bx is a convenience constructor for Box.

func (Box) Add

func (b Box) Add(pt Point) Box

Add returns a copy of the box with the given point added to the corners.

func (Box) Contains

func (b Box) Contains(pt Point) bool

Contains returns true if a given point is inside the box.

func (Box) DistanceTo

func (b Box) DistanceTo(pt Point) Point

DistanceTo returns a signed distance to the given point from the nearest box corner.

func (Box) ExpandBy

func (b Box) ExpandBy(d Point) Box

ExpandBy symmetrically expands a copy of the box by a given x/y displacement, returning the copy.

func (Box) ExpandTo

func (b Box) ExpandTo(pt Point) Box

ExpandTo expands a copy of the box to include the given point, returning the copy.

func (Box) Max

func (b Box) Max(pt Point) Box

Max returns a copy of the box each corner max'd to the given point.

func (Box) Min

func (b Box) Min(pt Point) Box

Min returns a copy of the box each corner min'd to the given point.

func (Box) Size

func (b Box) Size() Point

Size returns the width and height of the box as a point.

func (Box) Sub

func (b Box) Sub(pt Point) Box

Sub returns a copy of the box with the given point subtracted from the corners.

type Point

type Point struct{ X, Y int }

Point represents a point in <X,Y> 2-space.

func Pt

func Pt(x, y int) Point

Pt is a convenience constructor for Point.

func (Point) Abs

func (pt Point) Abs() Point

Abs returns a copy of this point with its values non-negative.

func (Point) Add

func (pt Point) Add(other Point) Point

Add adds another point's values to a copy of this point, returning the copy.

func (Point) Div

func (pt Point) Div(n int) Point

Div divides a copy of this point's values by a constant, returning the copy.

func (Point) Dot

func (pt Point) Dot(other Point) int

Dot return the dot product of this point with another.

func (Point) Equal

func (pt Point) Equal(other Point) bool

Equal returns true if both this point's X and Y components equal another's.

func (Point) Less

func (pt Point) Less(other Point) bool

Less returns true if this point's X or Y component is less than the other's.

func (Point) Max

func (pt Point) Max(other Point) Point

Max returns a copy of this point with each component the maximum of the two points' components.

func (Point) Min

func (pt Point) Min(other Point) Point

Min returns a copy of this point with each component the minimum of the two points' components.

func (Point) Mul

func (pt Point) Mul(n int) Point

Mul multiplies a copy of this point's values by a constant, returning the copy.

func (Point) Neg

func (pt Point) Neg() Point

Neg negates a copy of this point, returning the copy.

func (Point) Sign

func (pt Point) Sign() Point

Sign returns a copy of this point reduced to the values -1, 0, or 1 depending on the sign of the original values.

func (Point) Sub

func (pt Point) Sub(other Point) Point

Sub subtracts another point's values from a copy of this point, returning the copy.

func (Point) SumSQ

func (pt Point) SumSQ() int

SumSQ returns the sum-of-squared components.

type ZFrame

type ZFrame struct {
	Bounds image.Rectangle
}

ZFrame represents a frame of reference for computing Z-Curve keys.

func (ZFrame) Key

func (zf ZFrame) Key(pt image.Point) (z uint64)

Key packs a point into a z-curve key; if the point is outside the bounding box, then Key(bounds.Max) is returned.

func (ZFrame) Point

func (zf ZFrame) Point(z uint64) image.Point

Point unpacks a z-curve key into a point.

Jump to

Keyboard shortcuts

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