matrix

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 0 Imported by: 1

README

Build Status codecov Maintainability

matrix - Package implements iterator for matrix navigation

Quick start

Use this package to minimize complexity when navigatin 2D matrix structures. To loop over an matrix from top, left corner to bottom, right

for nav, x, y, inside := NewNavigator(3, 3); inside; x, y, inside = nav.Right() {
	// do something
}

Note that all navigation methods wrap at the edge of the given boundary.

  0 1 2 3 4
-+---------+
0| | | | | |
1| |-|-|-| |
2| |-|>|x| |
3| |x|x|x| |
4| | | | | |
-+---------+

Documentation

Overview

Package matrix implements 2D matrix navigation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rect

type Rect struct {
	Left, Top     int // x,y of the top left corner
	Right, Bottom int // x,y of the bottom left corner
}

type XYNavigator

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

func NewNavigator

func NewNavigator(rows, cols int) (nav *XYNavigator, x, y int, inside bool)

func NewXYNavigator

func NewXYNavigator(x, y int, boundary Rect) *XYNavigator

func (*XYNavigator) Down

func (nav *XYNavigator) Down() (x, y int, inside bool)

Down returns next position below the current and wraps columns until reaching xj, yj.

func (*XYNavigator) Left

func (nav *XYNavigator) Left() (x, y int, inside bool)

Left returns next position left of the current and wraps lines until reaching xi, yi.

func (*XYNavigator) Right

func (nav *XYNavigator) Right() (x, y int, inside bool)

Right returns next position right of the current and wraps lines until reaching xj, yj.

func (*XYNavigator) Up

func (nav *XYNavigator) Up() (x, y int, inside bool)

Up returns next position above the current and wraps columns until reaching xi, yi.

Jump to

Keyboard shortcuts

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