good enough for now
This commit is contained in:
parent
a1abd8ac3c
commit
5c313e8518
1 changed files with 1 additions and 9 deletions
|
@ -116,7 +116,7 @@ func polygonRectOverlap(polygon []image.Point, rect image.Rectangle) bool {
|
||||||
// Walk each edge of polygon.
|
// Walk each edge of polygon.
|
||||||
for i, p := range polygon {
|
for i, p := range polygon {
|
||||||
q := polygon[(i+1)%len(polygon)]
|
q := polygon[(i+1)%len(polygon)]
|
||||||
// Exclude edges that don't overlap the rectangle in any way.
|
// Pretend the edge is a rectangle. Exclude those that don't overlap.
|
||||||
if !rect.Overlaps(image.Rectangle{p, q}.Canon()) {
|
if !rect.Overlaps(image.Rectangle{p, q}.Canon()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -130,17 +130,13 @@ func polygonRectOverlap(polygon []image.Point, rect image.Rectangle) bool {
|
||||||
min := (rect.Min.Y - p.Y) * d.X
|
min := (rect.Min.Y - p.Y) * d.X
|
||||||
max := (rect.Max.Y - p.Y) * d.X
|
max := (rect.Max.Y - p.Y) * d.X
|
||||||
// Test left side of rect
|
// Test left side of rect
|
||||||
//if (rect.Min.X >= p.X || rect.Min.X >= q.X) && (rect.Min.X <= p.X || rect.Min.X <= q.X) {
|
|
||||||
if t := (rect.Min.X - p.X) * d.Y; min <= t && t < max {
|
if t := (rect.Min.X - p.X) * d.Y; min <= t && t < max {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
// Test right side of rect
|
// Test right side of rect
|
||||||
//if (rect.Max.X > p.X || rect.Max.X > q.X) && (rect.Max.X <= p.X || rect.Max.X <= q.X) {
|
|
||||||
if t := (rmax.X - p.X) * d.Y; min <= t && t < max {
|
if t := (rmax.X - p.X) * d.Y; min <= t && t < max {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
// If the polygon edge is not horizontal, test the top and bottom sides
|
// If the polygon edge is not horizontal, test the top and bottom sides
|
||||||
if d.Y != 0 {
|
if d.Y != 0 {
|
||||||
|
@ -150,18 +146,14 @@ func polygonRectOverlap(polygon []image.Point, rect image.Rectangle) bool {
|
||||||
min := (rect.Min.X - p.X) * d.Y
|
min := (rect.Min.X - p.X) * d.Y
|
||||||
max := (rect.Max.X - p.X) * d.Y
|
max := (rect.Max.X - p.X) * d.Y
|
||||||
// Test top side of rect
|
// Test top side of rect
|
||||||
//if (rect.Min.Y >= p.Y || rect.Min.Y >= q.Y) && (rect.Min.Y <= p.Y || rect.Min.Y <= q.Y) {
|
|
||||||
if t := (rect.Min.Y - p.Y) * d.X; min <= t && t < max {
|
if t := (rect.Min.Y - p.Y) * d.X; min <= t && t < max {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
// Test bottom side of rect
|
// Test bottom side of rect
|
||||||
//if (rect.Max.Y > p.Y || rect.Max.Y > q.Y) && (rect.Max.Y <= p.Y || rect.Max.Y <= q.Y) {
|
|
||||||
if t := (rmax.Y - p.Y) * d.X; min <= t && t < max {
|
if t := (rmax.Y - p.Y) * d.X; min <= t && t < max {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue