Skip to content

Instantly share code, notes, and snippets.

@ivank2139
Created October 26, 2020 19:57
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/aae5717502e7a8c12e7b3ff0664ca37d to your computer and use it in GitHub Desktop.
Save ivank2139/aae5717502e7a8c12e7b3ff0664ca37d to your computer and use it in GitHub Desktop.
Generate the edges from the nodes
func CalculateEdges(listEdges bool) string {
var sbldr = strings.Builder{}
for _, co := range Nodes {
for _, ci := range Nodes {
if co.Name == ci.Name {
log.Trace.Println("Skipping " + co.Name + " and " + ci.Name)
continue
}
diffXSq := co.XCoord.Sub(ci.XCoord).Abs().Pow(decimal.NewFromInt(2))
diffYSq := co.YCoord.Sub(ci.YCoord).Abs().Pow(decimal.NewFromInt(2))
sumSq, _ := diffXSq.Add(diffYSq).Float64()
d := math.Sqrt(sumSq)
Edges[co.Name+" - "+ci.Name] = NewEdge(co, ci, decimal.NewFromFloat(d))
}
}
sbldr.WriteString("\n\nCalculated the edge length for " + strconv.Itoa(len(Edges)) + " edges between all nodes. ")
if listEdges {
sbldr.WriteString("\nEdges:")
for _, edge := range Edges {
sbldr.WriteString("\n\t" + edge.String())
}
}
findMaxEdgeLength()
return sbldr.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment