-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc.go
60 lines (51 loc) · 1.1 KB
/
fc.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
52
53
54
55
56
57
58
59
60
package lnr
import (
"github.com/intdxdt/geom"
)
type FC struct {
Coordinates geom.Coords
Fid int
}
func NewFC(coordinates geom.Coords, fid int) *FC {
return &FC{coordinates, fid}
}
//Planar self-intersection FCPlanarSelfIntersection
func FCPlanarSelfIntersection(featureClass []*FC) map[int][]int {
//preallocate points size
var n = 0
for _, self := range featureClass {
n += self.Coordinates.Len()
}
var points = make([]vertex, 0, n)
for _, self := range featureClass {
points = appendVertices(points, self.Coordinates, self.Fid)
}
vertices(points).Sort() //O(nlogn)
var d = 0
var indexes []*vertex
var results = make(map[int][]int, 0)
var a, b *vertex
var bln bool
for i, n := 0, len(points); i < n-1; i++ { //O(n)
a, b = &points[i], &points[i+1]
bln = a.Equals2D(b.Point)
if bln {
if d == 0 {
indexes = append(indexes, a, b)
d += 2
} else {
indexes = append(indexes, b)
d += 1
}
continue
}
if d > 1 {
for _, v := range indexes {
results[v.fid] = append(results[v.fid], v.index)
}
}
d = 0
indexes = indexes[:0]
}
return results
}