Loading icosahedron/icosahedron.go +18 −40 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package icosahedron import ( "math" mgl "github.com/go-gl/mathgl/mgl32" ) /* Loading Loading @@ -55,18 +57,18 @@ func (i *Icosahedron) Faces() Faces { // Create creates the vertices and faces for a regular icosahedron. func Create() (*Icosahedron, error) { vertices := Vertices{ {x: 0, y: +1, z: +Phi}, // 0 {x: 0, y: +1, z: -Phi}, // 1 {x: 0, y: -1, z: -Phi}, // 2 {x: 0, y: -1, z: +Phi}, // 3 {x: +1, y: +Phi, z: 0}, // 4 {x: +1, y: -Phi, z: 0}, // 5 {x: -1, y: -Phi, z: 0}, // 6 {x: -1, y: +Phi, z: 0}, // 7 {x: +Phi, y: 0, z: +1}, // 8 {x: -Phi, y: 0, z: +1}, // 9 {x: -Phi, y: 0, z: -1}, // 10 {x: +Phi, y: 0, z: -1}, // 11 {0, +1, +Phi}, // 0 {0, +1, -Phi}, // 1 {0, -1, -Phi}, // 2 {0, -1, +Phi}, // 3 {+1, +Phi, 0}, // 4 {+1, -Phi, 0}, // 5 {-1, -Phi, 0}, // 6 {-1, +Phi, 0}, // 7 {+Phi, 0, +1}, // 8 {-Phi, 0, +1}, // 9 {-Phi, 0, -1}, // 10 {+Phi, 0, -1}, // 11 } faces := Faces{ Loading Loading @@ -97,32 +99,8 @@ func Create() (*Icosahedron, error) { return &i, nil } func (v Vertex) add(a Vertex) Vertex { var r Vertex r.x = v.x + a.x r.y = v.y + a.y r.z = v.z + a.z return r } func (v Vertex) sub(a Vertex) Vertex { var r Vertex r.x = v.x - a.x r.y = v.y - a.y r.z = v.z - a.z return r } func (v Vertex) scale(s float32) Vertex { var r Vertex r.x = v.x * s r.y = v.y * s r.z = v.z * s return r } func calculateMidPoint(va Vertex, vb Vertex, r float32) (Vertex, error) { vr := va.add(vb.sub(va).scale(r)) func calculateMidPoint(va mgl.Vec3, vb mgl.Vec3, r float32) (mgl.Vec3, error) { vr := va.Add(vb.Sub(va).Mul(r)) return vr, nil } Loading Loading @@ -153,7 +131,7 @@ func Subdivide(icoIn *Icosahedron) (*Icosahedron, error) { in := [3]int{-1, -1, -1} // do the new vertices already exist for vi, vn := range []Vertex{ for vi, vn := range []mgl.Vec3{ v0, v1, v2, Loading @@ -161,7 +139,7 @@ func Subdivide(icoIn *Icosahedron) (*Icosahedron, error) { im := -1 match := false for vj, vo := range vso { if (vn.x == vo.x) && (vn.y == vo.y) && (vn.z == vo.z) { if (vn.X() == vo.X()) && (vn.Y() == vo.Y()) && (vn.Z() == vo.Z()) { // found a match im = vj match = true Loading icosahedron/structures.go +4 −5 Original line number Diff line number Diff line package icosahedron // Vertex is the tuple (x,y,z). type Vertex struct { x, y, z float32 } import ( mgl "github.com/go-gl/mathgl/mgl32" ) // Vertices of a regular icosahedron. type Vertices []Vertex type Vertices []mgl.Vec3 // Face contains the indexes of verticies. type Face []int Loading Loading
icosahedron/icosahedron.go +18 −40 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package icosahedron import ( "math" mgl "github.com/go-gl/mathgl/mgl32" ) /* Loading Loading @@ -55,18 +57,18 @@ func (i *Icosahedron) Faces() Faces { // Create creates the vertices and faces for a regular icosahedron. func Create() (*Icosahedron, error) { vertices := Vertices{ {x: 0, y: +1, z: +Phi}, // 0 {x: 0, y: +1, z: -Phi}, // 1 {x: 0, y: -1, z: -Phi}, // 2 {x: 0, y: -1, z: +Phi}, // 3 {x: +1, y: +Phi, z: 0}, // 4 {x: +1, y: -Phi, z: 0}, // 5 {x: -1, y: -Phi, z: 0}, // 6 {x: -1, y: +Phi, z: 0}, // 7 {x: +Phi, y: 0, z: +1}, // 8 {x: -Phi, y: 0, z: +1}, // 9 {x: -Phi, y: 0, z: -1}, // 10 {x: +Phi, y: 0, z: -1}, // 11 {0, +1, +Phi}, // 0 {0, +1, -Phi}, // 1 {0, -1, -Phi}, // 2 {0, -1, +Phi}, // 3 {+1, +Phi, 0}, // 4 {+1, -Phi, 0}, // 5 {-1, -Phi, 0}, // 6 {-1, +Phi, 0}, // 7 {+Phi, 0, +1}, // 8 {-Phi, 0, +1}, // 9 {-Phi, 0, -1}, // 10 {+Phi, 0, -1}, // 11 } faces := Faces{ Loading Loading @@ -97,32 +99,8 @@ func Create() (*Icosahedron, error) { return &i, nil } func (v Vertex) add(a Vertex) Vertex { var r Vertex r.x = v.x + a.x r.y = v.y + a.y r.z = v.z + a.z return r } func (v Vertex) sub(a Vertex) Vertex { var r Vertex r.x = v.x - a.x r.y = v.y - a.y r.z = v.z - a.z return r } func (v Vertex) scale(s float32) Vertex { var r Vertex r.x = v.x * s r.y = v.y * s r.z = v.z * s return r } func calculateMidPoint(va Vertex, vb Vertex, r float32) (Vertex, error) { vr := va.add(vb.sub(va).scale(r)) func calculateMidPoint(va mgl.Vec3, vb mgl.Vec3, r float32) (mgl.Vec3, error) { vr := va.Add(vb.Sub(va).Mul(r)) return vr, nil } Loading Loading @@ -153,7 +131,7 @@ func Subdivide(icoIn *Icosahedron) (*Icosahedron, error) { in := [3]int{-1, -1, -1} // do the new vertices already exist for vi, vn := range []Vertex{ for vi, vn := range []mgl.Vec3{ v0, v1, v2, Loading @@ -161,7 +139,7 @@ func Subdivide(icoIn *Icosahedron) (*Icosahedron, error) { im := -1 match := false for vj, vo := range vso { if (vn.x == vo.x) && (vn.y == vo.y) && (vn.z == vo.z) { if (vn.X() == vo.X()) && (vn.Y() == vo.Y()) && (vn.Z() == vo.Z()) { // found a match im = vj match = true Loading
icosahedron/structures.go +4 −5 Original line number Diff line number Diff line package icosahedron // Vertex is the tuple (x,y,z). type Vertex struct { x, y, z float32 } import ( mgl "github.com/go-gl/mathgl/mgl32" ) // Vertices of a regular icosahedron. type Vertices []Vertex type Vertices []mgl.Vec3 // Face contains the indexes of verticies. type Face []int Loading