Documentation
¶
Index ¶
- Variables
- func ArcGenerator(radius int) func() Coord
- func Circle(center Coord, radius int, fn func(pos Coord))
- func EachCoordInArea(b Bounded) iter.Seq[Coord]
- func EachCoordInIntersection(areas ...Bounded) iter.Seq[Coord]
- func EachCoordInPerimeter(b Bounded) iter.Seq[Coord]
- func Intersects(b1, b2 Bounded) bool
- type Bounded
- type Coord
- func (c1 Coord) Add(c2 Coord) Coord
- func (c1 Coord) DistanceSqTo(c2 Coord) int
- func (c1 Coord) DistanceTo(c2 Coord) float64
- func (c Coord) IsInPerimeter(b Bounded) bool
- func (c Coord) IsInside(b Bounded) bool
- func (c1 Coord) ManhattanDistanceTo(c2 Coord) int
- func (c *Coord) Move(dx, dy int)
- func (c *Coord) MoveTo(x, y int)
- func (c Coord) Scale(scale int) Coord
- func (c Coord) Step(d Direction) Coord
- func (c Coord) StepN(d Direction, n int) Coord
- func (c Coord) String() string
- func (c1 Coord) Subtract(c2 Coord) Coord
- func (c Coord) ToIndex(stride int) int
- type Dims
- type Direction
- type Line
- type Rect
- type Vec2Polar
- type Vec2f
- type Vec2i
Constants ¶
This section is empty.
Variables ¶
var Directions []Direction = []Direction{DIR_UP, DIR_UPRIGHT, DIR_RIGHT, DIR_DOWNRIGHT, DIR_DOWN, DIR_DOWNLEFT, DIR_LEFT, DIR_UPLEFT}
Functions ¶
func ArcGenerator ¶
returns a generator that computes successive coordinates representing 1/8th of a circle. rotate the arc to draw circles. gives back the ZERO_COORD when it is done.
func Circle ¶
Computes a circle, calling fn on each point of the circle. fn can be a drawing function or whatever.
func EachCoordInArea ¶
Returns an iterator producing a sequence of all Coords within the Rect r, starting in the top-left corner and proceeding to the right, going line by line (like how you'd read)
func EachCoordInIntersection ¶ added in v0.2.0
Returns an iterator producing a sequence of all Coords that are contained within the intersection of all provided bounded areas.
func EachCoordInPerimeter ¶
Returns an iterator producing a sequence of all coords in the perimeter of a bounded area.
func Intersects ¶
Intersects returns true if the two provided Bounded areas intersect
Types ¶
type Bounded ¶
type Bounded interface {
Bounds() Rect
}
Bounded defines objects that can report a bounding box of some kind.
type Coord ¶
type Coord Vec2i
Coord is an (X, Y) pair that represents a spot on some 2d grid.
func IndexToCoord ¶
IndexToCoord returns a coord representing an index from a 1D array representing a 2D grid with the given stride
func RandomCoordInArea ¶ added in v0.2.0
func (Coord) DistanceSqTo ¶ added in v0.2.0
DistanceSqTo returns the euclidean distance between c1 and c2, squared. This is useful for comparing distances in cases where the actual distance is not important, because this is much faster than calculating the real distance.
func (Coord) DistanceTo ¶ added in v0.2.0
DistanceTo returns the euclidean distance bewteen c1 and c2. For comparisons, consider using DistanceSqTo instead, it will be much faster.
func (Coord) IsInPerimeter ¶ added in v0.2.0
IsInPerimeter check if the coord lies in the perimeter of the bounded object b.
func (Coord) ManhattanDistanceTo ¶ added in v0.2.0
ManhattanDistance calculates the manhattan (or taxicab) distance on a square grid.
type Dims ¶
type Dims struct {
W, H int
}
Dims represents a set of dimensions in 2D.
type Direction ¶
type Direction int
func RandomCardinalDirection ¶ added in v0.2.0
func RandomCardinalDirection() Direction
func RandomDirection ¶ added in v0.2.0
func RandomDirection() Direction
func (Direction) RotateCCW90 ¶ added in v0.2.0
func (Direction) RotateCW90 ¶ added in v0.2.0
type Line ¶
Line represents a line between 2 points on a square grid.
func (Line) EachCoord ¶
EachCoord returns an iterator that produces Coords representing the line from start to end inclusive.
type Rect ¶
Rect is your standard rectangle object, with position (X,Y) in the top left corner.
func FindIntersectionRect ¶
FindIntersectionRect calculates the intersection of two rectangularly-bound objects. if no intersection returns Rect{0,0,0,0}
func (Rect) Center ¶ added in v0.2.0
Returns the center of the rect. Since we're all integers 'round these parts this won't be exact unless both width and height are odd numbers, so be aware.
func (Rect) Corners ¶
Returns the coordinates of the 4 corners of the rect, starting in the top left and going clockwise.
func (Rect) Translated ¶
type Vec2Polar ¶
type Vec2Polar struct {
R, Phi float64
}
func (Vec2Polar) Add ¶
Add converts to recitlinear components and adds, then converts back to polar.
func (Vec2Polar) AngularDistance ¶
Returns the shortest anglular distance from v1 to v2. positive for counterclockwise, negative for clockwise. NOTE: Do these need to be Pos()'d?? Hmm.