From 07915de2a1a50f0946fe1c5ac880e97ac220241f Mon Sep 17 00:00:00 2001 From: surdeus Date: Sun, 28 May 2023 19:45:58 +0300 Subject: [PATCH] Simplified the line type. --- src/cmd/math/main.go | 4 +--- src/gx/line.go | 17 +++++------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/cmd/math/main.go b/src/cmd/math/main.go index 79eebde..8891271 100644 --- a/src/cmd/math/main.go +++ b/src/cmd/math/main.go @@ -21,9 +21,7 @@ func main() { }.Line(), } - for _, l := range lines { - fmt.Println(l.Equation()) - } + for _, l := range lines { fmt.Println(l) } /*t := gx.Triangle{ gx.Point{0, 0}, gx.Point{0, 100}, diff --git a/src/gx/line.go b/src/gx/line.go index 5d526d3..2dfe1e8 100644 --- a/src/gx/line.go +++ b/src/gx/line.go @@ -4,17 +4,14 @@ import ( "math" ) -// The type represents mathematical equation of line. -type LineEquation struct { +// The type represents mathematical equation of line and line itself. +type Line struct { K, C Float } // The type represents a line segment. type LineSegment [2]Point -// The type represents a line. -type Line LineSegment - // Get square of length of line segment. func (ls LineSegment) LenSqr() Float { return Sqr(ls[0].X - ls[1].X) + @@ -26,18 +23,14 @@ func (ls LineSegment) Len() Float { return math.Sqrt(ls.LenSqr()) } -// Returns corresponding to the line segment line. -func (ls LineSegment) Line() Line { - return Line(ls) -} - -func (l Line) Equation() LineEquation { +// Returns corresponding to the segment line line. +func (l LineSegment) Line() Line { p0 := l[0] p1 := l[1] k := (p0.Y - p1.Y) / (p0.X - p1.X) c := p0.Y - p0.X*k - return LineEquation{k, c} + return Line{k, c} }