Documentation
¶
Index ¶
- Constants
- type Aspect
- type BaseIterator
- type BaseIteratorWrapper
- type DenseFloatGrid
- type DenseGrid
- type FloatGenerator
- type Generator
- type Grid
- type Iterator
- type IteratorFactory
- type Pt
- func (pt Pt) Abs() Pt
- func (pt Pt) Add(pt2 Pt) Pt
- func (pt Pt) Area() int
- func (pt Pt) AssertEqual(actual interface{}, t cmpr.Tolerance) error
- func (pt Pt) D2() d2.D2
- func (pt Pt) Index(idx int) Pt
- func (pt Pt) Iter() Iterator
- func (pt Pt) Mask(and int) Pt
- func (pt Pt) Multiply(scale float64) Pt
- func (pt Pt) Subtract(pt2 Pt) Pt
- func (pt Pt) To(pt2 Pt) Iterator
- type Range
- type Scale
- type ScanOption
- type Scanner
- func (s *Scanner) Contains(pt Pt) bool
- func (s *Scanner) Done() bool
- func (s *Scanner) Idx() int
- func (s *Scanner) Iter() Iterator
- func (s *Scanner) Next() bool
- func (s *Scanner) Pt() Pt
- func (s *Scanner) PtIdx(pt Pt) int
- func (s *Scanner) Reset() (done bool)
- func (s *Scanner) Scale() Scale
- func (s *Scanner) Size() Pt
- type SparseGrid
Constants ¶
const ( // TwoMask sets the one bit to zero, the result is always divisible by 2. TwoMask int = (^int(0)) ^ 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseIterator ¶
type BaseIterator interface { IteratorFactory Next() (done bool) Pt() Pt Idx() int Done() bool Reset() (done bool) PtIdx(Pt) int Size() Pt Contains(Pt) bool Scale() Scale }
BaseIterator contains the methods needed for BaseIteratorWrapper to create an Iterator
type BaseIteratorWrapper ¶
type BaseIteratorWrapper struct {
BaseIterator
}
BaseIteratorWrapper takes a BaseIterator and extends it's functionality.
func (BaseIteratorWrapper) Chan ¶
func (base BaseIteratorWrapper) Chan() <-chan Pt
Chan runs a go routine that will return the points of the iterator. When all the points are consumed the channel is closed. Failing to consume all the points will cause a Go routine leak.
func (BaseIteratorWrapper) Each ¶
func (base BaseIteratorWrapper) Each(fn func(int, Pt))
Each calls the fn for each point in the iterator.
func (BaseIteratorWrapper) Slice ¶
func (base BaseIteratorWrapper) Slice() []Pt
Slice returns all the points in the iterator as a slice.
func (BaseIteratorWrapper) Start ¶
func (base BaseIteratorWrapper) Start() (Iterator, bool)
Start is helper that can be as the first portion of a classic for loop
type DenseFloatGrid ¶
DenseFloatGrid stores a fixed size grid of float64s.
func NewDenseFloatGrid ¶
func NewDenseFloatGrid(i IteratorFactory, generator FloatGenerator) DenseFloatGrid
NewDenseFloatGrid with a size determined by the Iterator generated by the IteratorFactory. If generator is not nil, the values will be prepopulated.
func (DenseFloatGrid) Get ¶
func (g DenseFloatGrid) Get(pt Pt) (interface{}, error)
Get a value, fulfills Grid. The underlying type will always be float64
func (DenseFloatGrid) GetFloat ¶
func (g DenseFloatGrid) GetFloat(pt Pt) (float64, error)
GetFloat from DenseFloatGrid
func (DenseFloatGrid) Normalize ¶
func (g DenseFloatGrid) Normalize()
Normalize sets the lowest value to 0 and the highest value to 1 and distributes all other value proportionally.
func (DenseFloatGrid) Set ¶
func (g DenseFloatGrid) Set(pt Pt, val interface{}) error
Set a value, fulfills Grid. Any numeric value can be passed in and will be cast to float64.
type DenseGrid ¶
type DenseGrid struct { Iterator Data []interface{} }
DenseGrid is backed by a slice and should have an entry for every node in the grid.
func NewDenseGrid ¶
func NewDenseGrid(i IteratorFactory, generator Generator) *DenseGrid
NewDenseGrid creates a DenseGrid with Data allocated at the correct size. If a Generator is given, the data will be populated.
type FloatGenerator ¶
FloatGenerator returns a float64 given a pt
type Generator ¶
type Generator func(pt Pt) interface{}
Generator is used to fill grids from their point values.
type Iterator ¶
type Iterator interface { BaseIterator Start() (iter Iterator, done bool) Slice() []Pt Chan() <-chan Pt Each(fn func(int, Pt)) Until(fn func(int, Pt) bool) bool }
Iterator is used to iterate over the cells in a grid.
type IteratorFactory ¶
type IteratorFactory interface {
Iter() Iterator
}
IteratorFactory is anything that can produce an iterator. An InteratorFactory should return a new iterator, not one that may already be in use.
type Pt ¶
type Pt struct {
X, Y int
}
Pt is a cell in a grid
func (Pt) AssertEqual ¶
AssertEqual fulfils geomtest.AssertEqualizer
type Range ¶
type Range [2]Pt
Range represents a grid with the first point being inclusive and the second point exclusive.
func (Range) Contains ¶
Contains checks if the point is in the Range with the first point being inclusive and the second point being exclusive.
func (Range) Max ¶
Max returns the point with the largest X and Y value that is contained in the range.
func (Range) Min ¶
Min returns the point with the lowest X and Y value that is contained in the range.
type Scale ¶
type Scale struct {
X, Y, DX, DY float64
}
Scale is used to convert a Grid Pt to two float64 values, often
type ScanOption ¶
type ScanOption byte
ScanOption allows the scanner operation to be configured.
const ( // ScanVertical will scan columns then rows ScanVertical ScanOption = 1 // ScanPrimaryReversed causes the scan in the primary direction to proceed // backward. The primary direction is X unless ScanVertical is used. ScanPrimaryReversed ScanOption = 2 // ScanSecondaryReversed causes the scan in the secondary direction to // proceed backward. The secondary direction is Y unless ScanVertical is // used. ScanSecondaryReversed ScanOption = 4 )
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner scans a rectangular region.
func NewScanner ¶
func NewScanner(r Range, opts ...ScanOption) *Scanner
NewScanner creates a scanner based on a Range. The r[0] value is incluse and the r[1] value is exclusive.
func (*Scanner) PtIdx ¶
PtIdx takes a Pt and returns the Idx value when the scanner would reach that point. If the point is not inside the scan region, the response will not be meaningful.
type SparseGrid ¶
SparseGrid is backed by a map so it can hold an arbitrary amount of data. If a generator is defined, it will be invoked lazily.
func NewSparseGrid ¶
func NewSparseGrid(i IteratorFactory, generator Generator) *SparseGrid
NewSparseGrid creates a SparseGrid. If an IteratorFactory is defined, that will be used as an iterator. This is for convience only as a sparse grid is not actually limited to any range. If a generator is defined, it will be invoked lazily when accessing points that have not been set.
func (*SparseGrid) Get ¶
func (g *SparseGrid) Get(pt Pt) (interface{}, error)
Get the value at the defined Pt in the grid. If the point value has not been set and a generator has been set the value will be generated and stored.
func (*SparseGrid) Set ¶
func (g *SparseGrid) Set(pt Pt, val interface{}) error
Set the value at the point. Setting a value to nil will remove it from the underlying map. This means that if there is a generator, the next Get will update that point with the value from the generator.