From 8cd352b7a32ea4b9d6dfd443d52a3b953e60b236 Mon Sep 17 00:00:00 2001 From: Ben Cragg Date: Wed, 3 Apr 2019 08:13:33 +0100 Subject: [PATCH] WIP line tests --- geometry.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/geometry.go b/geometry.go index d71cbd8..5854914 100644 --- a/geometry.go +++ b/geometry.go @@ -222,17 +222,10 @@ func (l Line) Closest(v Vec) Vec { m, b := l.Formula() perpendicularM := -1 / m perpendicularB := v.Y - (perpendicularM * v.X) - fmt.Println(m) - fmt.Println(b) - fmt.Println(perpendicularM) - fmt.Println(perpendicularB) // Coordinates of intersect (of infinite lines) x := (perpendicularB - b) / (m - perpendicularM) - y := m*x - b - - fmt.Println(x) - fmt.Println(y) + y := m*x + b return V(x, y) } @@ -253,11 +246,9 @@ func (l Line) Formula() (m, b float64) { // Intersect will return the point of intersection for the two line segments. If the line segments do not intersect, // this function will return the zero-vector and `false`. func (l Line) Intersect(k Line) (Vec, bool) { - fmt.Printf("%v, %v\n", l, k) // Check if the lines are parallel lDir := l.A.To(l.B) kDir := k.A.To(k.B) - fmt.Printf("%v, %v\n", lDir, kDir) if lDir.X == kDir.X && lDir.Y == kDir.Y { fmt.Println("p") return ZV, false @@ -268,13 +259,10 @@ func (l Line) Intersect(k Line) (Vec, bool) { // segments lm, lb := l.Formula() km, kb := k.Formula() - fmt.Printf("%.2f, %.2f -- %.2f, %.2f\n", lm, lb, km, kb) // Coordinates of intersect x := (kb - lb) / (lm - km) y := lm*x + lb - fmt.Printf("(%.2f, %.2f)\n", x, y) - fmt.Printf("%t %t\n", l.Contains(V(x, y)), k.Contains(V(x, y))) if l.Contains(V(x, y)) && k.Contains(V(x, y)) { // The intersect point is on both line segments, they intersect.