Created
October 26, 2020 19:57
-
-
Save ivank2139/aae5717502e7a8c12e7b3ff0664ca37d to your computer and use it in GitHub Desktop.
Generate the edges from the nodes
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 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