-
Notifications
You must be signed in to change notification settings - Fork 2
/
line_test.go
111 lines (95 loc) · 2.94 KB
/
line_test.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
110
111
package cirno_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zergon321/cirno"
)
func TestLinesAreCollinear(t *testing.T) {
l1, err := cirno.NewLine(cirno.NewVector(1, 3), cirno.NewVector(3, 5))
assert.Nil(t, err)
l2, err := cirno.NewLine(cirno.NewVector(1, 1), cirno.NewVector(5, 5))
assert.Nil(t, err)
l3, err := cirno.NewLine(cirno.NewVector(3, 1), cirno.NewVector(5, 1))
assert.Nil(t, err)
res0, err := l1.CollinearTo(l2)
assert.Nil(t, err)
res1, err := l2.CollinearTo(l1)
assert.Nil(t, err)
res2, err := l1.CollinearTo(l3)
assert.Nil(t, err)
res3, err := l2.CollinearTo(l3)
assert.Nil(t, err)
res4, err := l3.CollinearTo(l1)
assert.Nil(t, err)
res5, err := l3.CollinearTo(l2)
assert.Nil(t, err)
assert.True(t, res0)
assert.True(t, res1)
assert.False(t, res2)
assert.False(t, res3)
assert.False(t, res4)
assert.False(t, res5)
}
func TestProjectPointOntoLine(t *testing.T) {
line, err := cirno.NewLine(cirno.NewVector(1, 1), cirno.NewVector(8, 1))
assert.Nil(t, err)
p1 := cirno.NewVector(3, 4)
r1 := cirno.NewVector(3, 1)
p2 := cirno.NewVector(9, 5)
r2 := cirno.NewVector(9, 1)
p3 := cirno.NewVector(-1, -3)
r3 := cirno.NewVector(-1, 1)
assert.Equal(t, line.ProjectPoint(p1), r1)
assert.Equal(t, line.ProjectPoint(p2), r2)
assert.Equal(t, line.ProjectPoint(p3), r3)
line, err = cirno.NewLine(cirno.NewVector(3, 2), cirno.NewVector(6, 4))
assert.Nil(t, err)
t.Log("Projection of P1:", line.ProjectPoint(p1))
t.Log("Projection of P2:", line.ProjectPoint(p2))
t.Log("Projection of P3:", line.ProjectPoint(p3))
}
func TestLineSegmentsOnSameLine(t *testing.T) {
l1, err := cirno.NewLine(cirno.NewVector(1, 1), cirno.NewVector(3, 3))
assert.Nil(t, err)
l2, err := cirno.NewLine(cirno.NewVector(4, 4), cirno.NewVector(6, 6))
assert.Nil(t, err)
l3, err := cirno.NewLine(cirno.NewVector(1, 1), cirno.NewVector(4, 4))
assert.Nil(t, err)
l4, err := cirno.NewLine(cirno.NewVector(2, 3), cirno.NewVector(4, 1))
assert.Nil(t, err)
res0, err := l1.SameLineWith(l2)
assert.Nil(t, err)
res1, err := l2.SameLineWith(l1)
assert.Nil(t, err)
res2, err := l3.SameLineWith(l4)
assert.Nil(t, err)
assert.True(t, res0)
assert.True(t, res1)
assert.False(t, res2)
}
func TestLinesAreParallel(t *testing.T) {
l1, err := cirno.NewLine(cirno.NewVector(1, 1), cirno.NewVector(3, 3))
assert.Nil(t, err)
l2, err := cirno.NewLine(cirno.NewVector(4, 4), cirno.NewVector(6, 6))
assert.Nil(t, err)
l3, err := cirno.NewLine(cirno.NewVector(3, 1), cirno.NewVector(6, 4))
assert.Nil(t, err)
res0, err := l1.ParallelTo(l3)
assert.Nil(t, err)
res1, err := l3.ParallelTo(l1)
assert.Nil(t, err)
res2, err := l2.ParallelTo(l3)
assert.Nil(t, err)
res3, err := l3.ParallelTo(l2)
assert.Nil(t, err)
res4, err := l1.ParallelTo(l2)
assert.Nil(t, err)
res5, err := l2.ParallelTo(l1)
assert.Nil(t, err)
assert.True(t, res0)
assert.True(t, res1)
assert.True(t, res2)
assert.True(t, res3)
assert.False(t, res4)
assert.False(t, res5)
}