-
Notifications
You must be signed in to change notification settings - Fork 2
/
site.go
29 lines (23 loc) · 852 Bytes
/
site.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
package voronoi
import (
"fmt"
"github.com/quasoft/dcel"
)
// Site is a prerequisute for computing a voronoi diagram.
// Site is the point (also called seed or generator) in a voronoi diagram,
// around which a cell (subset of the plane) is formed, with such a property
// that every point in the cell is closer to this site than any other site.
type Site struct {
X, Y int
ID int64
Face *dcel.Face // Pointer to the DCEL face corresponding to this site
Data interface{}
}
func (s Site) String() string { return fmt.Sprintf("%d,%d", s.X, s.Y) }
// SiteSlice is a slice of Site values, sortable by Y
type SiteSlice []Site
func (s SiteSlice) Len() int { return len(s) }
func (s SiteSlice) Less(i, j int) bool {
return s[i].Y < s[j].Y || (s[i].Y == s[j].Y && s[i].X < s[j].X)
}
func (s SiteSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }