r2

package
v0.0.0-...-583b476 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package r2 implements operations relating to objects in R2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Box

type Box struct {

	// A defines the top-left corner of the box
	A Vec2

	// S defines the size of the box
	S Vec2
}

Box defines a box in R2

            A
            |
            |
            |
            v
(1) A.X,A.Y +------+ A.X+S.X,A.Y (2)
            |\     |
            | \    |
            |  \   |
            |   \S |
            |    \ |
            |     \|

(3)A.X,A.Y+S.Y +------+ A.X+S.X,A.Y+S.Y (4)

func BoundingBox

func BoundingBox(points []Vec2) Box

BoundingBox creates a minimum axis-aligned bounding box for the given list of points.

func MakeBox

func MakeBox(a, s Vec2) Box

func (Box) Area

func (b Box) Area() float64

func (Box) Bottom

func (b Box) Bottom() Line

Bottom returns the bottom face of the box.

func (Box) Center

func (b Box) Center() Vec2

func (Box) Contains

func (b Box) Contains(v Vec2) bool

Contains returns true if the point v is within the box b.

func (Box) GetCorner1

func (b Box) GetCorner1() Vec2

GetCorner1 returns the top left corner of the box

func (Box) GetCorner2

func (b Box) GetCorner2() Vec2

GetCorner2 returns the top right corner of the box

func (Box) GetCorner3

func (b Box) GetCorner3() Vec2

GetCorner3 returns the bottom left corner of the box.

func (Box) GetCorner4

func (b Box) GetCorner4() Vec2

GetCorner4 returns the bottom right corner of the box.

func (Box) Height

func (b Box) Height() float64

func (Box) Intersect

func (b Box) Intersect(l Line) (Vec2, bool)

Returns the intersection of the box and the line, and a Boolean indicating if the box and vector intersect. If they do not collide, the zero vector is returned.

func (Box) Left

func (b Box) Left() Line

Left returns the left face of the box.

func (Box) Right

func (b Box) Right() Line

Right returns the right face of the box.

func (Box) Top

func (b Box) Top() Line

Top returns the top face of the box.

func (Box) Width

func (b Box) Width() float64

type Line

type Line struct {
	// A defines the basis point of the line
	A Vec2

	// S defines the direction and length of the line
	S Vec2
}

Line describes a line in R2

(1) A.X,A.Y  +
              \
               \
                \
                 \
                  + A.X+S.X,A.Y+S.Y (2)

func MakeLine

func MakeLine(a, s Vec2) Line

func MakeLineFromEndpoints

func MakeLineFromEndpoints(a, b Vec2) Line

Return a line which has endpoints a, b

func (Line) Endpoint1

func (l Line) Endpoint1() Vec2

func (Line) Endpoint2

func (l Line) Endpoint2() Vec2

func (Line) Length

func (l Line) Length() float64

type Vec2

type Vec2 struct {
	// X magnitude of the vector
	X float64

	// Y magnitude of the vector
	Y float64
}

Vec2 implements a vector in R2

func IntersectLines

func IntersectLines(l1, l2 Line) (Vec2, bool)

This code is transliterated from here:

https://github.com/JulNadeauCA/libagar/blob/master/gui/primitive.co

Which is in turn based on Gem I.2 in Graphics Gems II by James Arvo.

func MakeVec2

func MakeVec2(x, y float64) Vec2

MakeVec2 creates a new vector inline

func V2

func V2(x, y float64) Vec2

V2 is a shortcut for MakeVec2

func (Vec2) Add

func (v Vec2) Add(u Vec2) Vec2

Add returns the sum of vector v and u

func (Vec2) Dot

func (v Vec2) Dot(u Vec2) float64

Dot returns the dot product of vector v and u

func (Vec2) Length

func (v Vec2) Length() float64

Length return the vector length

func (Vec2) Project

func (v Vec2) Project(u Vec2) Vec2

Project returns the vector projection of v onto u

func (Vec2) Scale

func (v Vec2) Scale(s float64) Vec2

Scale returns the vector v scaled by the scalar s

func (Vec2) ScaleToLength

func (v Vec2) ScaleToLength(l float64) Vec2

ScaleToLength keeps the vector direction, but updates the length

func (Vec2) Unit

func (v Vec2) Unit() Vec2

Unit returns the vector scaled to length 1

Jump to

Keyboard shortcuts

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