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]}, } }