geometry

package
v0.0.0-...-b5b2f04 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 0 Imported by: 1

Documentation

Overview

Geometry utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rectangle

type Rectangle struct {
	// Top Left corner of rectangle.
	Origin Vec2D

	// RectSize define size of rectangle.
	RectSize Size
}

Rectangle define a rectangle with two 2D vectors for the minimum (top-left corner) and the maximum (bottom-right corner).

func (Rectangle) Area

func (r Rectangle) Area() int

Area computes surface area of the rectangle.

func (Rectangle) Bottom

func (r Rectangle) Bottom() int

Bottom returns position of the bottom edge on Y axis.

func (Rectangle) BottomLeft

func (r Rectangle) BottomLeft() Vec2D

BottomLeft returns position of bottom left corner.

func (Rectangle) BottomRight

func (r Rectangle) BottomRight() Vec2D

BottomRight returns position of bottom right corner.

func (Rectangle) Contains

func (r Rectangle) Contains(p Vec2D) bool

Contains returns true if it contains the given vector.

func (Rectangle) GrowBottom

func (r Rectangle) GrowBottom(n int) Rectangle

GrowBottom returns a new rectangle with bottom edge moved by n unit to the bottom.

func (Rectangle) GrowLeft

func (r Rectangle) GrowLeft(n int) Rectangle

GrowLeft returns a new rectangle with left edge moved by n unit to the left.

func (Rectangle) GrowRight

func (r Rectangle) GrowRight(n int) Rectangle

GrowRight returns a new rectangle with right edge moved by n unit to the right.

func (Rectangle) GrowTop

func (r Rectangle) GrowTop(n int) Rectangle

GrowTop returns a new rectangle with top edge moved by n unit to the top.

func (Rectangle) Left

func (r Rectangle) Left() int

Left returns origin position on X axis.

func (Rectangle) MoveBy

func (r Rectangle) MoveBy(n Vec2D) Rectangle

MoveBy returns a new Rectangle moved by the given offset.

func (Rectangle) Right

func (r Rectangle) Right() int

Right returns position of the right edge on X axis.

func (Rectangle) ShrinkBottom

func (r Rectangle) ShrinkBottom(n int) Rectangle

ShrinkBottom returns a new rectangle with bottom edge moved by n unit to the top.

func (Rectangle) ShrinkLeft

func (r Rectangle) ShrinkLeft(n int) Rectangle

ShrinkLeft returns a new rectangle with left edge moved by n unit to the right.

func (Rectangle) ShrinkRight

func (r Rectangle) ShrinkRight(n int) Rectangle

ShrinkRight returns a new rectangle with right edge moved by n unit to the left.

func (Rectangle) ShrinkTop

func (r Rectangle) ShrinkTop(n int) Rectangle

ShrinkTop returns a new rectangle with top edge moved by n unit to the bottom.

func (Rectangle) Size

func (r Rectangle) Size() Size

Size implements Sized.

func (Rectangle) Top

func (r Rectangle) Top() int

Top returns origin position on Y axis.

func (Rectangle) TopLeft

func (r Rectangle) TopLeft() Vec2D

TopLeft returns position of top left corner.

func (Rectangle) TopRight

func (r Rectangle) TopRight() Vec2D

TopRight returns position of top right corner.

type Size

type Size struct {
	Width  int
	Height int
}

Size define the width and the height of an object.

func (Size) Size

func (s Size) Size() Size

Size implements the Sized interface.

type Sized

type Sized interface {
	Size() Size
}

Sized define any sized object.

type Vec2D

type Vec2D struct {
	X, Y int
}

Vec2D define a point in 2 dimensional Euclidian space.

func (Vec2D) Add

func (v2 Vec2D) Add(other Vec2D) Vec2D

Add returns a new Vec2D translated by adding the given vector.

func (Vec2D) Sub

func (v2 Vec2D) Sub(other Vec2D) Vec2D

Sub returns a new Vec2D translated by subtracting the given vector.

Jump to

Keyboard shortcuts

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