Skip to content

Instantly share code, notes, and snippets.

@ivank2139
Created October 26, 2020 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivank2139/a56853c1a3f3787a1d0cf39d2816af57 to your computer and use it in GitHub Desktop.
Save ivank2139/a56853c1a3f3787a1d0cf39d2816af57 to your computer and use it in GitHub Desktop.
func FindOriginNode(listNodes bool) string {
originDist := float64(100 * 100)
for _, node := range Nodes {
sqd, _ := node.XCoord.Pow(decimal.NewFromInt(2)).Add(node.YCoord.Pow(decimal.NewFromInt(2))).Float64()
d := math.Sqrt(sqd)
if d < originDist {
originDist = d
OriginNode = node
}
}
var sbldr = strings.Builder{}
sbldr.WriteString("\nClosest node to origin is " + OriginNode.String())
if listNodes {
sbldr.WriteString("\nNodes: ")
for _, node := range Nodes {
sbldr.WriteString("\n\t" + node.String())
}
}
NextNode = OriginNode
return sbldr.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment