From 4f755e67666ca0bea3a3c192932689c955c1a575 Mon Sep 17 00:00:00 2001 From: surdeus Date: Sat, 3 Jun 2023 22:41:00 +0300 Subject: [PATCH] ... --- src/cmd/test/main.go | 3 ++- src/gx/line.go | 21 ++++++++++++++++++++- src/gx/polygon.go | 16 ++++++++++++++++ src/gx/rect.go | 4 ++-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/gx/polygon.go diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 8f86070..7ccbca4 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -186,7 +186,8 @@ func (d *Debug) Draw( keyStrs = append(keyStrs, k.String()) } - if rectMove.Vertices().Contained(rect).Len() > 0 { + if rectMove.Vertices().Contained(rect).Len() > 0 || + rect.Vertices().Contained(rectMove).Len() > 0 { keyStrs = append(keyStrs, "THIS IS SHIT") } diff --git a/src/gx/line.go b/src/gx/line.go index f3c048e..aeed1a4 100644 --- a/src/gx/line.go +++ b/src/gx/line.go @@ -2,6 +2,7 @@ package gx import ( "math" + "fmt" ) // The type represents mathematical equation of line and line itself. @@ -25,7 +26,8 @@ type LineSegment [2]Point type LineSegments []LineSegment type Edge = LineSegment -type Edges []Vertex +type Edges = LineSegments + // Check if two LinerPointContainers do cross and return the @@ -120,3 +122,20 @@ func (ls LineSegment) Len() Float { return math.Sqrt(ls.LenSqr()) } +func (what LineSegments) Cross(with LineSegments) ([][2]int, Points) { + indexes := [][2]int{} + points := Points{} + for i := range what { + for j := range with { + p, cross := LinersCross(what[i], with[j]) + if cross { + fmt.Println("in") + points = append(points, p) + indexes = append(indexes, [2]int{i, j}) + } + } + } + + return indexes, points +} + diff --git a/src/gx/polygon.go b/src/gx/polygon.go new file mode 100644 index 0000000..154060e --- /dev/null +++ b/src/gx/polygon.go @@ -0,0 +1,16 @@ +package gx + +// The type represents polygons. +// Fuck. The package gets too big. +// Should split it somehow. +type Polygon []Point + +func (p Polygon) Edges() Edges { + ret := Edges{} + /*for i := range p { + ret = append(ret, Edge{}) + }*/ + + return ret +} + diff --git a/src/gx/rect.go b/src/gx/rect.go index d99bb14..c265803 100644 --- a/src/gx/rect.go +++ b/src/gx/rect.go @@ -38,13 +38,13 @@ func (r Rectangle) Vertices() Points { return Points{p1, p2, p3, p4} } -func (r Rectangle) Edges() LineSegments { +func (r Rectangle) Edges() Edges { vs := r.Vertices() return LineSegments{ LineSegment{vs[0], vs[1]}, LineSegment{vs[1], vs[2]}, LineSegment{vs[2], vs[3]}, - LineSegment{vs[4], vs[0]}, + LineSegment{vs[3], vs[0]}, } }