-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoint_inters.go
59 lines (48 loc) · 1.2 KB
/
point_inters.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
package geom
import (
"bytes"
"fmt"
"github.com/intdxdt/math"
)
type InterPoint struct {
Point
Inter VBits
}
type IntPts []InterPoint
func (s IntPts) Len() int {
return len(s)
}
func (s IntPts) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s IntPts) Less(i, j int) bool {
return (s[i].Point[X] < s[j].Point[X]) || (feq(s[i].Point[X], s[j].Point[X]) && s[i].Point[Y] < s[j].Point[Y])
}
func (p *InterPoint) IsIntersection() bool {
return p.Inter == 0
}
func (p *InterPoint) IsVertex() bool {
var mask = SelfMask | OtherMask
return p.Inter&mask > 0
}
func (p *InterPoint) IsVertexSelf() bool {
return p.Inter&SelfMask > 0
}
func (p *InterPoint) IsVertexOther() bool {
return p.Inter&OtherMask > 0
}
func (p *InterPoint) IsVerteXOR() bool {
return (p.IsVertexSelf() && !p.IsVertexOther()) ||
(!p.IsVertexSelf() && p.IsVertexOther())
}
//string
func (self *InterPoint) String() string {
var buf bytes.Buffer
buf.WriteString("[")
buf.WriteString(math.FloatToString(self.Point[X]) + ", ")
buf.WriteString(math.FloatToString(self.Point[Y]) + ", ")
buf.WriteString(math.FloatToString(self.Point[Z]) + ", ")
buf.WriteString(fmt.Sprintf("%04b", self.Inter))
buf.WriteString("]")
return buf.String()
}