(x float64, event *SweepPoint, refNode *SweepNode)
| 1396 | } |
| 1397 | |
| 1398 | func (squares *toleranceSquares) Add(x float64, event *SweepPoint, refNode *SweepNode) { |
| 1399 | // refNode is always the node itself for left-endpoints, and otherwise the previous node (ie. |
| 1400 | // the node below) of a right-endpoint, or the next (ie. above) node if the previous is nil. |
| 1401 | // It may be inside or outside the right edge of the square. If outside, it is the first such |
| 1402 | // segment going upwards/downwards from the square (and not just any segment). |
| 1403 | y := snap(event.Y, BentleyOttmannEpsilon) |
| 1404 | if idx, ok := squares.find(x, y); !ok { |
| 1405 | // create new tolerance square |
| 1406 | square := boSquarePool.Get().(*toleranceSquare) |
| 1407 | *square = toleranceSquare{ |
| 1408 | X: x, |
| 1409 | Y: y, |
| 1410 | Events: []*SweepPoint{event}, |
| 1411 | Node: refNode, |
| 1412 | } |
| 1413 | *squares = append((*squares)[:idx], append(toleranceSquares{square}, (*squares)[idx:]...)...) |
| 1414 | } else { |
| 1415 | // insert into existing tolerance square |
| 1416 | (*squares)[idx].Node = refNode |
| 1417 | (*squares)[idx].Events = append((*squares)[idx].Events, event) |
| 1418 | } |
| 1419 | |
| 1420 | // (nearly) vertical segments may still be used as the reference segment for squares around |
| 1421 | // in that case, replace with the new reference node (above or below that segment) |
| 1422 | if !event.left { |
| 1423 | orig := event.other.node |
| 1424 | for i := len(*squares) - 1; 0 <= i && (*squares)[i].X == x; i-- { |
| 1425 | if (*squares)[i].Node == orig { |
| 1426 | (*squares)[i].Node = refNode |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | //func (event *SweepPoint) insertIntoSortedH(events *[]*SweepPoint) { |
| 1433 | // // O(log n) |
no test coverage detected