changed permission on func and added maximum error

made sure that not all functions were public and changed some to private
that need not be exposed.

also added in maximum error to deal with floating point inaccuracies
This commit is contained in:
dm
2016-08-27 20:46:32 -07:00
parent 3850bdc592
commit 9b908a8db1
4 changed files with 26 additions and 23 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ func distance(p1, p2 Point) float64 {
}
func onLine(rp1, rp2, p Point) bool {
if distance(rp1, p)+distance(rp2, p) == distance(rp1, rp2) {
if math.Abs(distance(rp1, p)+distance(rp2, p)-distance(rp1, rp2)) < ɛ {
minx, maxx := math.Min(rp1.X, rp2.X), math.Max(rp1.X, rp2.X)
miny, maxy := math.Min(rp1.Y, rp2.Y), math.Max(rp1.Y, rp2.Y)
if minx <= p.X && p.X <= maxx && miny <= p.Y && p.Y <= maxy {