-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlineSegment.go
48 lines (37 loc) · 939 Bytes
/
lineSegment.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
package common
type LineSegment struct {
start *Point
end *Point
slope *Point
}
func NewLineSegment(start *Point, end *Point) *LineSegment {
return &LineSegment{
start: start,
end: end,
}
}
func (line *LineSegment) Start() *Point {
return line.start
}
func (line *LineSegment) End() *Point {
return line.end
}
func (line *LineSegment) Slope() *Point {
if line.slope == nil {
x := line.End().X() - line.Start().X()
y := line.End().Y() - line.Start().Y()
z := line.End().Z() - line.Start().Z()
reducesNumbers := Reduce(x, y, z)
line.slope = New3DPoint(reducesNumbers[0], reducesNumbers[1], reducesNumbers[2])
}
return line.slope
}
func (line *LineSegment) IsVertical() bool {
return line.Start().X() == line.End().X()
}
func (line *LineSegment) IsHorizontal() bool {
return line.Start().Y() == line.End().Y()
}
func (line *LineSegment) IsStacked() bool {
return line.Start().Z() == line.End().Z()
}