From 306c2a9871a4f12519ef56f7ca9fa4a272381e32 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 24 Dec 2018 22:53:42 +0100 Subject: cron commit --- main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..c33a669 --- /dev/null +++ b/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "strconv" + + "github.com/gorilla/mux" + + "git.darknebu.la/GalaxySimulator/structs" +) + +func nextpos(deltat float64, star structs.Star2D) { + // ... +} + +func initMassCenter(w http.ResponseWriter, r *http.Request) { + log.Println("[ ] Initializing the Mass Center of all the nodes in the tree") + + // getting the tree index + vars := mux.Vars(r) + treeindex, _ := strconv.ParseInt(vars["treeindex"], 10, 0) + _, _ = fmt.Fprintln(w, treeindex) + + // Recursively calculate the center of mass of a node by calculating the center of mass of the four children of + // that node. + // The formula used is the following: + // ( (x_i * m_i)/(m_total) , (y_i * m_i)/(m_total) ) + + // starting at the root node of the tree + +} + +func calcNewPos(w http.ResponseWriter, r *http.Request) { + // get the post parameters + x, _ := strconv.ParseFloat(r.PostFormValue("x"), 64) + y, _ := strconv.ParseFloat(r.PostFormValue("y"), 64) + z, _ := strconv.ParseFloat(r.PostFormValue("z"), 64) + + log.Printf("(%f, %f, %f)", x, y, z) +} + +func main() { + router := mux.NewRouter() + + router.HandleFunc("/initMassCenter", calcNewPos).Methods("POST") + + // this is an endpoint searching for a star and calculating the forces acting inbetween it and all the other star + // in it's direct range + router.HandleFunc("/newpos", calcNewPos).Methods("POST") + log.Fatal(http.ListenAndServe(":8345", router)) +} -- cgit 1.4.1