rect

package
v0.0.0-...-9989d13 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// contains filtered or unexported fields
}

Field is a single field of a grid, identified by column and row. Fields are value objects, i.e. they never change. Fields can safely be used as map keys.

func CreateField

func CreateField(column, row int) Field

CreateField creates a field point to (column, row).

func (Field) Column

func (f Field) Column() int

Column returns the field's column.

func (Field) Row

func (f Field) Row() int

Row returns the field's row.

type FieldOffset

type FieldOffset interface {
	// Apply applies this offset to a field, resulting in a new field. The old field
	// remains unchanged.
	Apply(Field) Field
}

FieldOffset is an offset for fields, e.g. a linear translation.

func FieldOffsetDown

func FieldOffsetDown() FieldOffset

FieldOffsetDown returns an offset which takes the field below the given field.

func FieldOffsetFromField

func FieldOffsetFromField(f Field) FieldOffset

FieldOffsetFromField converts a field to a corresponding offset, meaning its column is used as the horizontal part of the offset, while the row is used as the vertical part.

func FieldOffsetLeft

func FieldOffsetLeft() FieldOffset

FieldOffsetLeft returns an offset which takes the field left to the given field.

func FieldOffsetRight

func FieldOffsetRight() FieldOffset

FieldOffsetRight returns an offset which takes the field right to the given field.

func FieldOffsetUp

func FieldOffsetUp() FieldOffset

FieldOffsetUp returns an offset which takes the field above the given field.

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid represents a finite rectangular grid, providing methods for calculating field indexes and more. The zero value is usable (although probably not very useful).

func (*Grid) Contains

func (grid *Grid) Contains(field Field) bool

Contains checks wether a field is inside the grid.

func (*Grid) CoordinatesFromField

func (grid *Grid) CoordinatesFromField(field Field) v2d.Vector

CoordinatesFromField takes a field and returns the corresponding coordinates of the top left corner as a vector. Unlike FieldFromCoordinates, CoordinatesFromField works on grids with zero field size, it is just not useful because all grid points have the same coordinates: (0, 0).

func (*Grid) CoordinatesFromGridCoordinates

func (grid *Grid) CoordinatesFromGridCoordinates(field v2d.Vector) v2d.Vector

CoordinatesFromGridCoordinates is basically the same as CoordinatesFromField, but allows for non-integer "fields", e.g. the position of column 1.5 and row -0.75.

func (*Grid) FieldFromCoordinates

func (grid *Grid) FieldFromCoordinates(pos v2d.Vector) (*Field, error)

FieldFromCoordinates takes a vector and returns its corresponding grid field. This field is not necessarely contained within the grid, this can be checked with Grid.Contains(). Returns an error and no field if the field size in any dimension is zero.

func (*Grid) Set

func (grid *Grid) Set(options ...GridOption) error

Set applies options to the grid. If any option fails and causes an error, the grid remains unchanged and that error is returned. No more options are applied in this case. Unlike grid methods for queries and calcuations, Set is not safe for concurrency. The typical use case is: Set the options on the grid once, then use methods like FieldFromCoordinates from as many Go routines as you like.

type GridOption

type GridOption interface {
	// contains filtered or unexported methods
}

GridOption is used by Grid.Set().

func FieldSize

func FieldSize(fieldSize v2d.Vector) GridOption

FieldSize is an option for setting the size of a single field on the grid.

func Offset

func Offset(offset v2d.Vector) GridOption

Offset is an option for setting the offset of the grid.

func Size

func Size(columns int, rows int) GridOption

Size is an option for setting the size of the grid, i.e. how many columns and rows the grid has.

Jump to

Keyboard shortcuts

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