func splitOverlappingAtIntersections(zs []Point, queue *SweepEvents, s *SweepPoint, isA bool) bool { changed := false for prev := s.node.Prev(); prev != nil; prev = prev.Prev() { if prev.Point == s.Point && prev.other.Point == s.other.Point { splitAtIntersections(zs, queue, prev.SweepPoint, i
(zs []Point, queue *SweepEvents, s *SweepPoint, isA bool)
| 1249 | //} |
| 1250 | |
| 1251 | func splitAtIntersections(zs []Point, queue *SweepEvents, s *SweepPoint, isA bool) bool { |
| 1252 | changed := false |
| 1253 | for i := len(zs) - 1; 0 <= i; i-- { |
| 1254 | z := zs[i] |
| 1255 | if z == s.Point || z == s.other.Point { |
| 1256 | // ignore tangent intersections at the endpoints |
| 1257 | continue |
| 1258 | } |
| 1259 | |
| 1260 | // split segment at intersection |
| 1261 | right, left := s.SplitAt(z) |
| 1262 | |
| 1263 | // reverse direction if necessary |
| 1264 | if left.X == left.other.X { |
| 1265 | // segment after the split is vertical |
| 1266 | left.vertical, left.other.vertical = true, true |
| 1267 | if left.other.Y < left.Y { |
| 1268 | left.Reverse() |
| 1269 | } |
| 1270 | } else if right.X == right.other.X { |
| 1271 | // segment before the split is vertical |
| 1272 | right.vertical, right.other.vertical = true, true |
| 1273 | if right.Y < right.other.Y { |
| 1274 | // reverse first segment |
| 1275 | if isA { |
| 1276 | fmt.Println("WARNING: reversing first segment of A") |
| 1277 | } |
| 1278 | if right.other.node != nil { |
| 1279 | panic("impossible: first segment became vertical and needs reversal, but was already in the sweep status") |
| 1280 | } |
| 1281 | right.Reverse() |
| 1282 | |
| 1283 | // Note that we swap the content of the currently processed left-endpoint of b with |
| 1284 | // the new left-endpoint vertically below. The queue may not be strictly ordered |
| 1285 | // with other vertical segments at the new left-endpoint, but this isn't a problem |
| 1286 | // since we sort the events in each square after the Bentley-Ottmann phase. |
| 1287 | |
| 1288 | // update references from handled and queue by swapping their contents |
| 1289 | first := right.other |
| 1290 | *right, *first = *first, *right |
| 1291 | first.other, right.other = right, first |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | // add to handled |
| 1296 | //handled[SweepPointPair{a, bLeft}] = struct{}{} |
| 1297 | //if aPrevLeft != a { |
| 1298 | // // there is only one non-tangential intersection |
| 1299 | // handled[SweepPointPair{aPrevLeft, bLeft}] = struct{}{} |
| 1300 | //} |
| 1301 | |
| 1302 | // add to queue |
| 1303 | queue.Push(right) |
| 1304 | queue.Push(left) |
| 1305 | changed = true |
| 1306 | } |
| 1307 | return changed |
| 1308 | } |
no test coverage detected