-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelaunay.go
49 lines (43 loc) · 1.38 KB
/
delaunay.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
// Package delaunay implements Delaunay Triangulation.
package delaunay
// Node is a data point in the list of objects to determine a Delaunay
// Triangulation. X and Y are Cartesian coordinates in a plane. At
// this time, Z is another float. TODO: Change struct so that Z can be
// any type of object -- int, float, string, list, etc. Perhaps a
// pointer?
type Node struct {
X, Y float32
Z float32
}
// Edge is the line between the X and Y components of two of the Nodes
// that make up a Delaunay Triangle.
type Edge struct {
n1, n2 Node
}
// Triangle is an object that consists of three Nodes that make up a
// Delaunay Triangle. It also has an index I which is an index into a
// acyclic graph of all the Delaunay Triangles which make up a
// triangulation.
type Triangle struct {
// I int
n1, n2, n3 Node
}
// NewNode creates a Node object and returns its address
//
func NewNode(a, b, c float32) *Node {
n := new(Node)
n.X, n.Y, n.Z = a, b, c
return n
}
// NewEdge creates an Edge object and returns its address
// NOTE: This is the most succinct declaration
func NewEdge(n1, n2 Node) *Edge {
return &Edge{n1, n2}
}
// NewTriangle creates a Triangle object and returns its address
// TODO: Implement this so it can take either three Nodes or three Edges
// NOTE: This is more succinct than NewNode
func NewTriangle(n1, n2, n3 Node) *Triangle {
t := Triangle{n1, n2, n3}
return &t
}