-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinates.go
51 lines (44 loc) · 1.31 KB
/
coordinates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/csv"
"log"
"strconv"
"strings"
)
type coordinates struct {
MeshName string
MostPositive [3]float32
MostNegative [3]float32
}
func NewCoordinates(meshName string, mostPositive [3]float32, mostNegative [3]float32) *coordinates {
return &coordinates{
MeshName: meshName,
MostPositive: mostPositive,
MostNegative: mostNegative,
}
}
func GetCoordinatesFromCsv(csvFile []byte) []*coordinates {
// Parse the CSV
records, err := csv.NewReader(strings.NewReader(string(csvFile))).ReadAll()
if err != nil {
log.Fatal(err)
}
// Create the coordinates
coordinates := make([]*coordinates, 0)
for i := 1; i < len(records); i++ {
record := records[i]
mostPositive := [3]float32{convertToFloat32(record[1]), convertToFloat32(record[3]), -convertToFloat32(record[5])}
mostNegative := [3]float32{convertToFloat32(record[4]), convertToFloat32(record[6]), -convertToFloat32(record[2])}
coordinates = append(coordinates, NewCoordinates(record[0], mostPositive, mostNegative))
}
return coordinates
}
// Function to convert string to float64
func convertToFloat32(value string) float32 {
value = strings.TrimSpace(value) // Trim leading and trailing spaces
floatValue, err := strconv.ParseFloat(value, 32)
if err != nil {
log.Fatal(err)
}
return float32(floatValue) * M_TO_AYLIN
}