Added the Liner interface for better and more general interaction.
This commit is contained in:
parent
07915de2a1
commit
522e9a2d58
3 changed files with 52 additions and 4 deletions
|
@ -22,6 +22,17 @@ func main() {
|
|||
}
|
||||
|
||||
for _, l := range lines { fmt.Println(l) }
|
||||
|
||||
l1 := gx.LineSegment{
|
||||
gx.Point{0, 0},
|
||||
gx.Point{1, 1},
|
||||
}.Line()
|
||||
|
||||
l2 := gx.LineSegment{
|
||||
gx.Point{0, 1},
|
||||
gx.Point{1, 2},
|
||||
}.Line()
|
||||
fmt.Println(l1.Parallel(l2))
|
||||
/*t := gx.Triangle{
|
||||
gx.Point{0, 0},
|
||||
gx.Point{0, 100},
|
||||
|
|
|
@ -9,9 +9,24 @@ type Line struct {
|
|||
K, C Float
|
||||
}
|
||||
|
||||
type Liner interface {
|
||||
Line() Line
|
||||
}
|
||||
|
||||
// The type represents a line segment.
|
||||
type LineSegment [2]Point
|
||||
|
||||
// Check whether the liner is parallel to the line.
|
||||
func (l Line) Parallel(liner Liner) bool {
|
||||
buf := liner.Line()
|
||||
|
||||
if buf.K == l.K {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Get square of length of line segment.
|
||||
func (ls LineSegment) LenSqr() Float {
|
||||
return Sqr(ls[0].X - ls[1].X) +
|
||||
|
@ -23,6 +38,10 @@ func (ls LineSegment) Len() Float {
|
|||
return math.Sqrt(ls.LenSqr())
|
||||
}
|
||||
|
||||
func (l Line) Line() Line {
|
||||
return l
|
||||
}
|
||||
|
||||
// Returns corresponding to the segment line line.
|
||||
func (l LineSegment) Line() Line {
|
||||
p0 := l[0]
|
||||
|
@ -34,3 +53,25 @@ func (l LineSegment) Line() Line {
|
|||
return Line{k, c}
|
||||
}
|
||||
|
||||
|
||||
func (l LineSegment) Crosses(with any) (bool, Point) {
|
||||
switch with.(type) {
|
||||
case Line :
|
||||
return l.crossesLine(with.(Line))
|
||||
case LineSegment :
|
||||
return l.crossesLineSegment(with.(LineSegment))
|
||||
default:
|
||||
panic("The type that is not defined to be crossed")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (l LineSegment) crossesLineSegment(with LineSegment) (bool, Point) {
|
||||
return false, Point{}
|
||||
}
|
||||
|
||||
func (l LineSegment) crossesLine(with Line) (bool, Point) {
|
||||
return false, Point{}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,6 @@ type Engine struct {
|
|||
|
||||
type engine Engine
|
||||
|
||||
var (
|
||||
Infinity = math.MaxFloat64
|
||||
)
|
||||
|
||||
// Return current camera.
|
||||
func (e *Engine) Camera() *Camera {
|
||||
return e.camera
|
||||
|
|
Loading…
Reference in a new issue