-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxy.go
More file actions
49 lines (37 loc) · 749 Bytes
/
xy.go
File metadata and controls
49 lines (37 loc) · 749 Bytes
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
package poly2tri
import (
"fmt"
"math"
)
type XYInterface interface {
String() string
GetX() float64
GetY() float64
}
func XYCompare(a, b XYInterface) float64 {
xeq := XYEqualsFloat(a.GetX(), b.GetX())
yeq := XYEqualsFloat(a.GetY(), b.GetY())
if yeq {
if xeq {
return 0
}
return a.GetX() - b.GetX()
}
return a.GetY() - b.GetY()
}
func XYEquals(a, b XYInterface) bool {
return XYEqualsFloat(a.GetX(), b.GetX()) &&
XYEqualsFloat(a.GetY(), b.GetY())
}
func XYString(a XYInterface) string {
return fmt.Sprintf("(%f;%f)", a.GetX(), a.GetY())
}
func XYEqualsFloat(a, b float64) bool {
return math.Abs(a-b) <= EPSILON
}
func XYCompareFloat(a, b float64) float64 {
if XYEqualsFloat(a, b) {
return 0
}
return a - b
}