rect

package module
v0.0.0-...-2b69fc7 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2017 License: MIT Imports: 3 Imported by: 1

README

rect

GoDoc Go Report Card

Package rect implements rectangles and can determine when rectangles intersect, are contained, and when rectangles lie adjacent

usage

in cmd/recty/main.go is an example of how one could use this package.

r := rect.Rectangle{     
    P1: rect.Point{1, 1},
    P2: rect.Point{1, 2},
    P3: rect.Point{2, 1},
    P4: rect.Point{2, 2},
}                        

defines a rectangle.

fmt.Println(r.IsRect())

would varify that the rectangle provided is a valid rectangle.

r1 := rect.Rectangle{     
    P1: rect.Point{1, 1},
    P2: rect.Point{1, 2},
    P3: rect.Point{2, 1},
    P4: rect.Point{2, 2},
}                        
r2 := rect.Rectangle{     
    P1: rect.Point{1, 1},
    P2: rect.Point{1, 2},
    P3: rect.Point{2, 1},
    P4: rect.Point{2, 2},
}                        

fmt.Println(rect.Intersection(r1, r2))

Running the above code would print out all intersection points of the two rectangles.

r3 := rect.Rectangle{     
    P1: rect.Point{0, 0},
    P2: rect.Point{0, 3},
    P3: rect.Point{3, 0},
    P4: rect.Point{3, 3},
}                        
r4 := rect.Rectangle{     
    P1: rect.Point{2, 2},
    P2: rect.Point{2, 3},
    P3: rect.Point{3, 2},
    P4: rect.Point{3, 3},
}                        

fmt.Println(rect.Adjacency(r3, r4))

This would return a boolean for whether r3 and r4 have an adjacent side.

r5 := rect.Rectangle{     
    P1: rect.Point{0, 0},
    P2: rect.Point{0, 3},
    P3: rect.Point{3, 0},
    P4: rect.Point{3, 3},
}                        
r6 := rect.Rectangle{     
    P1: rect.Point{1, 1},
    P2: rect.Point{1, 2},
    P3: rect.Point{2, 1},
    P4: rect.Point{2, 2},
}                        

fmt.Println(rect.Containment(r5, r6))

And finally, running rect.Containment(r5, r6) would return true because r6 is contained inside of r5

Documentation

Overview

Package rect implements rectangles and can determine when rectanges intersect, are contained, and when rectangles lie adjacent

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adjacency

func Adjacency(r1, r2 Rectangle) bool

Adjacency detects whether two rectangles, r1, and r2, are adjacent. Adjacency is defined as the sharing of a side

func Containment

func Containment(r1, r2 Rectangle) bool

Containment returns whether r2 is contained inside of r1

Types

type Point

type Point struct {
	X, Y float64
}

Point is a struct defining a coordinates position on a 2D plane

func Intersection

func Intersection(r1, r2 Rectangle) []Point

Intersection determine whether two rectangles, r1 and r2, have one or more intersecting lines and produce a result, []Point, identifying the points of intersection

type Rectangle

type Rectangle struct {
	P1, P2, P3, P4 Point
}

Rectangle struct defines a plane figure with four straight sides and four right angles, which contains 4 vertixes points, P1 through P4

func (Rectangle) IsRect

func (r Rectangle) IsRect() bool

IsRect determins if the rectangle provided really is a rectangle, which by definition means a plane figure with four straight sides and four right angles.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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