-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly.go
73 lines (70 loc) · 1.7 KB
/
poly.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
61
62
63
64
65
66
67
68
69
70
71
72
73
package nest
import (
. "github.com/mojinfu/point"
)
type PolygonStruct struct {
RootPoly *PolyNode
id int //全局唯一id
typeID int //同一类型的 NFP 无需重复生成//但要注意这个字段可能没被初始化的 没被初始化 则用id代替
width float64
height float64
rotation int //当前旋转的角度
Name string
isWart bool
AngleList []int64
}
func NewPolyWithName(points []*Point, name string) *PolygonStruct {
a := NewPoly(points)
a.SetName(name)
return a
}
func NewPoly(points []*Point) *PolygonStruct {
poly := &PolygonStruct{
RootPoly: newNodePoly(points),
}
return poly
}
func newNodePoly(points []*Point) *PolyNode {
poly := &PolyNode{}
for index := range points {
poly.OriginPolygon = append(poly.OriginPolygon, &Point{
X: points[index].X,
Y: points[index].Y,
})
}
return poly
}
func (this *PolygonStruct) setTypeID(id int) {
if this.typeID <= 0 {
this.typeID = id
}
}
func (this *PolygonStruct) getTypeID() int {
return this.typeID
}
func (this *PolygonStruct) IsWart() bool {
return this.isWart
}
func (this *PolygonStruct) SetName(name string) {
this.Name = name
}
func (this *PolygonStruct) GetName() string {
return this.Name
}
func (this *PolygonStruct) SetAngelList(angleList []int64) {
if this.isWart {
return
}
this.AngleList = angleList
}
func (this *PolygonStruct) AddChildPoly(points []*Point) string {
//检查child是不是都在root poly里面
this.RootPoly.children = append(this.RootPoly.children, newNodePoly(points))
return this.Name
}
func (this *PolygonStruct) TypeID() int {
return this.typeID
}
func (this *PolygonStruct) GetPolygonBeforeRotation() []*Point {
return this.RootPoly.polygonBeforeRotation
}