Created
October 26, 2020 19:47
-
-
Save ivank2139/a56853c1a3f3787a1d0cf39d2816af57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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