added documentation for all functions
This commit is contained in:
@@ -5,20 +5,26 @@ import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// line is described as two Points
|
||||
type line struct {
|
||||
pt1, pt2 Point
|
||||
}
|
||||
|
||||
func lineHelper(l line) (float64, float64, float64) {
|
||||
// determinants aids by calculating necesary values for performing
|
||||
// calculations using the determinant of two points
|
||||
func determinants(l line) (float64, float64, float64) {
|
||||
a := l.pt2.Y - l.pt1.Y
|
||||
b := l.pt1.X - l.pt2.X
|
||||
c := a*l.pt1.X + b*l.pt1.Y
|
||||
return a, b, c
|
||||
}
|
||||
|
||||
// lineIntersection returns the Point of intersection between two lines.
|
||||
// lineIntersection will only return a point if the point lies on the
|
||||
// line, otherwise it will return a nil point and an error
|
||||
func lineIntersection(l1, l2 line) (Point, error) {
|
||||
a1, b1, c1 := lineHelper(l1)
|
||||
a2, b2, c2 := lineHelper(l2)
|
||||
a1, b1, c1 := determinants(l1)
|
||||
a2, b2, c2 := determinants(l2)
|
||||
det := a1*b2 - a2*b1
|
||||
|
||||
if det != 0 {
|
||||
@@ -37,6 +43,7 @@ func lineIntersection(l1, l2 line) (Point, error) {
|
||||
return Point{}, fmt.Errorf("lines do not intersect")
|
||||
}
|
||||
|
||||
// lineOnLine determins if both points of a line, l1, are on the same line, l2
|
||||
func lineOnLine(l1, l2 line) bool {
|
||||
if onLine(l1.pt1, l1.pt2, l2.pt1) && onLine(l1.pt1, l1.pt2, l2.pt2) {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user