-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
109 lines (84 loc) · 1.88 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Package pgeo implements geometric types for Postgres
//
// Geometryc types:
// https://www.postgresql.org/docs/current/static/datatype-geometric.html
//
// Description:
// https://github.com/saulortega/pgeo
package pgeo
func NewPoint(X, Y float64) Point {
return Point{X, Y}
}
func NewLine(A, B, C float64) Line {
return Line{A, B, C}
}
func NewLseg(A, B Point) Lseg {
return Lseg([2]Point{A, B})
}
func NewBox(A, B Point) Box {
return Box([2]Point{A, B})
}
func NewPath(P []Point, C bool) Path {
return Path{P, C}
}
func NewPolygon(P []Point) Polygon {
return Polygon(P)
}
func NewCircle(P Point, R float64) Circle {
return Circle{P, R}
}
func NewNullPoint(P Point, v bool) NullPoint {
return NullPoint{P, v}
}
func NewNullLine(L Line, v bool) NullLine {
return NullLine{L, v}
}
func NewNullLseg(L Lseg, v bool) NullLseg {
return NullLseg{L, v}
}
func NewNullBox(B Box, v bool) NullBox {
return NullBox{B, v}
}
func NewNullPath(P Path, v bool) NullPath {
return NullPath{P, v}
}
func NewNullPolygon(P Polygon, v bool) NullPolygon {
return NullPolygon{P, v}
}
func NewNullCircle(C Circle, v bool) NullCircle {
return NullCircle{C, v}
}
func NewRandPoint() Point {
return Point{newRandNum(), newRandNum()}
}
func NewRandLine() Line {
return Line{newRandNum(), newRandNum(), 0}
}
func NewRandLseg() Lseg {
return Lseg([2]Point{NewRandPoint(), NewRandPoint()})
}
func NewRandBox() Box {
return Box([2]Point{NewRandPoint(), NewRandPoint()})
}
func NewRandPath() Path {
return Path{RandPoints(3), newRandNum() < 40}
}
func NewRandPolygon() Polygon {
return Polygon(RandPoints(3))
}
func NewRandCircle() Circle {
return Circle{NewRandPoint(), newRandNum()}
}
func NewZeroPoint() Point {
return Point{0, 0}
}
func RandPoints(n int) []Point {
var points = []Point{}
if n <= 0 {
return points
}
for i := 0; i < n; i++ {
points = append(points, NewRandPoint())
}
return points
}