point2d

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: MIT Imports: 2 Imported by: 0

README

Point 2D

A 2 dimensional Point.

Get it go get git.red-green.com/david/point2d

Go Reference

Example

package main

import (
    "fmt"
    "git.red-green.com/david/point2d"
)

func main() {
    var p *point2d.Point = new(point2d.Point)
    fmt.Println(p) // Automatically calls p.String()
    p.Set(3, 2) // Set's the Point's position to (3, 2)
    if p.Equal(3, 2) {
       fmt.Println("p is equal (3, 2)")
    } else {
       fmt.Println("p is not equal (3, 2), p is", p.String())
    }
    var p2 *point2d.Point = point2d.AsPoint(3, 9)
    var dist int = p.DistanceTo(&p2)
    fmt.Printf("p is %d away from p2\n", dist)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Point

type Point struct {
	X int // X Axis (Horizontal)
	Y int // Y Axis (Vertical)
}

A Point 2D

func AsPoint

func AsPoint(to ...int) *Point

Creates a new point given 1-2 integers (more integers are ignored)

func NewPoint

func NewPoint() *Point

Creates a new point at (0, 0)

func (*Point) Abs

func (p *Point) Abs() *Point

Makes both X and Y axis's positive

func (*Point) Copy

func (p *Point) Copy() *Point

Makes a copy of the Point's location

func (*Point) Distance

func (p *Point) Distance(x, y int) int

The distance from the Point to the assumed location

func (*Point) DistanceTo

func (p *Point) DistanceTo(o *Point) int

The distance from the Point to another Point

func (*Point) Equal

func (p *Point) Equal(to ...int) bool

Compares if the Point is equal to the 1-2 integers (more integers are ignored)

func (*Point) EqualTo

func (p *Point) EqualTo(o *Point) bool

Compares the Point to another Point

func (*Point) Greater

func (p *Point) Greater(than ...int) bool

Compares the Point against 1-2 integers (more integers are ignored)

func (*Point) GreaterThan

func (p *Point) GreaterThan(o *Point) bool

Compares the Point to another Point

func (*Point) IsX

func (p *Point) IsX(x int) bool

Compares if the Point's X is the same as given X axis

func (*Point) IsY

func (p *Point) IsY(y int) bool

Compares if the Point's Y is the same as given Y axis

func (*Point) IsZero

func (p *Point) IsZero() bool

Compares if the Point is (0, 0)

func (*Point) Less

func (p *Point) Less(than ...int) bool

Compares the Point against 1-2 integers (more integers are ignored)

func (*Point) LessThan

func (p *Point) LessThan(o *Point) bool

Compares the Point against another Point

func (*Point) Move

func (p *Point) Move(by ...int) *Point

Translate by 1-2 integers (more integers are ignored)

func (*Point) MoveBy

func (p *Point) MoveBy(o *Point) *Point

Translate by another Point's location

func (*Point) Negate

func (p *Point) Negate() *Point

Flips both the X and Y axis's signs

func (*Point) Set

func (p *Point) Set(to ...int) *Point

Assignment by 1-2 integers (more integers are ignored)

func (*Point) SetTo

func (p *Point) SetTo(o *Point) *Point

Assignment to another Point's location

func (*Point) String

func (p *Point) String() string

Outputs the Point as "X Y"

func (*Point) Within

func (p *Point) Within(topLeft, botRight *Point) bool

Compares the Point to see if it's within the 2 other Points

Supports if you gave the parameters backwards

func (*Point) Zero

func (p *Point) Zero() *Point

Assigns this Point to (0, 0)

Jump to

Keyboard shortcuts

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